# Normal vector to Matrix

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

## Recommended Posts

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]

##### Share on other sites
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 ;))

It's talk only about matrices and vectors ;)

##### Share on other sites
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);

##### Share on other sites
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

##### Share on other sites
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 ??

##### Share on other sites
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.

##### Share on other sites
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

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 11
• 15
• 11
• 12
• ### Forum Statistics

• Total Topics
634152
• Total Posts
3015840
×