# Thread: Find angle in 3D space, from two vectors

1. ## Find angle in 3D space, from two vectors

Hi Everybody. I've a simple (I think) question, but can't find the answer. I'm building a graphical application in 3D where I need to rotate objects and to do coordinate conversions on the representation of their orientation. My explanation here use the right handed system (X left, Y top, Z forward). The object orientation is actually the position and orientation of its local space into the global space.

One of these conversions is to compute Euler's angles (well that's Cardan or Tait-Bryan, but everybody says Euler for years) yaw, pitch and roll from two vectors local-Z and local-Y. I know how to compute yaw and pitch, but I'm having hard problems with roll.

You may forget about all that was said above and just consider the problem this way: in a 3D space O,X,Y,Z:

------------------

- we have two unit vectors that are orthogonal LY (LYx, LYy, LYz) and LZ (LZx, LZy, LZz)
- LZ can be anything in the global space, and LY can be anything perpendicular to LZ
- we can define a plan P perpendicular to LZ (hence including LY)

Now, we project the global vertical axis Y onto P along LZ and we want to know the coordinates of its projection named Y1 (Y1x, Y1y, Y1z).

-----------------

If I can solve Y1xyz according to LZxyz and LYxyz, then I'll be able to measure the angle Y1,LY which happens to be the roll angle.

BTW, LZ is the direction in which the object is looking at, and LY is the direction of the "top" of the object, the two vectors define a 3-degree of freedom orientation.

You'll probably say it's a very basic exercise, but I'm not a mathematician, and you would help me to a great extend if you know the formula. Thanks to you math geniuses!

2. This wording, "project the global vertical axis Y onto P along LZ" is confusing me. Isn't P orthogonal to LZ? On what, exactly, do you wish to project the Y axis?

3. Originally Posted by Ackbeet
Isn't P orthogonal to LZ? On what, exactly, do you wish to project the Y axis?
Thanks for your time. Yes P is orthogonal to LZ. But, as LZ may be anything, Y may not be parallel to P. I want to project Y on P, the projection being made using LZ direction (orthogonal projection?). I'm sorry if the wording is not totally accurate, English is not my native language.