I have two meshes that I want to align, I'll call the reference mesh the template mesh and the other is the target mesh. I have 1 point-to-point correspondence between my template and target mesh. I am trying to find the uniform scale and translation to align these 2 meshes. This is what I've been doing :
My optimal transformation matrix M = [M11 0 0 M14; 0 M11 0 M24 ; 0 0 M11 M34; 0 0 0 1 ] , here M11 is my scale and M14, M24, M34 are the translation in x,y and z.
I represent my points from the template mesh as homogeneous coordinates -> A = [xt, yt, zt, 1]
the corresponding points on the target mesh -> B = [xp, yp, zp, 1]
I know that :
xp = M11*xt + M14
yp = M11*xt + M24
zp = M11*xt + M34
This is how I form and solve my least sqauares problem :
findMin((X*T - B)^2)
Where T, X and B are :
B = X * T
[xp [ xt 1 0 0 [M11
yp = yt 0 1 0 * M14
zp zt 0 0 1 M24
1] 1 1 1 1] M34]
This is how I find the least squares fit for T :
(Inverse(X'*X))*X'*B
I am not sure if this is the right way to go about this, particularly
- Is it acceptable to add the row of ones in the last row of matrix X in my least sqaures problem? It has no physical meaning, I just added it to make dimensions match and ensure that the matrix X is invertible.
- With this I get negative scale values, is there a way I can add constraints in the least squares problem to ensure that I get a scale that is always greater than 0? Is this even the right approach to find a scale value?