Sign in to follow this  
QuadMV

from matrix to radians

Recommended Posts

QuadMV    168
I have a 4x4 matrix with the orientation and location of an object. It's a ms directx style matrix (I think it's the opposits of opengl if I remember correctly) Anyway, how do I convert my orrientation into radians (or degrees) along any of the 3 axis? For my specific instance I want to determine how far I'm rotated around the Y axis, so I can convert that to a compass heading. Thanks

Share this post


Link to post
Share on other sites
jyk    2094
You may be looking for matrix-to-Euler-angle conversion. There are many ways to do such a conversion, and there are a lot of things to take into account. Once you do get a conversion function working, there are still multiple Euler angle triples that will describe the same rotation. So you either have to tweak your function to observe certain constraints, or be able to work with whatever the function gives you. (I know DirectX has an Euler-to-matrix function, but I don't know if it has a matrix-to-Euler function...)

However, when you say 'compass heading', that suggests to me that there are some constraints on your rotations - for example, as with a character or vehicle. For such a case simpler solutions exist. For example, for an object that will remain more or less upright, the 'yaw' angle can be found using atan2() with the appropriate matrix elements as arguments.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Quote:
Original post by QuadMV
For my specific instance I want to determine how far I'm rotated around the Y axis, so I can convert that to a compass heading.

If you want the compass heading of the transformed objects y-axis, as projected onto the xy-plane, you could do something like angle=atan2(t(1,2),t(2,2)), where t(i,j) is the transformation matrix element at row i and column j.

Share this post


Link to post
Share on other sites
QuadMV    168
Great, atan2 is what I needed, but now I need help tweaking it.

It's working if my object remains level, but if my object rotates vertically, slightly above the horrizon, it flips 180. I understand the flip, but not above the horrizon, it's off by 90 degrees (or so) for me. I don't want it to flip before I'm either orriented straight up or straight down.

For what it's worth, I'm initially set to the identity matrix, so when I'm looking up it's just beyond that setting.

Thanks for all the help

Share this post


Link to post
Share on other sites
QuadMV    168
Actually, let me pose another question,

I found burried in my math libs a function to get Euler but I never really understood how it works.

It seems to flip flop every 90 degrees, so if I try and rotate around the y axis say, it seems to flip as I cross the X or Z axis. I kind of understand what it's doing, but I don't know the math to compinsate so I get an ever incrementing value from 0-360 (or 0-3.14 (that's rads right?)) without flip flop? I'm trying to display my heading or compass reading.

Thanks

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Sorry, I see now that I misread you post. You say you rotate the object around the y-axis, while my answer assumed the z-axis. Just change "2" to "3" in the above solution and I expect it should work alright.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
can you explain?

the Y axis would be up down, x = side to side, z = in out, therefore the terrain would be along the x,z and the rotation would be along the Y, right? I know this to be true, because I can navigate correctly in 3D space with yaw, pitch, roll as described above.

That being said, I wasn't using 21,22. I thought that was just an example, but I went back and tried it and it worked but in the wrong way. If I rotate the object around the X axis, I correctly get back the angle I want, but I don't want it when I'm rotating around the X, I want it around the Y. What's confusing is that 2a is the y axis. Anyway, I tried 11,12 and 31,32 but neither work the way 21,22 is.

I'm pretty certain I'm doing something wrong, but the math is my Achilles heel.

Also, as I mentioned, I have the GetEular function, but I'm not sure how to apply it witht he values it's returning?

Share this post


Link to post
Share on other sites
QuadMV    168
that last post was me, I didn't realize I wasn't logged in.

Let me add something that maybe will clarify some of my problem:

I'm calling GetEular (from this paper: http://skal.planet-d.net/demo/matrixfaq.htm#Q37 )

When I start with my object set to the identity matrix, and I just rotate around the Y axis only, here is what I get when facing:

north 0,0,0
north (a little to the east) 0,6,0
north (a little to the west) 0,0,0

east 0,4.7 (give or take), 0

south (a little to the east) 0,6,0
south (a little to the west) 0,0,0

west 0,1.5 (give or take), 0

*************************************************************
Notice, with rotating toward the east, it's always between
4-6
*************************************************************

*************************************************************
Notice, with rotating toward the west, it's always between
0-1.5
*************************************************************

what is going on, and how do I get it to show 0-360 (or 0-3.14)

It seems like this should be trivial, I'm I doing something major wrong?

Thanks

Quad

Share this post


Link to post
Share on other sites
QuadMV    168
I got it working thanks to DrakeX, see his reply in

http://www.gamedev.net/community/forums/topic.asp?topic_id=333390

If you are interested.

this was a similar thread I posted in the DirectX forum instead of the math forum.

Thanks to all for helping, and I'd still be interested in understanding what I might have been doing wroing with what had been suggested.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this