Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!njin!idunno!gauss!markv From: markv@gauss.Princeton.EDU (Mark VandeWettering) Newsgroups: comp.graphics Subject: Re: Rotation Matries Message-ID: <1172@idunno.Princeton.EDU> Date: 11 Jul 90 04:14:45 GMT References: <40050@mips.mips.COM> Sender: news@idunno.Princeton.EDU Reply-To: markv@gauss.Princeton.EDU (Mark VandeWettering) Organization: Princeton University Lines: 61 In article <40050@mips.mips.COM> koblas@mips.COM (David Koblas) writes: >This is a simple problem that I've spent far too long on. David, David, David. Tsk, Tsk, Tsk :-) Gotta spend more time in the lab late at night :-) Well, I dug up my Math for Siggraph notes, and found what I think you are looking for. You want to convert a rotation matrix to a set of Euler angles. This also appeared in 1985 Siggraph, the article is by Ken Shoemake, "Animating Rotations with Quaternion Curves". This is excerpted without permission: "While converting a matrix to a uniform quaternion only involves sign ambiguity of square roots, converting to Euler angles involves inverse trigonometric functions, as we can only directly determine the sin's and cos's of the angles. Some convention, such as principle angles, must be adopted. However, interpolation paths will vary greatly, depending on the choice of angles. Setting that problem aside, here's a way to extract the sin's and cos's. Looking at the previous euqation, sin(theta) can be read off directly as -M[1][3]. Use the trigonometric identity cos(theta) = +-sqrt(1 - sin(theta)^2) to compute cos(0) to within a sign, which is the best we can do. Assuming cos(theta) is not zero, obtain the other sin's and cos's from the other angles from sin(theta) = -M[1][3] cos(theta) = sqrt(1 - sin(theta)^2) sin(psi) = M[2][3] / cos(theta) cos(psi) = M[3][3] / cos(theta) sin(phi) = M[1][2] / cos(theta) cos(phi) = M[1][1] / cos(theta) If cos(theta) is zero, then we must avoid dividing by zero. It also becomes impossible to distinguish roll from yaw. Adopting the convention that the yaw angle is zero allows sin(psi) = -M[3][2] cos(psi) = M[2][2] sin(phi) = 0 cos(phi) = 1 [end quotation] Shoemake also mentions that due to the problems with "gimbal lock", the result of this is often ill-defined. His quaternion formulation is noticeably free of such problems. >Any ideas, would be appreciated. And CODE would be celebrated with >champagne.. Well, Dave, I will expect the champagne at Siggraph, even though I don't have any code (yet). I do think that there is a much simpler way to formulate the entire problem, having to do with maintaining the "right" matrix and merely inverting and converting to spherical coordinates to determine your latitude and longitude. Email to interested parties. Mark