2

I have a conversion from a rotation vector to a rotation matrix by:

Eigen::Vector3d rotVec(-0.67925191, -1.35850382, -2.03775573);
Eigen::AngleAxisd rotAA(rotVec.norm(), rotVec.normalized());
Eigen::Matrix3d rotationMatrix = rotAA.matrix();

Then I want to do the reverse conversion from matrix to the vector and what I do is:

Eigen::AngleAxisd rotvec2(rotationMatrix);

yet, I have not been able to convert Eigen::AngleAxisd back to Eigen::Vector3d and the AngleAxisd itself seems to only have an angle and axis member function.

Does anyone know how we can do this?

Alejandro
  • 879
  • 11
  • 27

1 Answers1

1

AngleAxis has many more member functions than angle() and axis(). Either fromRotationMatrix(const MatrixBase< Derived > &mat) or AngleAxis(const MatrixBase< Derived > &mat) will do the first step in converting back. See: https://eigen.tuxfamily.org/dox/classEigen_1_1AngleAxis.html

Then use the product angle() * axis() to get back the original vector.

#include <Eigen/Dense>
#include <cstdlib>

int main()
{
    using namespace Eigen;
    using T = double;

    Vector3<T> const rotVec{-0.67925191, -1.35850382, -2.03775573};
    AngleAxis<T> const rotAA{rotVec.norm(), rotVec.normalized()};
    Matrix3<T> const rotMat{rotAA.toRotationMatrix()};

#if 0
    AngleAxis<T> rotAA2{};
    rotAA2.fromRotationMatrix(rotMat);
#else
    AngleAxis<T> const rotAA2{rotMat};
#endif

    Vector3<T> const rotVec2{rotAA2.angle() * rotAA2.axis()};
    bool const is_valid = rotVec.isApprox(rotVec2);
    return is_valid ? EXIT_SUCCESS : EXIT_FAILURE;
}
Matt Eding
  • 917
  • 1
  • 8
  • 15