View Full Version : please help me on this rotation!

huangzl99

09-21-2001, 05:55 PM

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!

ffish

09-21-2001, 07:13 PM

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.

huangzl99

09-21-2001, 08:32 PM

Thanks,buddy!

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

Originally posted by ffish:

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.

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.