Euler angles, direction angles, and 3 axes
I hate to ask this because it should be an easy problem, but it is not. In any of my games, I''ve always hit a barrier (not a real barrier, a mental barrier) where I would like to move an object in a 3D enviroment using the magnitude and the rotation angles about each axis (X, Y, Z). Using two angles is a very simple process, and one even easier. The problem comes when I introduce the third angle. Can anyone explain, in layman''s terms, how to go about finding a vector from the rotation angles about the axes and the vector''s magnitude. I am currently trying to find it using direction angles, but even my Calculus teacher can''t figure it out. Any help would be greatly appreciated.
"Donkey, if it were me, you''d be dead."
I cna ytpe 300 wrods pre mniute.
"Donkey, if it were me, you'd be dead."I cna ytpe 300 wrods pre mniute.
Use 3 matrix :
1 0 0
0 cos a -sin a
0 sin a cos a
cos b 0 -sin b
0 1 0
sin b 0 cos b
1 0 0
0 cos c -sin c
0 sin c cos c
Multiply them to get a final one (care for order, I think it can produces unexpected result), put your x, y, z coordinates in the 4th column and you can push this last matrix as your object matrix.
1 0 0
0 cos a -sin a
0 sin a cos a
cos b 0 -sin b
0 1 0
sin b 0 cos b
1 0 0
0 cos c -sin c
0 sin c cos c
Multiply them to get a final one (care for order, I think it can produces unexpected result), put your x, y, z coordinates in the 4th column and you can push this last matrix as your object matrix.
It is not an easy problem when it comes to dealing with three seperate rotation axis. The order you do your operations must be consistant since the order does effect the final result but the problem does not end there. If you rotate 90 degrees on one axis so it lines up with another axis you are screwed because on the next rotation on the new axis you will get a rotation result you did not want. Its called gimbal lock. Do a search using your favourite search engine to find out more about the effect.
If you want to stick with using euler angles to do rotation about a central point then look into angle axis rotation. There is a controversial but excellent article by Diana Gruber titled "Do We Really Need Quaternions?" written a few years ago that shows how you can use euler angles without getting gimbal lock using the angle axis rotation method. It does work. She got a lot of flak since quaternions were the rage at the time and she denounced the use of them. The article can be found on the GameDev.net site.
If you are going to do smooth animation though, and are interpolating between rotations, I recommend you have a look at quaternions. How they work is much harder to visualize but the math isn''t that hard and they work so nice.
If you want to stick with using euler angles to do rotation about a central point then look into angle axis rotation. There is a controversial but excellent article by Diana Gruber titled "Do We Really Need Quaternions?" written a few years ago that shows how you can use euler angles without getting gimbal lock using the angle axis rotation method. It does work. She got a lot of flak since quaternions were the rage at the time and she denounced the use of them. The article can be found on the GameDev.net site.
If you are going to do smooth animation though, and are interpolating between rotations, I recommend you have a look at quaternions. How they work is much harder to visualize but the math isn''t that hard and they work so nice.
Thanks for the replies. I thought about using quaternions for a while, but they just seemed like too much work. I understand the problem with gimbal lock, but I thought there might be a way around it since I was using all the rotations as if they happened at one time, not three seperate times. I guess I will use the quaternion class from the book "OpenGL Game Programming". Still, does anyone know how to get the direction angles if the angles about the axes are known? I think that might be the way to go, also, because it allows you to use all three rotations at once. No gimbal lock.
"Donkey, if it were me, you''d be dead."
I cna ytpe 300 wrods pre mniute.
"Donkey, if it were me, you''d be dead."
I cna ytpe 300 wrods pre mniute.
"Donkey, if it were me, you'd be dead."I cna ytpe 300 wrods pre mniute.
Hmmm.... I am not sure if this will answer your question but here goes:
For a while I experimented with using polar coordinates to represent the rotation and position of an object in its model space. I used 4 scaler values: 3 angles and a magnitude. With this data you can position an object anywhere in a virtual sphere with a rotation. The 3 angles define the unit vector that the magnitude sits on. I used basic trig calcs to derive the rotation axis from the three angles (using sin, cos). Am I on the right track as to what you want to do?
Using this method works well since no gimbal lock up occurs (like you said) but there was another problem that occured which had to do with converting to a matrix: you needed to do more calculations than converting 3 euler angles to a matrix. So then I started using a unit vector of x,y,z that defined the axis of rotation and an angle that defined the rotation about that axis which also uses 4 values required to represent a rotation but less number of instructions to convert to a matrix. It also simplified my code quite a bit because I could plug those values directly into glRotate. Converting to a rotation matrix is almost as involved as using a quaternion but a little bit shorter. This is the angle axis method that Gruber talks about in her article that you should read if you haven''t. Finding the new rotation axis that is formed between two other rotations makes use of the cross product of the two unit vectors. To find the angle to rotate between the two rotations take the dot product of the two unit vectors. But this simplicity is misleading when you start doing animation.
Interpolating between two rotations proved to be trickier. The first problem had to do with wraping of the angles ie: going from say 15 deg to 350 but taking the short route by passing through zero. If you don''t check then you get very jerky motion when animating. I found an elegant algorithm(from a paper written back in 1972) to solve the problem but code size was starting to increase. The second problem has to do with multiple rotations occuring at the same time but with different angular velocities and trying to do blending of rotation changes at the same time too which resulted in a lot of sleepless nights and getting very confused and frustrated. So I had another look at quaternions and noticed that a lot of the calculations were similar to what I was doing with the angle axis method but the thing that turned me to using quaternions ( and jumping on the quaternion bandwagon) was that interpolation and blending were much smoother, no angle wrapping checks had to be done, and animation blending was relatively simple to implement compared to what I was dealing with before.
I guess in the end I don''t have an easy answers or simple formulas to your question. I can post the code for doing angle axis rotation involving 3 axis that has no gimbal lock but its no shorter than using quaternions when you have to convert to a matrix. If you are only using glRotate then the angle axis method is definately faster and easier to implement. If you are doing quality bone animation with blending and need the matrix instead then using a quaternion to represent the joint rotation has its benifits. But the jury is not out yet on this one. One drawback to using quaternions is implementing rotation limits on a particular axis. But I am working on that. Who knows, maybe I will go back to using angle axis but for now I doubt it.
For a while I experimented with using polar coordinates to represent the rotation and position of an object in its model space. I used 4 scaler values: 3 angles and a magnitude. With this data you can position an object anywhere in a virtual sphere with a rotation. The 3 angles define the unit vector that the magnitude sits on. I used basic trig calcs to derive the rotation axis from the three angles (using sin, cos). Am I on the right track as to what you want to do?
Using this method works well since no gimbal lock up occurs (like you said) but there was another problem that occured which had to do with converting to a matrix: you needed to do more calculations than converting 3 euler angles to a matrix. So then I started using a unit vector of x,y,z that defined the axis of rotation and an angle that defined the rotation about that axis which also uses 4 values required to represent a rotation but less number of instructions to convert to a matrix. It also simplified my code quite a bit because I could plug those values directly into glRotate. Converting to a rotation matrix is almost as involved as using a quaternion but a little bit shorter. This is the angle axis method that Gruber talks about in her article that you should read if you haven''t. Finding the new rotation axis that is formed between two other rotations makes use of the cross product of the two unit vectors. To find the angle to rotate between the two rotations take the dot product of the two unit vectors. But this simplicity is misleading when you start doing animation.
Interpolating between two rotations proved to be trickier. The first problem had to do with wraping of the angles ie: going from say 15 deg to 350 but taking the short route by passing through zero. If you don''t check then you get very jerky motion when animating. I found an elegant algorithm(from a paper written back in 1972) to solve the problem but code size was starting to increase. The second problem has to do with multiple rotations occuring at the same time but with different angular velocities and trying to do blending of rotation changes at the same time too which resulted in a lot of sleepless nights and getting very confused and frustrated. So I had another look at quaternions and noticed that a lot of the calculations were similar to what I was doing with the angle axis method but the thing that turned me to using quaternions ( and jumping on the quaternion bandwagon) was that interpolation and blending were much smoother, no angle wrapping checks had to be done, and animation blending was relatively simple to implement compared to what I was dealing with before.
I guess in the end I don''t have an easy answers or simple formulas to your question. I can post the code for doing angle axis rotation involving 3 axis that has no gimbal lock but its no shorter than using quaternions when you have to convert to a matrix. If you are only using glRotate then the angle axis method is definately faster and easier to implement. If you are doing quality bone animation with blending and need the matrix instead then using a quaternion to represent the joint rotation has its benifits. But the jury is not out yet on this one. One drawback to using quaternions is implementing rotation limits on a particular axis. But I am working on that. Who knows, maybe I will go back to using angle axis but for now I doubt it.
Thanks so much. Yeah, I spent a lot of time thinking instead of coding. I would love to see your code for the angle-axis rotation because I don''t really think I need the matrix, as long as I can find the point at the end of the vector formed by the angles and the magnitude after rotation. The help was greatly appreciated, but it may go on the backburner for a while. I just switched to Linux after playing with it on an old computer and I want to do some 2d SDL games for a while.
"Donkey, if it were me, you''d be dead."
I cna ytpe 300 wrods pre mniute.
"Donkey, if it were me, you''d be dead."
I cna ytpe 300 wrods pre mniute.
"Donkey, if it were me, you'd be dead."I cna ytpe 300 wrods pre mniute.
September 21, 2003 06:28 AM
The easy way to make a matrix from several rotations is to use a library with that function.
I use plib and that seems to have functions to create the matrix from the heading, roll and pitch. I have never used that function anyway.
Note that the usual method for avoiding gimbal lock type of problems is working anyway because only small changes are done at each update.
nfz, the method Diana Gruber is using in the article to get the angle and axis for the rotation is only working in some special cases. There is an easy way to get the equivalent angle-axis from any rotation matrix without using quaternions but it is not the one in the article. In my opinion is it easier to use the angle-axis method instead of a slerp.

Note that the usual method for avoiding gimbal lock type of problems is working anyway because only small changes are done at each update.
nfz, the method Diana Gruber is using in the article to get the angle and axis for the rotation is only working in some special cases. There is an easy way to get the equivalent angle-axis from any rotation matrix without using quaternions but it is not the one in the article. In my opinion is it easier to use the angle-axis method instead of a slerp.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement