Path: utzoo!attcan!uunet!dg!vis01!mpogue From: mpogue@vis01.webo.dg.com (Mike Pogue) Newsgroups: comp.graphics Subject: Re: Rotation question ... Message-ID: <1262@dg.dg.com> Date: 23 Jan 91 19:04:50 GMT References: <87540@tut.cis.ohio-state.edu> Sender: root@dg.dg.com Reply-To: mpogue@vis01.webo.dg.com (Mike Pogue) Organization: Data General Corporation, Research Triangle Park, NC Lines: 54 In article <87540@tut.cis.ohio-state.edu>, thamer@gecko.cis.ohio-state.edu (M T ) writes: |> |> Assuming RHS (positive Z pointing out of the screen), and given |> an object at the origin, how can one determine the Euler angles |> to rotate the object around the X and Y axes so as to align it |> (point it in the direction) of an arbitrary unit direction vector D? |> |> Thanks, |> |> -Mustafa This might be the long way around, but this is how I solved this problem: 1) Your problem is equivalent to finding the Euler rotation, that is, the single rotation that changes one orientation to another. 2) Consider an orientation to be a direction vector, and a twist angle around that vector. 3) Consider the Euler rotation to be composed of three rotations, each simpler, and applied in succession. 4) The first rotation aligns the direction vectors in a sinlge plane only, say the XY plane (X = 0). Rotate around the Z axis until the starting direction vector (picked arbitrarily as (1,0,0) lines up with the projection of the destination direction vector onto the Z=0 plane. 5) Second, rotate around a vector perpendicular to the projection in step 4) (remember that a 90 degree rotation of (X,Y) around the Z axis is (-Y,X) ) until the direction vector is aligned with the final destination direction vector. 6) Third, rotate around the final direction vector (this is the "twist") until the object is where you want it. 7) All the three rotations in step s 4, 5, and 6 can be expressed easily as quaternions (see "Graphics Gems" for a good intro and some sample code). They will then compose easily as Q4 * Q5 * Q6. 8) Convert the resulting quaternion back to Euler angles. This formula has been published, and might be in Graphics Gems (I don't remember).... Sounds complicated, but isn't all that difficult. Good luck! -- Mike Pogue Data General Corp. Speaking for myself, not my company.... Westboro, MA.