# Align 3d object to vector by rotation

1. Jul 14, 2010

### jschieck

i have the normal vector of a polygon face, and an object i wish to align to it by rotating it on XYZ. my up vector is (0,1,0). been trying to figure it out by using CrossProduct but i never get the right results. I already have CrossProduct and Normalize functions so I don't need the math for that.

help?

2. Jul 14, 2010

### quasar987

Basically, the mathematical problem you're asking about is: given two vectors v_1 and w_1 in R³, find a rotation that takes one to the other right?

Here is a way to do this. With a computer it should take only a few minutes.

1) normalize v_1 and complete to an orthonormal basis {v_1,v_2,v_3} (find v_2, v_3 linearly independant and use gram-schmidt process to orthonormalize)

2) normalize w_1 and complete to an orthonormal basis {w_1,w_2,w_3}

3) write down the matrix V whose column are the vectors v_i. Compute the determinant. If it is -1, switch columns 2 and 3.

4) write down the matrix W whose columns are the w_i. Compute the determinant. If it is -1, switch columns 2 and 3.

(These are the matrices that send the standard orthonormal basis e_1,e_2,e_3 to v_1,v_2,v_3 and w_1,w_2,w_3 respectively by a rotation.)

5) Invert the matrix V. Then WV^{-1} is a matrix that send the v_i to w_i by a rotation.