[comp.graphics] Rotation Matries

koblas@mips.COM (David Koblas) (07/11/90)

This is a simple problem that I've spent far too long on.  

Given an arbitrary rotation matrix M, what combonation of three
rotation matries can generate M.  i.e

	Ry Rx Rz = M

Thus what I'm interested in is the angle theata for each of those
rotation matries.  What this has to do with is that I've done
an arbitrary number of RxRy's to generate M, and now I need to
figure out a way to decompose and regenerate M as a set of 
three angles (Longitude, Latitude and Twist).

Any ideas, would be appreciated.  And CODE would be celebrated with
champagne..  

-- 
name : David Koblas                        domain: koblas@cs.uoregon.edu
place: Nowhere, I'm just an AI batch job.  domain: koblas@mips.com
quote: "Time has little to do with         domain: koblas@riacs.edu
	infinity and jelly donuts."        domain: koblas@stellar.arc.nasa.gov

markv@gauss.Princeton.EDU (Mark VandeWettering) (07/11/90)

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

ph@miro.Berkeley.EDU (Paul Heckbert) (07/21/90)

David Koblas (koblas@mips.COM)
> Given an arbitrary rotation matrix M, what combonation of three
> rotation matries can generate M.  i.e
>	Ry Rx Rz = M

If you want code, check out Ned Greene's contribution to the book
"Graphics Gems", that is coming out in August.  Ned has an article in
the book on extraction of rotation, translation, and scaling parameters
from arbitrary 4x4 matrices.

You can see the book at the Academic Press booth at SIGGRAPH.  This
book is a collection of about 100 "gems" (short articles) of computer
graphics lore contributed by about 50 authors from around the country
and around the world.  It was edited by Andrew Glassner.  It looks like
the book will contain some very useful information for graphics programmers,
including a large appendix of C code.

I was one of the contributors to the book, however, so my opinions are
somewhat biassed.

Paul Heckbert, Computer Science Dept.
Evans Hall, UC Berkeley			INTERNET: ph@miro.berkeley.edu
Berkeley, CA 94720			UUCP: ucbvax!miro.berkeley.edu!ph