Get the rotation matrix between two two transformation matrices (XNA)

I have a marker detection system for AR at the moment, it detects markers in the scene and gives a camera conversion matrix for each marker in the scene.

Say I found 2 markers. I am trying to find a rotation matrix that I have to apply to one of the markers in order to make it match the orientation of the other marker.

I decided that it should be the same as calculating the transformation matrix of one marker to another and decomposing the transformation to get the rotation matrix x, y, z euler, but I can not get this to work. I am using C # with XNA.

In code:

Matrix marker1 = markerTransforms[0]; Matrix marker2 = markerTransforms[1]; Matrix relativeTransform = Matrix.Invert(marker1) * marker2; Quaternion rotation; Vector3 scale; Vector3 translation; relativeTransform.Decompose(out scale, out rotation, out translation); Matrix rotationMatrix = Matrix.CreateFromQuaternion(rotation); 

This does not work.

Another question is how to extract the rotation matrix x, y, z of the Euler from the rotation?

EDIT:

I found a function to convert quaternion to eiler, following the x, y, z order here: http://forums.create.msdn.com/forums/p/4574/23763.aspx

Applying this to my code, I got the following results:

enter image description here

Actual rotation should be: x: 0 y: 0 z: -0.52

I also noticed that y and z changed a lot depending on how I positioned the camera.

The two transformation matrices that I get from the marker detector contain the orientation and translation of the camera relative to one of the markers, as described here: http://www.hitl.washington.edu/artoolkit/documentation/tutorialcamera.htm I converted them to XNA format , and I know that they work correctly, because I can draw corners on the screen, and this corresponds to what the camera sees.

+8
math c # matrix-multiplication xna augmented-reality
source share
1 answer

The solution I like best is the use of quaternions. If you have one orientation described by q1 and the other q2 , you can switch from one orientation to another using

q1 = q2 d *

q you are looking for.

q = q1 * (q2) ^ - 1; q = q1 * conj (q2);

You just need to convert from rotation to quaternion and quaternion to rotation .

Just make sure you normalize the quaternions so that the equivalences are true. On the linked pages you have all the necessary formulas, explanations, even code in Java, C ++. Really worth adding to your favorites.

+7
source share

All Articles