# Y-Angle rotation from 3-d vector

## Recommended Posts

Steve_Segreto    2080
Hi guys,

Given a 3-d normalized vector (x,y,z) that represents some rotation around the (x,z) axis, how can I figure out the Y-angle (in radians) that this vector represents?

##### Share on other sites
Gangi    100
[quote name='Steve_Segreto' timestamp='1312924733' post='4846899']
Hi guys,

Given a 3-d normalized vector (x,y,z) that represents some rotation around the (x,z) axis, how can I figure out the Y-angle (in radians) that this vector represents?
[/quote]

I dont't know how to do it but this books are pretty good so maybe you can find what you are looking for.

3D_Math_Primer_For_Graphics_And_Game_Development - WordWare
Mathematics_for_Game_Developers - Thompson

##### Share on other sites
You can't, because a 3D vector alone is not enough information to represent a rotation (or orientation) - it can represent an axis of rotation, but to represent a rotational offset we need to define a basis for our transform... like another vector, an angle, an orientation, representing the existing orientation *before* we rotated it, from which we may measure a difference.
It can be done using trigonometry, for example using another vector... if I remember correctly its 2 * acos (theta) radians, where theta = the dot product of two vectors. That will work for 3D, or any 2D component axis (say, the XZ plane for precious Y rotation value). You simply perform a 2D dotproduct instead of a 3D one.

##### Share on other sites
Steve_Segreto    2080
Thanks guys!

I figured it out using a second vector (v1) and arc tangent like this:

[size="2"] D3DXVECTOR3 a = v0 - v1;

D3DXVec3Normalize( &a, &a );

[/size][size="2"][color="#0000ff"][color="#0000ff"]
[size="2"][color="#0000ff"] [/color][/size]
return[/color][/color] ([color="#0000ff"][color="#0000ff"]float[/color][/color])(atan2f(a.x, a.z);[/size]