title: Trying to find the relative transformation between to two positions - XNA
body: <p>I have written a simple AR program in XNA and I am now trying to find the relative transformation between my 2 markers. </p>
  
  <p>I have located my markers relative to my camera and have extracted out translation and rotation matrixes for the markers.</p>
  
  <p>What I am trying to do is to find out the relative translation to get to marker 2 from marker 1. For instance if marker 1 and marker 2 were lying on the same Z plane the Z translation component would be 0mm.</p>
  
  <p>The image below is the application working for 2 positions on the same plane:</p>
  
  <p><img src="https://i.stack.imgur.com/5trdC.jpg" alt="enter image description here"></p>
  
  <p>I assumed that by simply multiplying the matrix of the 2nd marker by the inverse of the 1st marker I can get the translation. However I am getting completely wrong results. </p>
  
  <p>The code I am running is as follows:</p>
  
  <p>posit.EstimatePose(points, out matrix, out trans);</p>
  
  <pre><code>            float yaw, pitch, roll;
  
              matrix.ExtractYawPitchRoll(out yaw, out pitch, out roll);
  
              Matrix rotation = 
                  Matrix.CreateFromYawPitchRoll(-yaw, -pitch, roll);
  
              Matrix translation = 
                  Matrix.CreateTranslation(new Vector3(trans.X, trans.Y, -trans.Z));
  
              Matrix complete = rotation * translation;
              List&lt;Matrix&gt; all = new List&lt;Matrix&gt;();
              all.Add(rotation);
              all.Add(translation);
              all.Add(complete);
              matrixes.Add(all);
  
          }
  
          Matrix res = Matrix.Invert(matrixes[0][2]) * matrixes[1][2];
          Vector3 scaleR;
          Vector3 translationR;
          Quaternion rotationR;
          res.Decompose(out scaleR, out rotationR, out translationR);
  </code></pre>
  
  <p>The result:</p>
  
  <p>TranslationR : {X:-103.4285 Y:-104.1754 Z:104.9243}</p>
  
  <p>I have overlaid 3D axes onto the image as shown above using XNA so I assume the rotation and translation relative to the camera has been worked out correctly.</p>
  
  <p>It seems like I am doing something wrong along the way to calculate the translation. I would definitely not expect the Z to equal 104mm. I was expecting something along the lines of:</p>
  
  <p>{X:0 Y:150 Z:0}</p>