diff --git a/gtsam/geometry/Rot3M.cpp b/gtsam/geometry/Rot3M.cpp index 6e258112e..ba5408555 100644 --- a/gtsam/geometry/Rot3M.cpp +++ b/gtsam/geometry/Rot3M.cpp @@ -183,8 +183,11 @@ Rot3 Rot3::operator*(const Rot3& R2) const { /* ************************************************************************* */ Point3 Rot3::rotate(const Point3& p, boost::optional H1, boost::optional H2) const { - if (H1) *H1 = matrix() * skewSymmetric(-p.x(), -p.y(), -p.z()); - if (H2) *H2 = matrix(); + if (H1 || H2) { + const Matrix R(matrix()); + if (H1) *H1 = R * skewSymmetric(-p.x(), -p.y(), -p.z()); + if (H2) *H2 = R; + } return r1_ * p.x() + r2_ * p.y() + r3_ * p.z(); }