Tavio

09-20-2009, 11:59 AM

Say I have a triangle with normal X. How do I rotate so it has a given normal Y?

View Full Version : How to rotate a surface so it has a given normal?

Tavio

09-20-2009, 11:59 AM

Say I have a triangle with normal X. How do I rotate so it has a given normal Y?

todayman

09-21-2009, 07:46 AM

The rotation from X to Y is the same as the desired rotation of the triangle. X x Y = Z is some vector perpendicular to both of those, around which you want to rotate. Assuming the normals are, in fact, normalized, the magnitude Z is the sine of the angle between them. So, you essentially need to use the following call:

glRotatef(arcsin(Z.mag())*180/pi, Z.x, Z.y, Z.z);

Depending on where/how you choose to implement this transformation, there may be a better way that avoids the arcsin. You could go straight to the transformation matrix.

glRotatef(arcsin(Z.mag())*180/pi, Z.x, Z.y, Z.z);

Depending on where/how you choose to implement this transformation, there may be a better way that avoids the arcsin. You could go straight to the transformation matrix.

DmitryM

09-23-2009, 07:32 PM

http://stackoverflow.com/questions/11718...ctor-to-another (http://stackoverflow.com/questions/1171849/finding-quaternion-representing-the-rotation-from-one-vector-to-another)

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