please help me on this rotation!

I have a triangle P1( 5,6,7) p2(-3,6,8) p3(1,3,7). I need to rotate this triangle, such that the triangle has a nomaln=(2,0,1).

how do I perform this rotation?

Many thanks!

Create two vectors for two of the sides of the triangle and take the cross product:

(p1 - p2) x (p1 - p3) = (3, -4, 24)

This gives the (unnormalised) normal to the triangle. Take the cross product to the normal you want:

axis[3] = (3, -4, 24) x (2, 0, 1) = (-4, 45, 8)/sqrt(2105) (normalised)

which gives a vector orthogonal to both normals (the axis to rotate around). Calculate the following:

angle = arccos( (3, -4, 24).(2, 0, 1)/(sqrt((3, -4, 24).(3, -4, 24)) * sqrt((2, 0, 1).(2, 0, 1))) ) = (approx.) 56.82 degrees

which gives the angle to rotate. Pass this in as glRotatef(angle, axis[0], axis[1], axis[2]) == glRotatef(56.82, -4/sqrt(2105), 45/sqrt(2105), 8/sqrt(2105)). I hope that’s all correct.

Hope that helps.

Thanks,buddy!

but should I move the world coordinate origin to the triangle?

Originally posted by ffish:
[b]Create two vectors for two of the sides of the triangle and take the cross product:

(p1 - p2) x (p1 - p3) = (3, -4, 24)

This gives the (unnormalised) normal to the triangle. Take the cross product to the normal you want:

axis[3] = (3, -4, 24) x (2, 0, 1) = (-4, 45, 8)/sqrt(2105) (normalised)

which gives a vector orthogonal to both normals (the axis to rotate around). Calculate the following:

angle = arccos( (3, -4, 24).(2, 0, 1)/(sqrt((3, -4, 24).(3, -4, 24)) * sqrt((2, 0, 1).(2, 0, 1))) ) = (approx.) 56.82 degrees

which gives the angle to rotate. Pass this in as glRotatef(angle, axis[0], axis[1], axis[2]) == glRotatef(56.82, -4/sqrt(2105), 45/sqrt(2105), 8/sqrt(2105)). I hope that’s all correct.

Hope that helps.[/b]