Rotation Matricies / 3 floats

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

Recommended Posts

hi, I'm using a friends camera class in a game, i'm currently making. For a spring dampened bolt it needs a rotation sent in. He uses 3 separate floats for the x y and z rotations whereas in my game i'm using a rotation matrix. Is there a way (either simple or complex) to find out the original separate angles of rotation from the matrix? am i being stupid by not being able to realise how to do it? Thanx Rich

Share on other sites
I would assume that vector is a Quaternion. I'm afraid I've never taken the time to learn them so can't explain them. Basically it is a representation of an axis-angle rotation. Encoded in the vector is the axis of rotation and the angle to rotate by. The manner in which it is encoded makes it easy to concatenate rotations and interpolate between rotations.

Share on other sites
It's not that bad, although I don't recommend it. But then, I don't really like using Euler angles all that much. You might be better off convincing your friend to use matrices...

Assuming you can't, if your order of rotation is z-y-x, then you multiply 3 matrices together Rx*Ry*Rz (assuming that you're using column matrices for vectors). The final rotation matrix R is

| CyCz -CySz Sy |
| SxSyCz+CxSz -SxSySz+CxCz -SxCy |
| -CxSyCz+SxSz CxSySz+SxCz CxCy |

where Sx is the sine of the angle around the x-axis, and Cy is the cosine of the angle around the y-axis, etc.

You know Sy immediately; it's in the upper right. Cy can be found by sqrt(1-Sy^2). We'll assume that it's positive. Plug those into atan2() and you get the angle around y. You can find the rest by dividing out terms. So, for example, Sx = -R[1,2]/Cy, and Cx = -R[2,2]/Cy, and use atan2() again.

The one problem is if Cy is 0. In this case the x and z axes have become aligned. One possibility is to assume that rotation around z is 0, so Sz = 0, Cz = 1, Sx = R[2,1] and Cx = R[1,1].

If you're using row vectors, or if your multiplication order is different, you'll just have to multiply it out and see what you get. There should always be one element that's a single factor, and you just go from there.

Because of the square root, and because your angles are clamped between 0 and 2*pi, and because Euler angles are ill-formed, you won't get always get back the same result as your input. For example, (90,90,90) will produce the same rotation matrix as (0,90,0).

Share on other sites
http://sjbaker.org/steve/omniv/matrices_can_be_your_friends.html

Share on other sites
Oops, guess I didn't read that carefully enough.

Share on other sites
thanx everyone...
jim - i think the order is y-z-x but i'm not certain... i should be able to take it from here, thanx again :)

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 15
• 13
• 9
• 12
• 10
• Forum Statistics

• Total Topics
631442
• Total Posts
3000086
×