Jump to content
  • Advertisement
Sign in to follow this  
HalcyonX

Euler angles and matrices

This topic is 4844 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ive been donig some reading on euler angles, and from my current understanding of it, its basically just yaw/pitch/roll, right? So, say im on the OpenGL coordinate system, and am trying to rotate point (0, 0, -1) by 45 degrees around the y axis, and then 45 degrees around the x axis. In other words, 45 degrees yaw, then 45 pitch. This point should then end up at (-0.5, 0.5, -0.5), correct? Everything ive read so far has told me that to combine euler angle rotations such as the one described above, you simply multiply the matrices together in the correct order. But when i tried doing so, the rotations are all rotating around the global axis. So when i tried to perform the rotations above, the first rotation around y yield the correct value (-0.707, 0, -0.707). But when i apply the rotation around the x axis, instead of pitching up, it rotated around the global x axis, resulting in (-0.707, 0.5, -0.5). So what am i doing wrong? What is the correct way to implement roll/pitch/yaw with matrices? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
from my current understanding of it, its basically just yaw/pitch/roll, right?
Yaw/pitch/roll is one of many ways Euler angles can be applied. The fact is, Euler angles are more complicated than they may seem at first.

In the most general sense, an Euler angle sequence is a sequence of rotations about a sequence of axes. In our case the axes are the world x, y, and z axes.

Next you have to decide in what order to perform the rotations. There are 6 non-repeating sequences (xyz, xzy, yzx, yxz, zxy, zyx) and 6 repeating sequences (xyx, xzx, yzy, yxy, zxz, zyz). You can also apply them in pairs of two (xy, xz, yz, yx, zx, zy).

You also have to consider vector convention. Since you're using OpenGL, you're using column vectors, and transformations are applied in right-to-left ('reverse') order. So to apply three rotations in the order xyz, you would write:

glLoadIdentity();
glRotatef(zRot, 0, 0, 1);
glRotatef(yRot, 0, 1, 0);
glRotatef(xRot, 1, 0, 0);

Generally, the rotation that is applied first will appear to occur about the object's corresponding local axis, while the rotation that is applied last will appear to occur about the corresponding world axis. The middle rotation will in general appear to be about an arbitrary axis (neither a world or local axis).

So you have to choose your order based on the desired behavior. For example, in an FPS you often want pitch to occur about the local side axis, and yaw to occur about the world up axis. So you would write:

glLoadIdentity();
glRotatef(yaw, 0, 0, 1);
glRotatef(pitch, 1, 0, 0);

Other than that, I can't tell you specifically where your problem is. I will say that vector length is invariant under rotation, so you should not expect (0, 0, -1) to be rotated to (-.5, .5, -.5) under any circumstances.

Share this post


Link to post
Share on other sites
Quote:
Original post by jyk
You also have to consider vector convention. Since you're using OpenGL, you're using column vectors, and transformations are applied in right-to-left ('reverse') order. So to apply three rotations in the order xyz, you would write:

glLoadIdentity();
glRotatef(zRot, 0, 0, 1);
glRotatef(yRot, 0, 1, 0);
glRotatef(xRot, 1, 0, 0);

Generally, the rotation that is applied first will appear to occur about the object's corresponding local axis, while the rotation that is applied last will appear to occur about the corresponding world axis. The middle rotation will in general appear to be about an arbitrary axis (neither a world or local axis).

That is backwards (or it is ambiguous).
To apply three rotations in the local coordinate system in the order xyz, you would write:

glRotatef(xRot, 1, 0, 0);
glRotatef(yRot, 0, 1, 0);
glRotatef(zRot, 0, 0, 1);

This corresponds to the notation (OpenGL): v' = RXRYRZv.

If you want to rotate locally yaw, then pitch, then roll, you would write:

glRotatef(yaw, ...);
glRotatef(pitch, ...);
glRotatef(roll, ...);

This matches your FPS example, so that's why I added "(or it is ambiguous)"

As a mathmatical expression in OpenGL notation, it is: v' = RyawRpitchRrollv.

HalcyonX, I think your matrices are being multiplied in the wrong order or applied in the wrong order or maybe the multiplication is broken.

Share this post


Link to post
Share on other sites
John, I went over my example carefully and couldn't find the error (or ambiguity) that you mentioned.

To clarify, the example was for a sequence of rotations about the world axes, as specified earlier in the post. For the order of application xyz, you would have Rz(Ry(Rxv)) = (RzRyRx)v, which translates to the OpenGL code snippet that I gave. I did a visual test of this particular sequence, and the behavior appeared to be as I described in my post.

Anyway, it's always possible that I've made an error, but perhaps you could clarify where you think the mistake is.

Share this post


Link to post
Share on other sites
Quote:
Original post by jyk
To clarify, the example was for a sequence of rotations about the world axes, as specified earlier in the post.

I thought you meant world axes, but it wasn't clear to me because he is trying to rotate around local axes and I missed the mention of world axes in your post.

Share this post


Link to post
Share on other sites
mmm i see. That clarified a few things. My original understanding of angles and rotation was off. Thanks guys!

Share this post


Link to post
Share on other sites
Well I do know Euler prooved that any combination of rotations is equivalent to a single rotation about an axis. I don't know how to find the angle-axis from a sequence of euler angles though.

Share this post


Link to post
Share on other sites
hi,

take a look at these pictures (2ab mainly). i think it's part of your problem.

you first rotate around the y-axis which results in an adjustment of x and z. after that the rotation around the x-axis results in an adjustment of y and z. i think you're finished then and the x-axis isn't updated anymore. i think this explains why you're getting these results.

i'm busy with this theory too. in my example a 45 degree rotation about each of the x, y and z axis doesn't result in a (0.5,0.5,0.5) point. that's what i always tought.

i don't know if it's correct (maybe not the last two), if someone can check it.

http://members.home.nl/rmdeboer/rotations.jpg

[Edited by - rm82 on August 16, 2005 10:21:03 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!