Matrix from direction and orientation

Started by
4 comments, last by DangerDave 19 years, 4 months ago
I'm not too good at matrices and I've been pouring over a piece of paper trying to work out how to do this to no avail... Basically I have 2 normalised perpendicular vectors, a direction vector and an orientation vector (pointing "downward"). I need a rotation matrix to rotate a cube so its facing the right direction and is the right way up. I'm pretty sure its simple if you know how, can anyone gimme any hints? Additionally, the vectors are always simply of the form (0,1,0), (1,0,0), (-1,0,0), etc, in case that makes it easier.
Dave.
Advertisement
you cant define an orientation in 3d with just a vector, use either a 3x3 matrix, euler angles or quaternions.

a homogenous transformation matrix will be a 4x4 matrix with the top left 3x3 being the rotation the 4th column being the translation.

there is lots of material out there to detail exactly how to do it.
-jonnii=========jon@voodooextreme.comwww.voodooextreme.com
Moved to "Math and Physics".

The only thing you miss is a "right"-vector. To get it, cross "dir" with "up".

The matrix is
right_x  right_y  right_zup_x     up_y     up_zdir_x    dir_y    dir_z

if you use row-vectors. Transpose it otherwise.

Quote:Original post by jonnii
you cant define an orientation in 3d with just a vector, use either a 3x3 matrix, euler angles or quaternions.

a homogenous transformation matrix will be a 4x4 matrix with the top left 3x3 being the rotation the 4th column being the translation.

there is lots of material out there to detail exactly how to do it.

read the OP. he has more than one vector.

if you have two peripendicular vectors, constructing a matrix out of them is a joke.

do a crossproduct between these two vectors to obtain a third othonormal vector.

these three vectors are the three column vectors of the matrix you want. just place these vectors in the collumns of a matrix, and there you go. you might need to transpose the matrix depending on how the rest of your code is working, just try it.
Ah, cheers guys, exactly what I needed, nice one.
Dave.

This topic is closed to new replies.

Advertisement