Normal vector to Matrix

Started by
6 comments, last by nlo 18 years, 8 months ago
is there any article about this ? i'm not a 3d maths guru, i wanna convert a normal vector to a "rotation matrix", but search arround the internet with no luck, anyone help ? thanks for help. :) [Edited by - nlo on August 4, 2005 2:01:26 AM]
Advertisement
Well not that hard

Let's say you have the vector x,y,z

The matrice would be

X
Y
Z

(If i remember corectly about my maths classes ;))

For more info visit that link http://www.gamedev.net/reference/articles/article1832.asp

It's talk only about matrices and vectors ;)
I just came across this problem and this was my naive solution. It has issues but works for my application. :D

          GLfloat* p = pts;  // p is my normal vector (I want a rotation mtx with p as the z axis)|||       GLfloat x[3], y[3];|||       // p is now the z-axis|||       // find two perpendicular vectors to create my orthonormal basis||||||       if (p[0]>0.5) // if the z-axis has a substantial x component|||       {23-         // find p x j234234         x[0] = - p[2]*1;234         x[1] = 0;234         x[2] = p[0]*1;|||       }|||       else|||       {23-         x[0] = 0;234         x[1] = p[2]*1;234         x[2] = - p[1]*1;|||       }||||||       y[0] = x[1]*p[2] - x[2]*p[1];|||       y[1] = x[2]*p[0] - x[0]*p[2];          GLfloat mtx[] = { y[0],y[1],y[2],0,---                         x[0],x[1],x[2],0,>>>                         p[0],p[1],p[2],0,>>>                         p[0],p[1],p[2],1 }; //rotation and translation|||       glPushMatrix();||||||       glMultMatrixf(mtx);

you're saying you want to convert a vector to a rotation matrix? just do google on glrotatef this function does the same thing, just impliment the matrix forumla there. to extract the angle paramater it would be of course the magnatude of the vector
thx guys, but i think i did something stupid, i didn't explain my question well, what i mean is, i wanna convert a "direction-vector" to "rotation matrix", is that mean same as RotationYawPitchRoll ??
well what i posted gives a rotation matrix to change the z-axis into the vector you specify. this will make anything pointing in the z-direction now point in the direction of your vector.
These are the rotation matrix

Remember if you matrix is 4x4 your vector need to be 4x1 So if your Vector is 5,6,3 JUst add 0

5
6
3
0

http://www.gamedev.net/reference/articles/1832/image192.gif
thx, Kuladus. :D

This topic is closed to new replies.

Advertisement