Extracting Xr Yr Zr from a matrix

Started by
7 comments, last by haegarr 18 years, 5 months ago
I'm quite unfamiliar with matrices at the moment, and need help with something. I want to tell if a box is upside down, so I want to find out the Z rotational value, so if it is between a certain value, it has been flipped over. How can I find a single float value for the Zrotation from a matrix? Thanks.
Advertisement
Isolating a specific single value like an angle from a trafo matrix can become quite complex, depending on which transformations are concatenated into the matrix of interest. However, it may be a solution to simply transform a "placeholder" vector, i.e. (0,0,1) resp. (0,0,1,0) as a upright vector, by the matrix. If the result shows a z component below 0, it points downwards, and that is equivalent of a flipped box, I think.

If your matrix only contains rotations, or else rotations and translations, then the solution is simple. Then the x, y, and z column vectors denote the basis of the frame equivalent to the transformation, and the z column vector is useable directly instead of the "placeholder" vector mentioned above. I assume also scaling would make no problems here.

[EDIT: The longer I think about, both ways above are the same, since multiplying the matrix w/ (0,0,1,0) makes nothing than isolating the z column vector ;-) Tststs.]
Ok, thanks.
I think i've got it by using the Y value from the X column.
You need to find the dot product of the y column vector and the Y axis. If the y column is point in generally the same direction as the Y axis its right side up( y.Y > 0 ). If its in the opposite direction it up side down.( y.Y < 0)
Thanks Grain, it's making sense now.
Quote:AnonymousTipster
I think i've got it by using the Y value from the X column.

Well, which component to use depends on how your co-ordinate frames are defined, and also the angle range of interest. I'm a little bit surprised that you want to use the y component of the x column, since i've expected something like the y component of the y column if (0,1,0) points upright) or the z component of the z column (if (0,0,1) points upright). I've understood your original posting as you're interested in a distinction of the inclination angle being either between 0 and 90 degree or else between 90 and 180 degree?

@grain: Computing the dot product w/ the global y axis does a computation
(x y z) dot (0 1 0) = y
so it is absolutely the same as picking the component.
True. But if your parent coordinate space is rotated then that doesn’t work. The general solution I posted always works. Of course this is a basic solution and it will only tell you if the box is closer to upside down or right side up. If you want to classify your boxes orientation more specifically ( ie: "Perfectly right side up" "mostly up side down" " on its side" ect ) you will need to fine the specific angle between the y column and the Y axis which is cos -1 (y.Y) if they are both unit length vectors which they should be in this case, if not you will need to normalize them be for using that angle formula.
Well, it seems to work, when it's upright I get close to 1 and when it's upside down I get close to -1. I think the orientation of my box is probably wrong, so I've got the Z axis pointing up, which would explain why X.y returns a value that you'd expect from Z.y.
@Grain: Right you are. In general a general solution is the best ;-) I've interpreted the term "I want to tell if a box is upside down" of the original posting as "all happens in global space anyway" and wanted to show AnonymousTipster that our solutions are not different under these special consideration, and hence both "make sense".

This topic is closed to new replies.

Advertisement