[#27163] Statically linked extensions and deferred initialization. — Kent Dahl <kentda@...>

Hi.

12 messages 2001/12/01

[#27168] which editor is adviceful? — Niko Schwarz <niko.schwarz@...>

I know this always is the standard question for every language, but for

17 messages 2001/12/01

[#27191] OO AI — mentifex@... (Arthur T. Murray)

The road to supercomputer AI is paved with good inventions; visit

22 messages 2001/12/01

[#27265] John Roth dolt ( Re: A challenge to proponents of Unit Testing. ) — olczyk@... (Thaddeus L Olczyk)

Background.

166 messages 2001/12/02
[#27295] Re: John Roth dolt ( Re: A challenge to proponents of Unit Testing. ) — Ron Jeffries <ronjeffries@...> 2001/12/02

On Sat, 01 Dec 2001 13:46:42 GMT, olczyk@interaccess.com (Thaddeus L

[#28226] Re: John Roth dolt ( Re: A challenge to proponents of Unit Testing. ) — rbinder@... (Bob Binder) 2001/12/11

Keith Ray <k1e2i3t4h5r6a7y@1m2a3c4.5c6o7m> wrote in message news:<k1e2i3t4h5r6a7y-7C2620.18082110122001@news.attbi.com>...

[#27697] Re: John Roth dolt ( Re: A challenge to proponents of Unit Testing. ) — tadamsmar@... (Tom Adams) 2001/12/06

Ron Jeffries <ronjeffries@REMOVEacm.org> wrote in message news:<176717160028CE03.51B6AF6E20305FB5.2EC5DCFFD6C10DFD@lp.airnews.net>...

[#27958] Re: John Roth dolt ( Re: A challenge to proponents of Unit Testing. ) — "Robert C. Martin" <rmartin@...> 2001/12/08

On Sat, 08 Dec 2001 00:35:43 -0600, Robert C. Martin <rmartin @

[#27287] New RubyGarden Poll - this one affects us all :) — Dave Thomas <Dave@...>

38 messages 2001/12/02
[#27290] RE: New RubyGarden Poll - this one affects us all :) — "Mark Hahn" <mchahn@...> 2001/12/02

[#27482] Re: New RubyGarden Poll - this one affects us all :) — Darrin Thompson <dthompson@...> 2001/12/04

Paul Brannan wrote:

[#27488] Re: New RubyGarden Poll - this one affects us all :) — Michael Neumann <neumann@...> 2001/12/04

Darrin Thompson wrote:

[#27546] Re: New RubyGarden Poll - this one affects us all :) — Bob Hutchison <hutch@...> 2001/12/05

Hi everyone,

[#27552] Re: New RubyGarden Poll - this one affectsus all :) — "Bill Kelly" <billk@...> 2001/12/05

[#27553] Re: New RubyGarden Poll - this one affectsus all :) — David Alan Black <dblack@...> 2001/12/05

Hello --

[#27344] Programname in (un*x) top — kamphausen@... (SKa)

Dear Rubies,

25 messages 2001/12/03
[#27454] Re: Programname in (un*x) top — kamphausen@... (SKa) 2001/12/04

mark@wutka.com wrote in message news:<IsPO7.70773$8n4.4039369@e3500-atl1.usenetserver.com>...

[#27456] Re: Programname in (un*x) top — Martin Weber <Ephaeton@...> 2001/12/04

On Wed, Dec 05, 2001 at 01:03:17AM +0900, SKa wrote:

[#27369] Killer app for Ruby developers? — "Hal E. Fulton" <hal9000@...>

This is an idea that is very skeletal

17 messages 2001/12/03

[#27405] Sourceforge vs. Savannah — "Hal E. Fulton" <hal9000@...>

Opinion question(s).

16 messages 2001/12/04

[#27485] Package Naming — Dave Thomas <Dave@...>

69 messages 2001/12/04
[#27487] RE: Package Naming — "Mark Hahn" <mchahn@...> 2001/12/04

[#27501] RE: Package Naming — Sean Russell <ser@...> 2001/12/05

Mark Hahn wrote:

[#27506] Re: Package Naming — "Mark Hahn" <mchahn@...> 2001/12/05

[#27585] Re: Package Naming — "Mark Hahn" <mchahn@...> 2001/12/05

The forest service must be a hotbed for beauracracy. The only requirement

[#27587] Re: Package Naming — David Alan Black <dblack@...> 2001/12/05

Hello --

[#27588] Re: Package Naming — "Rich Kilmer" <rich@...> 2001/12/05

> -----Original Message-----

[#27589] Re: Package Naming — David Alan Black <dblack@...> 2001/12/05

Hi --

[#27591] Re: Package Naming — "Rich Kilmer" <rich@...> 2001/12/05

David...

[#27505] Do we need something like Python-URL? — ptkwt@...1.aracnet.com (Phil Tomson)

16 messages 2001/12/05

[#27647] web hosting — "ktethridge" <kevinethridge@...>

Does anyone know of a good hosting service that supports Ruby and MySQL?

18 messages 2001/12/06
[#27654] RE: web hosting — "Curt Hibbs" <curt@...> 2001/12/06

Kevin wrote:

[#27761] what are symbols good for???? — Markus Jais <info@...>

hello

13 messages 2001/12/06

[#27783] DBI and large result sets — " JamesBritt" <james@...>

I'm starting to use Ruby DBI, and I'm wondering about its use when processing

18 messages 2001/12/07
[#27805] Re: DBI and large result sets — Michael Neumann <neumann@...> 2001/12/07

JamesBritt wrote:

[#27829] Re: DBI and large result sets — "James Britt (rubydev)" <james@...> 2001/12/07

Thanks to those who helped clarify things.

[#27824] Perl/Python Module Porting — Joseph Erickson <jerickson@...>

Has there been any thought in the Ruby Community of actively porting

27 messages 2001/12/07
[#27834] Re: Perl/Python Module Porting — ptkwt@...1.aracnet.com (Phil Tomson) 2001/12/07

In article <B3265BDC-EB39-11D5-97BA-0050E4C58663@eyemg.com>,

[#27837] Perl/Python Module Porting — Eric Lee Green <eric@...> 2001/12/07

On Friday 07 December 2001 11:55 am, Phil Tomson wrote:

[#27895] Re: Perl/Python Module Porting — Mathieu Bouchard <matju@...> 2001/12/08

[#27894] Re: App server for Ruby? — Tobias DiPasquale <anany@...>

Todd Gillespie wrote

12 messages 2001/12/08

[#27897] Dictionary.com speeder upper — "Ralph Mason" <ralph.mason@...>

Here is a little script I did to make dictionary.com more useful for me.

15 messages 2001/12/08

[#27915] Ruby IDE?? What about using Eclipse?? — "Ross Shaw" <rshaw1961@...>

Eclipse (www.eclipse.org) is an open extensible IDE (written in Java) that

16 messages 2001/12/08
[#27916] Re: Ruby IDE?? What about using Eclipse?? — Robert Feldt <feldt@...> 2001/12/08

On Sat, 8 Dec 2001, Ross Shaw wrote:

[#27920] Re: Ruby IDE?? What about using Eclipse?? — "Curt Hibbs" <curt@...> 2001/12/08

I am going to do this.

[#27921] Re: Ruby IDE?? What about using Eclipse?? — Robert Feldt <feldt@...> 2001/12/08

On Sat, 8 Dec 2001, Curt Hibbs wrote:

[#27980] Displaying Ruby code in LaTeX — "Harry Ohlsen" <harryo@...>

Has anyone written a document in LaTeX that includes examples of Ruby

15 messages 2001/12/08

[#28052] How does puts decide how to print a given object? — "Harry Ohlsen" <harryo@...>

I'm writing a short tutorial introduction to Ruby for an upcoming uni

20 messages 2001/12/10
[#28062] Re: How does puts decide how to print a given object? — matz@... (Yukihiro Matsumoto) 2001/12/10

Hi,

[#28087] Re: How does puts decide how to print a given object? — David Alan Black <dblack@...> 2001/12/10

Hello --

[#28096] The benefits of dynamic typing? — Roy Patrick Tan <rtan@...>

I have just recently read an old paper by Wirth "On the Design of

59 messages 2001/12/10
[#28108] Re: The benefits of dynamic typing? — Robert Feldt <feldt@...> 2001/12/10

This is a bit long...

[#28147] Re: The benefits of dynamic typing? — "Harry Ohlsen" <harryo@...> 2001/12/10

In article <3C153282.9000309@vt.edu>, "Roy Patrick Tan" <rtan@vt.edu>

[#28150] Re: The benefits of dynamic typing? — "Mark Hahn" <mchahn@...> 2001/12/10

[#28115] Ruby for Mac OS X — "Dan Hable" <DHable@...>

Hi,

18 messages 2001/12/10
[#28119] Re: Ruby for Mac OS X — Luc Heinrich <lucsky@...> 2001/12/10

On 10/12/2001 19:05, "Dan Hable" <DHable@phmining.com> wrote:

[#28885] Re: Ruby for Mac OS X — John Beppu <beppu@...9.org> 2001/12/18

[ date ] 2001/12/11 | Tuesday | 03:23 AM

[#28179] Ruby Musings — "John Kaurin" <jkaurin@...>

Ruby Musings (IMHO):

18 messages 2001/12/11

[#28272] Survey for new Rubyists — ptkwt@...1.aracnet.com (Phil Tomson)

23 messages 2001/12/11

[#28307] Reviews solicited for Ruby article — "Harry Ohlsen" <harryo@...>

I'm in the process of writing an article on Ruby for a computer science students'

17 messages 2001/12/12

[#28308] Rendering UML diagrams? — Robert Feldt <feldt@...>

Hi,

14 messages 2001/12/12

[#28495] internal server errors — Jack Dempsey <dempsejn@...>

hi all,

15 messages 2001/12/14

[#28500] A Review of "Ruby in a Nutshell" book — Johan Holmberg <holmberg@...>

27 messages 2001/12/14

[#28552] help with ^M (line endings ) removing — Dinakar Desai <Desai.Dinakar@...>

Hello:

12 messages 2001/12/14

[#28655] RDoc - Document Ruby source files — Dave Thomas <Dave@...>

25 messages 2001/12/16
[#28768] Re: RDoc - Document Ruby source files — Dave Thomas <Dave@...> 2001/12/17

Alexander Bokovoy <a.bokovoy@sam-solutions.net> writes:

[#28769] Re: RDoc - Document Ruby source files — Alexander Bokovoy <a.bokovoy@...> 2001/12/17

On Mon, Dec 17, 2001 at 11:19:11PM +0900, Dave Thomas wrote:

[#28789] Re: RDoc - Document Ruby source files — "Christian Boos" <cboos@...> 2001/12/17

[#28676] How do you do "character filtering" of a string using each_byte. — olczyk@... (Thaddeus L. Olczyk)

I'm trying to do several things where I produce new strings from old

10 messages 2001/12/16

[#28722] stderr from external process? — "MikkelFJ" <mikkelj-anti-spam@...1.dknet.dk>

I have asked this question before - maybe it is just not possible:

75 messages 2001/12/17
[#28923] Re: stderr from external process? — "MikkelFJ" <mikkelj-anti-spam@...1.dknet.dk> 2001/12/19

[#28960] RE: Ruby 'make' replacement (Re: stderr from external process?) — "Christian Boos" <cboos@...> 2001/12/19

Hello,

[#29094] Re: Ruby 'make' replacement (Re: stderr from external process?) — "Jason Horman" <jason@...> 2001/12/20

I wrote the Torrent library. I was not sure what license to pick so I picked

[#29096] Re: Ruby 'make' replacement (Re: stderr from external process?) — Robert Feldt <feldt@...> 2001/12/20

Just a thought on this thread (it might be obvious, I just want it to be

[#29117] Re: Ruby 'make' replacement (Re: stderr from external process?) — Dave Thomas <Dave@...> 2001/12/20

"MikkelFJ" <mikkelj-anti-spam@post1.dknet.dk> writes:

[#29156] Programming Ruby — "Marcio Barbosa" <argaeus@...> 2001/12/20

Hi,

[#28737] [Announcement] Ruby news weekly — Holden Glova <dsafari@...>

-----BEGIN PGP SIGNED MESSAGE-----

30 messages 2001/12/17

[#28749] Constant loss of memory with Kernel::load in a loop — "Jens Nissen" <frodo.hobbit@...>

We have developed a wonderful application under Windows 2K using Ruby 1.6.5

31 messages 2001/12/17
[#28755] Re: Constant loss of memory with Kernel::load in a loop — nobu.nokada@... 2001/12/17

At Mon, 17 Dec 2001 19:36:42 +0900,

[#28760] Re: Constant loss of memory with Kernel::load in a loop — ts <decoux@...> 2001/12/17

>>>>> "n" == nobu nokada <nobu.nokada@softhome.net> writes:

[#28774] Re: Constant loss of memory with Kernel::load in a loop — nobu.nokada@... 2001/12/17

At Mon, 17 Dec 2001 22:06:31 +0900,

[#28782] Re: Constant loss of memory with Kernel::load in a loop — ts <decoux@...> 2001/12/17

>>>>> "n" == nobu nokada <nobu.nokada@softhome.net> writes:

[#28803] Re: Constant loss of memory with Kernel::load in a loop — nobu.nokada@... 2001/12/17

At Mon, 17 Dec 2001 23:59:17 +0900,

[#29128] Re: Constant loss of memory with Kernel::load in a loop — matz@... (Yukihiro Matsumoto) 2001/12/20

Hi,

[#28855] [IDEA] creating stand-alone versions for easy distribution etc — Patrik Sundberg <ps@...>

hi list,

10 messages 2001/12/18
[#28856] Re: [IDEA] creating stand-alone versions for easy distribution etc — Robert Feldt <feldt@...> 2001/12/18

On Tue, 18 Dec 2001, Patrik Sundberg wrote:

[#28875] C++ preincrement operator — Paul Brannan <paul@...>

In Ruby, if I do this:

17 messages 2001/12/18
[#28876] Re: C++ preincrement operator — Peter Hickman <peter@...> 2001/12/18

Paul Brannan wrote:

[#28878] Re: C++ preincrement operator — Paul Brannan <paul@...> 2001/12/18

On Wed, Dec 19, 2001 at 02:09:03AM +0900, Peter Hickman wrote:

[#28879] Re: C++ preincrement operator — "Jack Dempsey" <dempsejn@...> 2001/12/18

so basically you're suggesting that any amount of stacking -'s or +'s past

[#28911] A Ruby programmer walked into a bar ... — "Harry Ohlsen" <harryo@...>

Now that I have your attention :-) ...

29 messages 2001/12/19
[#28985] Re: A Ruby programmer walked into a bar and ordered a Ruby-Thread — Luc Heinrich <lucsky@...> 2001/12/19

On 19/12/2001 15:46, "Harry Ohlsen" <harryo@zip.com.au> wrote:

[#29036] Re: A Ruby programmer walked into a bar and ordered a Ruby-Thread — HarryO <harryo@...> 2001/12/19

On Thu, 20 Dec 2001 07:58:47 +1100, Dave Thomas wrote:

[#29038] Re: A Ruby programmer walked into a bar and ordered a Ruby-Thread — "Mark Hahn" <mchahn@...> 2001/12/20

[#29046] Re: A Ruby programmer walked into a bar and ordered a Ruby-Thread — Dave Thomas <Dave@...> 2001/12/20

"Mark Hahn" <mchahn@facelink.com> writes:

[#28926] Stream? — Ron Jeffries <ronjeffries@...>

Is there a memory stream object in Ruby, analogous to Smalltalk's

14 messages 2001/12/19

[#28977] overriding methods: (almost) a replacement for alias_method — Paul Brannan <paul@...>

I think almost all of us will agree that it's pretty ugly to do:

17 messages 2001/12/19

[#29014] But is it Fun? — edwardhatfield1@... (Edward Hatfield)

I've been watching Ruby with great interest over

19 messages 2001/12/19

[#29265] upper case to lower — "Bashar A. Asad" <baasad@...>

hello,

25 messages 2001/12/21

[#29296] XEmacs problems with ruby-mode.el

Hi,

17 messages 2001/12/22

[#29327] a better way? — Ron Jeffries <ronjeffries@...>

I was writing a little code that cached a function value, and wound up

38 messages 2001/12/23
[#29328] Re: a better way? — David Alan Black <dblack@...> 2001/12/23

Hi --

[#29331] Re: a better way? — "Hal E. Fulton" <hal9000@...> 2001/12/23

----- Original Message -----

[#29488] Python and Ruby: a comparison — Ron Stephens <rdsteph@...>

I initiated a thread over on comp.lang.python which has turned into

68 messages 2001/12/27
[#29677] Re: Python and Ruby: a comparison — Ron Stephens <rdsteph@...> 2001/12/30

Very interesting idea. Unfortunately, I doubt if it woudl be possible. For one

[#29696] Re: Python and Ruby: a comparison — "Conrad Schneiker" <schneiker@...> 2001/12/30

"Ron Stephens" <rdsteph@earthlink.net> wrote:

[#29869] Re: Python and Ruby: a comparison — Michael Kelly <mkelly2002NOSPAM@...> 2001/12/31

On Mon, 31 Dec 2001 12:26:46 +1100, Michael Lucas-Smith >Check out

[#29871] Re: Python and Ruby: a comparison — Dan Sugalski <dan@...> 2001/12/31

At 02:02 AM 1/1/2002 +0900, Michael Kelly wrote:

[#29541] New Rubygarden poll — Dave Thomas <Dave@...>

27 messages 2001/12/28

[#29545] RDoc now displays source — Dave Thomas <Dave@...>

17 messages 2001/12/28

[#29596] extending method of class A to support arguments of class B by promoting `self' to class B — Tomasz Wegrzanowski <taw@...>

(Names of classes chosen arbitrarily, just to show issue)

18 messages 2001/12/28

[#29613] Extending Ruby on Windows platform using VC++ IDE — "Alan Moyer" <moyer4@...>

Hi,

11 messages 2001/12/29

[#29667] Yet Another Newbie — Michael Kelly <mkelly2002NOSPAM@...>

Yet Another Newbie. :)

13 messages 2001/12/29

[#29713] Ruby parsers in Ruby — ptkwt@...1.aracnet.com (Phil Tomson)

Wouldn't it be cool to have Ruby playing with Parrot before Python or even

20 messages 2001/12/30

[#29773] Proc.class vs yield — Michael Lucas-Smith <s3225202@...>

Hi,

49 messages 2001/12/31
[#29782] Re: Proc.class vs yield — David Alan Black <dblack@...> 2001/12/31

Hello --

[#29795] Re: Proc.class vs yield — Michael Lucas-Smith <s3225202@...> 2001/12/31

def someThing (&a, &b)

[#29796] Re: Proc.class vs yield — David Alan Black <dblack@...> 2001/12/31

Hi --

[#29797] Re: Proc.class vs yield — Michael Lucas-Smith <s3225202@...> 2001/12/31

>

[#29802] Re: Proc.class vs yield — David Alan Black <dblack@...> 2001/12/31

Hi --

[#29849] Re: Proc.class vs yield — Michael Lucas-Smith <s3225202@...> 2001/12/31

That's a good solution, thanks.

[#29867] Re: Proc.class vs yield — David Alan Black <dblack@...> 2001/12/31

Hi --

[#29798] FXRuby FreeRIDE Spike uploaded. — Phlip <phlip_cpp@...>

Rubies:

14 messages 2001/12/31

[#29886] Ruby/Python: Software Engineering — noone <nanotech@...>

All:

36 messages 2001/12/31
[#29889] Re: Ruby/Python: Software Engineering — Tomasz Wegrzanowski <taw@...> 2001/12/31

On Tue, Jan 01, 2002 at 05:03:35AM +0900, noone wrote:

[#29904] Re: Ruby/Python: Software Engineering — noone <nanotech@...> 2001/12/31

Tomasz/All:

[#29887] RE: Ruby multi-dimensional Hash question?---Any one out there willing to give this questions a try? — "Crandall, Jeff W" <jeff.w.crandall@...>

Anyone? Is this the correct mailing list to try and get

18 messages 2001/12/31

[#29895] How to check free diskspace? — Le Wang <lewang@?.?.bigfoot.com (nospam)>

Hi all,

23 messages 2001/12/31

[ruby-talk:28295] vector and quaternion classes

From: Issac Trotts <ITrotts@...>
Date: 2001-12-12 00:35:07 UTC
List: ruby-talk #28295
Here are some (alpha) classes for 3D geometry, just for fun:


#!/usr/bin/env ruby
#
# alg3d.rb : an any-dimensional vector and 3D spinor (quaternion)
#
# Copyright (c) 2001 Issac Trotts <itrotts at idolminds dot com>
# Under the Ruby license
# 

module GLIT # alg3d is part of the GL Interaction Tools library

    class Vec  # any-dimensional vector class
        attr_reader :a # array of elements

        #ZERO_VEC = GLIT::Vec.new([0.0, 0.0, 0.0])

        def initialize(a=[0.0, 0.0, 0.0])
            if not a.respond_to?('[]') 
                raise ArgumentError
            end
            @a = a; 
        end
        def [](i)
            @a[i]
        end
        def []=(i, x)
            @a[i] = x
        end
        def abs
            Math.sqrt( self.dot(self) )
        end
        def abs2
            self.dot(self)
        end
        def copy
            Vec.new(@a[0..-1])
        end
        def normalized
            self.copy/self.abs
        end
        def normalize!
            mag = self.abs
            0.upto(@a.size-1) { |i| @a[i] /= mag }
        end
        def dot(v)
            (self.size == v.size) or raise ArgumentError 
            s = 0.0
            0.upto(@a.size-1) { |i| s+= @a[i]*v[i] }
            s
        end
        def gp(v) # clifford / geometric product : returns Quat
            (self.size == v.size) or raise ArgumentError 
            Quat.sv2q(self.dot(v), self.cross(v))
        end
        def cross(v)
            (self.size == 3 and v.size == 3) or raise ArgumentError
            Vec.new([@a[1]*v[2]-@a[2]*v[1],
                     @a[2]*v[0]-@a[0]*v[2],
                     @a[0]*v[1]-@a[1]*v[0]])
        end
        #def collect
            #Vec.new( @a.collect ) # ?
        #end
        #def collect2(v)
            #Vec.new( (0 .. @a.size-1).collect { |i| yield @a[i], v[i] } )
        #end
        #alias map  collect
        #alias map2 collect2
        def +(v) # v = vector
            (self.size == v.size) or raise ArgumentError 
            r = self.copy
            0.upto(@a.size-1) { |i| r[i] += v[i] }
            r
        end
        def -(v)
            (self.size == v.size) or raise ArgumentError 
            r = self.copy
            0.upto(@a.size-1) { |i| r[i] -= v[i] }
            r
        end
        def *(s) # s = scalar
            s.kind_of?(Float) or raise ArgumentError
            r = self.copy
            0.upto(@a.size-1) { |i| r[i] *= s }
            r
            #self.map { |x| x*s }
        end
        def /(s)
            s.kind_of?(Float) or raise ArgumentError
            r = self.copy
            0.upto(@a.size-1) { |i| r[i] /= s }
            r
            #self.map { |x| x/s }
        end
        def size
            @a.size
        end
    end

    include Math

   
    class Quat   # Quaternion (a.k.a. 3D Spinor) s+B = s+Iv

        attr_reader :a     # array of elements

        def initialize(a=[0.0, 0.0, 0.0, 1.0])
            if a.respond_to?('[]')  # all 4 elts of quat specified by 4D
vector
                if a.size == 4
                    @a = a[0..3]
                elsif a.size == 3   # quat from 3D vector
                    @a = a[0..2]+[0.0]
                else
                    raise ArgumentError
                end
            elsif a.kind_of?(Float) or a.kind_of?(Fixnum) # quat from scalar
                @a = [0.0, 0.0, 0.0, a]
            end 
        end
        def copy
            Quat.new( @a[0..-1] )
        end
        ##
        # construct quat rotating vector f to vector t (up to scale)
        def Quat.vv2q(f, t) 
            (f.respond_to?('[]') and f.size == 3 and 
             t.respond_to?('[]') and t.size == 3) or raise ArgumentError
            f = f.normalized
            t = t.normalized
            f.gp(f+t)
            ft = f.gp(t)
            Quat.sv2q(1.0+ft[3], ft[0..2]) / (f+t).abs
        end
        def Quat.rotation(f, t)
            Quat.vv2q(f, t)
        end
        def Quat.sv2q(s, v)   # scalar and vector --> new quat
            (s.kind_of?(Float) and v.respond_to?('[]') and v.size == 3) or 
                raise ArgumentError
            Quat.new(v[0..2]+[s]) # array-concatenation, not vec addition
        end
        def Quat.rpy2q(roll, pitch, yaw) # pilferred from the FoX GUI lib
            r=0.5*roll;
            p=0.5*pitch;
            y=0.5*yaw;
            sr=sin(r); cr=cos(r);
            sp=sin(p); cp=cos(p);
            sy=sin(y); cy=cos(y);
            Quat.new([
                sr*cp*cy-cr*sp*sy,
                cr*sp*cy+sr*cp*sy,
                cr*cp*sy-sr*sp*cy,
                cr*cp*cy+sr*sp*sy])
        end

        def exp # Quaternion exponential
            mag = self.v.abs 
            Math.exp(self.s) * Quat.sv2q(cos(mag), sin(mag)*self.v/mag)
        end

        # Rotation about axis ax by t_rads radians
        def Quat.axis_rotation(ax, t_rads) 
            if len=axis.abs
                a=sin(t/2.0)*ax/len;
                Quat.sv2q(Math.cos(t/2.0), a)
            else
                Quat.sv2q(1.0, [0.0]*3)
            end
        end


        def rotate(v)
            (self.inverse * Quat.new(v) * self ).v 
        end
        def abs2
            @a[0]*@a[0] + @a[1]*@a[1] + @a[2]*@a[2] + @a[3]*@a[3] 
        end
        def abs
            Math.sqrt(@a[0]*@a[0] + @a[1]*@a[1] + @a[2]*@a[2] + @a[3]*@a[3])
        end
        def normalize!
            mag = self.abs
            @a[0] /= mag
            @a[1] /= mag
            @a[2] /= mag
            @a[3] /= mag
        end
        def s       # scalar part
            @a[3]
        end
        def v       # dual of bivector part
            Vec.new(@a[0..2])
        end
        def [](i)
            @a[i]
        end
        def axis 
            vlen=self.v.abs
            vlen>0.0 ? self.v/vlen : Vec.new([0.0, 0.0, 0.0])
        end
        def angle_rads
            2.0*Math.atan2(self.v.abs, self.s) 
        end
        def *(o) # o = Float, Fixnum or Quat
            if o.kind_of?(Float) or o.kind_of?(Fixnum)
                Quat.new([ @a[0]*o, @a[1]*o, @a[2]*o, @a[3]*o ])
            elsif o.kind_of?(Quat)
                s = self.s*o.s - self.v.dot(o.v)
                v = self.s*o.v - self.v.cross(o.v) + self.v*o.s
                Quat.sv2q(s, v)
            else
                raise ArgumentError
            end
        end
        def /(s) # s = scalar (Float)
            if s.kind_of?(Float) or s.kind_of?(Fixnum)
                Quat.new([ @a[0]/s, @a[1]/s, @a[2]/s, @a[3]/s ])
            else
                raise ArgumentError, "s = #{s.inspect}"
            end
        end
        def +(q) # q = quat
            Quat.new([ @a[0]+q[0],  @a[1]+q[1],  @a[2]+q[2],  @a[3]+q[3] ])
        end
        def -(q)
            Quat.new([ @a[0]-q[0],  @a[1]-q[1],  @a[2]-q[2],  @a[3]-q[3] ])
        end
        def conj 
            Quat.new([ -@a[0], -@a[1], -@a[2], @a[3] ])
        end
        def inverse
            s = self.abs2
            Quat.new( [-@a[0]/s, -@a[1]/s, -@a[2]/s, @a[3]/s] )
        end
    end

end # module GLIT

# left-multiplication by floats
class Float
    alias mul *
    def *(o)
        if o.kind_of?(GLIT::Vec)
            o*self
        elsif o.kind_of?(GLIT::Quat)
            o*self
        else
            self.mul(o)
        end
    end
end

require 'runit/testcase'

class Alg3dtest < RUNIT::TestCase
    include GLIT

	def setup
        @N = 100        # number of times to run each random test 
        @eps = 1e-9     # error tolerance
	end
	
    def test_vector
        puts
        0.upto(@N) {
            u = Vec.new([rand(), rand(), rand()])
            v = Vec.new([rand(), rand(), rand()])
            w = u.cross(v)
            err = w.dot(u)
            assert(err < @eps)
            err = w.dot(v)
            assert(err < @eps)
            u.normalize!
            assert((1.0 - u.abs).abs < @eps)
        }
    end

	def test_rotation
        puts
        0.upto(@N) {
            u = Vec.new([rand(), rand(), rand()])
            v = GLIT::Vec.new([rand(), rand(), rand()])
            q = GLIT::Quat.rotation(u,v)
            #puts "q = #{q.inspect}"
            v2 = q.rotate(u)
            #puts "u = #{u.inspect}"
            #puts "v = #{v.inspect}"
            #puts "v2 = #{v2.inspect}"
            err = (v.normalized-v2.normalized).abs
            puts "err = #{err}"
            #puts "u.abs = #{u.abs}"
            #puts "v2.abs = #{v2.abs}"
            assert(err < @eps)
        }
	end

    def test_quat_inverse
        puts
        0.upto(@N) {
            q = GLIT::Quat.new([rand(), rand(), rand(), rand()])
            #puts "q*q.inverse = #{(q*q.inverse).inspect}"
            err = (q*q.inverse - Quat.new([0.0]*3 + [1.0])).abs
            puts "err = #{err}"
            assert(err < @eps)
        }
    end

end

#--- main program ----
if __FILE__ == $0
	require 'runit/cui/testrunner'
	RUNIT::CUI::TestRunner.run(Alg3dtest.suite)
end

		

In This Thread

Prev Next