mpogue@vis01.webo.dg.com (Mike Pogue) (01/24/91)
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.
turk@Apple.COM (Ken "Turk" Turkowski) (02/01/91)
In article <87540@tut.cis.ohio-state.edu> <thamer@gecko.cis.ohio-state.edu> 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? Forget about Euler angles. Use coordinate frames. Euler angles have singularity problems. Coordinate frames are robust and don't even need trigonometry per se. See the chapter, "The Use of Coordinate Frames in Computer Graphics" in Graphics Gems, printed by Academic Press and edited by Andrew Glassner. -- Ken Turkowski @ Apple Computer, Inc., Cupertino, CA Internet: turk@apple.com Applelink: TURK UUCP: sun!apple!turk
davet@dgp.toronto.edu (Dave Tonnesen) (02/02/91)
In article <11937@goofy.Apple.COM> turk@Apple.COM (Ken "Turk" Turkowski) writes: >In article <87540@tut.cis.ohio-state.edu> <thamer@gecko.cis.ohio-state.edu> 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? > >Forget about Euler angles. Use coordinate frames. Euler angles >have singularity problems. Coordinate frames are robust and don't >even need trigonometry per se. See the chapter, "The Use of >Coordinate Frames in Computer Graphics" in Graphics Gems, printed >by Academic Press and edited by Andrew Glassner. >-- >Ken Turkowski @ Apple Computer, Inc., Cupertino, CA >Internet: turk@apple.com >Applelink: TURK >UUCP: sun!apple!turk Or use quaternions. "Animating Rotation with Quaternion Curves" by Ken Shoemake. Graphics, vol 18, num 3, 1985, pgs 245-254. Reprinted 1989 SIGGRAPH course notes #23, Math for SIGGRAPH. "Quaternion Calculus for Animation" by Ken Shoemake. 1989 SIGGRAPH course notes #23, Math for SIGGRAPH, pgs 187-205. Given any two vectors A and B, using the dot and cross products you can find the values needed to rotate A to B. From the dot product you can derive the angle (between 0 to pi). A dot B = |A| |B| cos(theta) The cross product A x B = C gives you a vector C which is perpendicular to both A and B. I.e. an axis to rotate about. (Of course some special case when A and B are parallel). The rotation can easily be converted to a quaternion or matrix. Quaternion mutliplication can be used to rotate the vector. --------- David Tonnesen davet@dgp.toronto.edu