# Y-Angle rotation from 3-d vector

This topic is 2537 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

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?

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
Thanks guys!

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

D3DXVECTOR3 a = v0 - v1;

D3DXVec3Normalize( &a, &a );

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

1. 1
2. 2
Rutin
25
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 22
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631764
• Total Posts
3002210
×