Getting Euler rotation (x,y,z) to match orientation of one transform to another. Reply Quote Edit

Started by
2 comments, last by RobTheBloke 11 years, 10 months ago
I am using XNA to build an augmented reality application and I am stuck on something.

Currently my application can detect square markers and obtain the camera transform relative to each found marker. What I want to do is find out the euler rotation matrix I would need to apply to one of the markers in order for it to match the orientation of the other. I want to get the x,y,z rotation.

So far I have tried the following:


if (arCamera.imarker.FindMarker(0) && arCamera.imarker.FindMarker(1))
{
Matrix mt = Matrix.Invert(markerTransforms[0]) * markerTransforms[1];
Vector3 scale;
Vector3 trans;
Quaternion rot;
mt.Decompose(out scale, out rot, out trans);
Vector3 vp= QuaternionToEuler(rot);
spriteBatch.DrawString(garamond14I, vp.X.ToString("0.00"), new Vector2(5, 5), Color.White);
spriteBatch.DrawString(garamond14I, vp.Y.ToString("0.00"), new Vector2(50, 5), Color.White);
spriteBatch.DrawString(garamond14I, vp.Z.ToString("0.00"), new Vector2(95, 5), Color.White);

}



I got the QuaternionToEuler code from: http://forums.create.msdn.com/forums/p/4574/23763.aspx

This gets me the an incorrect result. Here is a screenshot of the running application:

QBUiG.png


The actual rotation should be: x:0 y:0 z:-0.52

I also noticed that the rotation changed for both the y axis and z axis as I moved the camera around.

The two transform matrices I obtain from the marker detector contain the orientation and translation of the camera relative to one of the markers as explained here: http://www.hitl.washington.edu/artoolkit/documentation/tutorialcamera.htm

I have converted them to XNA format and I know them to work correctly as I can draw the corners onto the screen and it matches up with what the camera is seeing.

Essentially I want to get the rotation that will get marker 1 to match the orientation of marker 0, in the above example a rotation around of z axis of -0.52 will achieve this. This is based on marker 0's coordinate system with the axis centered on the middle of the marker as shown below:

PagyU.png
Advertisement
Hi!

Let’s see. We have the camera matrix [formula]M_0[/formula] of marker 0 and matrix [formula]M_1[/formula] of marker 1. We can get from one system to the other with a linear transformation:
[formula]M_1 = X \thinspace M_0[/formula]
Solving for X gives:
[formula]X = M_1 \thinspace M_0^{-1}[/formula].
Seems, you got a different order. Is the order of the matrices correct? (Not sure, which order XNA uses.)

After carrying out this multiplication with the inverse, I’d try to extract the angles like described here.
You don’t necessarily need the decomposition of the matrix [formula]X[/formula]. If the marker matrices are orthogonal, there is no scale. The translation is separated in the last column, thus you’d only need to look at the upper left 3x3 matrix. (Assuming the transformation is affine.)

Hope it helps! (Can’t guarantee anything, since I haven’t tested it…)
Best regards
You will never get the same rotation because you can representation the same rotation in many ways using euler angles and there is only one quaternion for each orientation. You will get a rotation in euler that transform in the specific orientation but it might not be the one you want.

and there is only one quaternion for each orientation.


There are two quats for every orientation - you're forgetting about the negate!

This topic is closed to new replies.

Advertisement