Last active
September 12, 2023 07:37
-
-
Save VRlabBuaa/46cb34f1885aebdfaf8f5efd622616c7 to your computer and use it in GitHub Desktop.
Extract a robust rotation matrix from an arbitray 3x3 matrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void extractRotation(const Matrix3d &A, Quaterniond &q, | |
const unsigned int maxIter) | |
{ | |
for (unsigned int iter = 0; iter < maxIter; iter++) | |
{ | |
Matrix3d R = q.matrix(); | |
Vector3d omega = (R.col(0).cross(A.col(0)) + R.col | |
(1).cross(A.col(1)) + R.col(2).cross(A.col(2)) | |
) * (1.0 / fabs(R.col(0).dot(A.col(0)) + R.col | |
(1).dot(A.col(1)) + R.col(2).dot(A.col(2))) + | |
1.0e-9); | |
double w = omega.norm(); | |
if (w < 1.0e-9) | |
break; | |
q = Quaterniond(AngleAxisd(w, (1.0 / w) * omega)) * | |
q; | |
q.normalize(); | |
} | |
} |
I think that the epsilon value should be inside 1/(x+epsilon):
(1.0 / (fabs(R.col(0).dot(A.col(0)) +
R.col(1).dot(A.col(1)) +
R.col(2).dot(A.col(2))) +
1.0e-9));
Certainly seems like it, in order to avoid div0. The original paper has it outside the divide as well in the code, but it is right in the text.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the paper's code of A Robust Method to Extract the Rotational Part of Deformations by Muller etc.