View Full Version : converting a 3D vector into three euler angles?

01-27-2004, 11:52 AM
In 2D you can view a point's X,Y coordinates as a vector and that vector can be thought of a describing a direction from the origin -- or a rotation around the origin.

To get the 2D angle of rotation you can do:
angle = tan(y/x);

Easy, but how do you do it with a 3D vector? I know in 3D you need three angles to represent any possible direction. Seems like there should be three simple trig equations for finding these angles when you have X,Y,Z but I can't seem to find the right Google phrase to search for today.

Please help!

01-27-2004, 12:08 PM

Just remembered that a lone 3D vector can't fully describe three Euler angles. Maybe two angles, but that's it.

That would explain why I can't find any info on how to do it! I'll try a matrix method.

NEVER MIND http://www.opengl.org/discussion_boards/ubb/smile.gif

02-13-2004, 01:06 AM
There's a way, by considering the length of the vector as an angle. Then you just convert an axis/angle to euler angles, which is pretty usual. In fact this is one way Exponential Map can be coded.

02-13-2004, 06:09 AM
You can post it in 3D coordinates. You must think of a sphere, rather than just a circle.
Let r = radius, t = angle on x-y plane, & p = angle off of z-axis. Then you get:

x = r * sin(p) * cos(t)
y = r * sin(p) * sin(t)
z = r * cos(p)

If you already have x,y,z and want to switch it back, this is the conversion:

r = sqrt(x*x + y*y + z*z)
t = arctan(y/x)
p = arccos(z/r)
*For computing p, it's easier to compute r first, then use it as the denominator (assuming ![x = y = z = 0]).