# Converting a Vector to Euler Rotations

Started by Oct 04 2001 11:59 PM

,
1 reply to this topic

###
#2
Members - Reputation: **146**

Posted 05 October 2001 - 01:22 AM

Well, this depends! Its posible to give any 3D direction of a vector with two angles! the third may be zero, this is if angle (xrot,yrot,zrot) 0,0,0 is the vector (x,y,z) 0,0,1 !

Imagen the vector rotating around its own axis! Do the vector have a spesific directin here? Same as asking for the front of a perfect sphere

The other problem is what is the order of you rotations?

xrot,yrot,zrot //the order

gives a different result then

zrot,yrot,xrot

So first you need to deside what number of angles you need, and what rotation order you already use when converting from angles to vectors!

A simple way to do this is:

say that the angle 0,0 (xrot, yrot) is vector 0,0,1 (x,y,z)

we start with the yrot!

convert your vector to a 2D img, by removing the y axis! Then find the sin and cos of your vector... (if the totale length of you 2D vector is 1, its cordinates is sin and cos)

use a func to find angle by sin, and you have the yrot!

The only problem is when the vector is pointing straight up, or down! If this is the case, dont mind! set yrot to 0

Now we need to use a special trick! Rotate your vector (maybe a temp one), (yrot *-1) around the y axis!

This is because if you convert your new vector to a 2D vector, by removing the x axis, you got the xrot!(get it the same way as you got yrot)

WOW :-)

This is the simplest way i think! If your going to get all xrot yrot and zrot, you need to define two vectors! Because your angle need a pointing direction, and a up direction, with 90 deg between, and if you got these two, just cross product them, and you got a matrix!(3,3) How do you get the xrot,yrot and zrot from a matrix? The same way!

Loop trough all the axis, the reverse way of how you translate from angles to matrixses!

Reed all the angles of the first,

Rotate the matrix with the angle you just got *-1

continue to the next axis!

This i think is called a revese rotation calc....

ok?

Imagen the vector rotating around its own axis! Do the vector have a spesific directin here? Same as asking for the front of a perfect sphere

The other problem is what is the order of you rotations?

xrot,yrot,zrot //the order

gives a different result then

zrot,yrot,xrot

So first you need to deside what number of angles you need, and what rotation order you already use when converting from angles to vectors!

A simple way to do this is:

say that the angle 0,0 (xrot, yrot) is vector 0,0,1 (x,y,z)

we start with the yrot!

convert your vector to a 2D img, by removing the y axis! Then find the sin and cos of your vector... (if the totale length of you 2D vector is 1, its cordinates is sin and cos)

use a func to find angle by sin, and you have the yrot!

The only problem is when the vector is pointing straight up, or down! If this is the case, dont mind! set yrot to 0

Now we need to use a special trick! Rotate your vector (maybe a temp one), (yrot *-1) around the y axis!

This is because if you convert your new vector to a 2D vector, by removing the x axis, you got the xrot!(get it the same way as you got yrot)

WOW :-)

This is the simplest way i think! If your going to get all xrot yrot and zrot, you need to define two vectors! Because your angle need a pointing direction, and a up direction, with 90 deg between, and if you got these two, just cross product them, and you got a matrix!(3,3) How do you get the xrot,yrot and zrot from a matrix? The same way!

Loop trough all the axis, the reverse way of how you translate from angles to matrixses!

Reed all the angles of the first,

Rotate the matrix with the angle you just got *-1

continue to the next axis!

This i think is called a revese rotation calc....

ok?