Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!haven!ames!pasteur!agate!saturn!skinner From: skinner@saturn.ucsc.edu (Robert Skinner) Newsgroups: comp.graphics Subject: Re: 3D Rotations/Instancing Message-ID: <6204@saturn.ucsc.edu> Date: 2 Feb 89 05:09:39 GMT References: <65@sdcc10.ucsd.EDU> <5909@leadsv.UUCP> <25598@sgi.SGI.COM> <5941@leadsv.UUCP> Reply-To: skinner@saturn.ucsc.edu (Robert Skinner) Distribution: usa Organization: University of California, Santa Cruz Lines: 60 In article <5941@leadsv.UUCP> kallaus@leadsv.UUCP (Jerry Kallaus) writes: >> In article <5909@leadsv.UUCP>, kallaus@leadsv.UUCP (Jerry Kallaus) writes: > (Jerry demonstrates an incredible lack of math talent.) >> In article <25598@sgi.SGI.COM>, andru@rhialto.SGI.COM (Andrew Myers) writes: > (Andrew notices this.) > >Thanks to Andrew Myers for pointing out errors in my previous posting in >this thread. They really were gross. I abandoned that approach, and offer >the following obsersvation. > ... Jerry adds more math... This is all true, but (IMHO) it seems too complicated. Remember what orthonormal means: Each column of a matrix is normal to each other column. (And since its transpose is its inverse, which is also orthonormal, the same is true of rows.) We can use that to fix up the matrix very quickly. Look at it this way, if we have the following vector/matrix: [x y z] | a b c | | d e f | | g h i |, then the X axis, [1 0 0], gets transformed into [a b c], and Y: [0 1 0] --> [d e f] and Z: [0 0 1] --> [g h i] now since X x Y = Z, this means that [a b c] x [d e f] = [g h i] So normalize [a b c] to get [a' b' c'], then compute [a' b' c'] x [d e f] and normalize to get [g' h' i'] Now you can calculate the correct Y component from the corrected X and Z components. [g' h' i'] x [a' b' c'] = [d' e' f'] You don't have to normalize, be cause X' and Z' are already unit length and perpendicular. --- This seems simpler to me, even though you have to compute two square-roots to normalize. But you use Newton's method to compute your own square-root. The vectors you're normalizing are always near unit length, so you can use 1.0 as a starting point and get pretty fast convergence. You may need only 3 or 4 steps (with one + and one * per step, I think), and you can unroll the loop to make it even faster. The nice thing is that you can tailor the routine to make it as accurate as you want. If I remember correctly, you were starting with some integer approximations anyway, so a few times through this loop may be adequate. hope this helps, Robert Skinner skinner@saturn.ucsc.edu