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.
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.
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.
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§ * cos(t)
y = r * sin§ * sin(t)
z = r * cos§
If you already have x,y,z and want to switch it back, this is the conversion:
r = sqrt(xx + yy + 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]).