Given two matrices mat1
and mat2
, each one representing a set of 3 points in a 3 dimensional space, I want to rotate mat2
so that it matches mat1
using orthogonal procrustes :
mat1 <- t(matrix(c(1.16, 0.21, 0.11, -0.78, -0.02, -0.73, -0.37, -0.18, 0.62), nrow=3))
mat2 <- t(matrix(c(0.40, -0.94, -0.05, -0.91, 0.24, -0.38, 0.51, 0.70, 0.43), nrow=3))
Q <- cds::orthprocr(mat1 , mat2)$Q
mat2_rotated <- mat2 %*% Q
The matrix Q
should then represent the optimal rotation / reflection to apply to mat2
to fit as much as possible mat1
. This also means that the optimal rotation/reflection between mat1
and mat2_rotated
should be the identity matrix. However, this doesn't seem to be the case :
Q_2 <- cds::orthprocr(mat1 , mat2_rotated)$Q
#frobenius norm of the difference between Q_2 and Identity :
sqrt(sum((Q_2 - diag(3))^2)) # returns 2 !!!
Where am I wrong? Also what would be the way (some other implementation maybe?) to obtain Identity as optimal orthogonal matrix when the considered matrices are already fitted?
Note that, in the above example, I remark that mat2_rotated
is invariant regarding Q_2
rotation / reflection :
sqrt(sum((mat2_rotated - (mat2_rotated %*% Q_2))^2)) # returns 1.400699e-15
Aucun commentaire:
Enregistrer un commentaire