View Full Version : vector to euler rotation

04-05-2005, 09:44 PM
I'm writting a script where I'm trying to align an object to a face normal. I have the face normal, but I don't know how to translate the face normal into regular eular x y z rotations. Anyone have any ideas?

04-06-2005, 02:59 AM
simple way :
create 2 locators
leave one at 0 0 0, move the other to the vector ....if the vec is <<3,5,5>> you move it there
aimconstraint the one at origin to the other, thats you rotations. copy those into the objects

04-06-2005, 03:30 AM
The aim constraint way is sufficient, but in case if you want more "clean" way:

Project your vector on each plane ( on XY : Z = 0, on YZ : X = 0 etc ) then for every plane calculate the angle from start angle axis and it's projected vector. You can do that using angle command or some linear algebra equations.

06-05-2005, 07:46 PM
Be aware your problem is underconstrained - there is more than one rotation that will align an object along a normal (since it could spin around the normal at any angle).

I would build a 3x3 matrix that corresponds to the rotation you want, then convert to Euler angles. Each row of the matrix will be the direction you want the object's X, Y, and Z axis to point after the rotation.

Assuming you want the object's Z axis along your face normal, just use the face normal's coordinates as the third row of the matrix. To get the other two rows you need the X and Y axes. I'd construct these by first arbitrarily picking the Y axis as (0,1,0), then cross Y and Z to get your X axis, and finally cross X and Z to "fix up" the Y axis so that it's orthogonal to the others. Normalize all these vectors, and you've got your matrix. Then use the standard matrix-to-euler conversion which goes like this:

heading = atan2(m[2][0], m[2][2]);
pitch = asin(-m[2][1]);
bank = atan2(m[0][1], m[1][1]);

(where m[x][y] is the 3-by-3 rotation matrix with rows as the orthonormal axes you want to object to end up with)

06-06-2005, 06:23 AM
And with all of that ... never forget about your rotation order !

Hey ! Is that you Dan ?? :-)


06-19-2005, 10:11 PM
Yep it's me! How is life at Pixar? I'm currently very busy on this Mars IMAX film... should be out early next year.

06-27-2005, 07:07 AM
Yep it's me! How is life at Pixar? I'm currently very busy on this Mars IMAX film... should be out early next year.

Cool ! I see you found your "niche" ! :-)

Everything is great at Pixar. Lovin the work ! :)

Great hearing from you !


CGTalk Moderation
06-27-2005, 07:07 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.