Skip to content

Commit 3e61783

Browse files
author
Ruben Smits
authored
Merge pull request #199 from maverick-long/fix_rotation_angle_numerical_error
back to use a more numerically stable method to compute the rotation angle
2 parents c42c4dc + 713c39a commit 3e61783

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

orocos_kdl/src/frames.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -413,15 +413,13 @@ double Rotation::GetRotAngle(Vector& axis,double eps) const {
413413
return angle; // return 180 deg rotation
414414
}
415415

416-
// If the matrix is slightly non-orthogonal, `f` may be out of the (-1, +1) range.
417-
// Therefore, clamp it between those values to avoid NaNs.
418416
double f = (data[0] + data[4] + data[8] - 1) / 2;
419-
angle = acos(std::max(-1.0, std::min(1.0, f)));
420417

421418
x = (data[7] - data[5]);
422419
y = (data[2] - data[6]);
423420
z = (data[3] - data[1]);
424421
axis = KDL::Vector(x, y, z);
422+
angle = atan2(axis.Norm()/2,f);
425423
axis.Normalize();
426424
return angle;
427425
}

0 commit comments

Comments
 (0)