Resolving rotation about an arbitary axis into rotation about X, Y and Z axis
I am currently trying to implement a virtual arcball in OpenGL utilizing GLUT library. As of now I am calculating the axis of rotation and angle of rotation by doing standard arcball computation on old and new coordinates of the mo开发者_如何学编程use. But I want to obtain the angle theta1, theta2, theta3 , such that rotation of the object about X axis by theta1 , about Y axis by theta2 and about Z axis by theta3 would yield the same effect as before.
What you want is to go from axis-angle two three Euler angles. Look into wikipedia rotation conversions . There you can go from axis-angle to quarternion and then to euler angles, or alternatively via the full 3x3 rotation matrix.
Look also into what is called the Rodrigues parameters to help in the conversion. To first rotate about X, then Y and then Z you want to do RZ(t3)*RY(t2)*RX(t1)
.
In your case it might be easier to construct the 3x3 rotation matrix and use OpenGL to transform the modelview based on the matrix, instead of the 3 sequential rotations.
What you want is called Euler angles, which are three angles rotating about coordinate axes (in your case XYZ, or maybe ZYX?). Just be sure to keep a look on the correct convention (axis order) to use, meaning the one that fits your needs. If you search for Euler angle computation formulas you will find many of them, but they will all use different conventions (and many people assume that their convention is the standard, so don't make any special mentioning of it, but there is no general standard).
Also keep in mind that Euler angles have many disadvantages, like gimbal lock, ambiguity and the mentioned convention mess. So if you have the opportunity to represent the rotation by an arbitrary axis and an angle (or even better, a quaternion), then you shouldn't mess with Euler angles. But nevertheless, in this document you find the methods for converting Euler angles to matrices for all 12 conventions and back again. The conversion form axis-angle to matrix is quite straight forward.
A better way to do the job is to convert the spatial rotation about an axis passing through origin to unit quartenions. Unit quartenions can easily be converted into euler angles without any ambiguity. More information on conversion can be found here http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles.
Thanks for all the help!
精彩评论