I have two meshes: mesh A and mesh B.
I'm working with MeshLab and all I need is to align them and then extrapolate a transformation matrix that brings B on A.
When I use the alignment tool, I glue A and I set it as the base mesh. Then I perform the point base glueing on B and optionally I use the process button. At the end of the procedure, I save the MeshLab project.
In order to extrapolate the transformation matrix that brings B on A, I just open the .mlp project file (it's a plain text file actually) and I read the data. Unfortunately, what I get is not what I expect. There are two meshes, of course, A and B. For each of them there is a transformation matrix. I expect that mesh A (the one glued and set as base mesh) has an identity matrix, while mesh B has the transformation matrix needed to bring B on A. Sometimes, the matrix of mesh A is close to identity, but still not the identity one.
Here is an example:
<!DOCTYPE MeshLabDocument>
<MeshLabProject>
<MeshGroup>
<MLMesh label="A" filename="A.stl">
<MLMatrix44>
1 3.61241e-09 1.85292e-11 -5.04461e-08
-3.61241e-09 1 3.45518e-10 1.03514e-07
-1.85292e-11 -3.45518e-10 1 5.35603e-09
0 0 0 1
</MLMatrix44>
</MLMesh>
<MLMesh label="B" filename="B.stl">
<MLMatrix44>
-0.670956 -0.741136 -0.0231387 78.366
0.738444 -0.665039 -0.111463 24.2717
0.0672212 -0.0918734 0.993499 33.6056
0 0 0 1
</MLMatrix44>
</MLMesh>
</MeshGroup>
<RasterGroup/>
</MeshLabProject>
Now, my simple assumption is that for some reason MeshLab can't properly bring B onto A. Instead it brings B very close to A, but it needs to minimally adjust A's position too for a best match.
If so, in order to have the best B to A transformation I want to perform the following:
[B matrix] * INVERTED[A matrix] = [B on A matrix]
Is this correct?
The order matters. Matrix Mb brings mesh B to position p, Matrix Ma brings mesh A to position p. Likewise, Ma_invert brings a mesh from position p to the location of mesh A.
Apply Mb to mesh B, now it reached p:
B_transformed = Mb * B
Bring B_transformed
from position p to the location of mesh A:
B_aligned = Ma_inverse * B_transformed
So the combined operation should look like:
B_aligned = Ma_inverse * Mb * B