I'm working with Eigen library and, in particular, 2d isometries to represent the pose of an object in a 2D world.
As you may know, this has three components: x
and y
for the position and an angle theta
for the rotation.
Extracting the position components is straightforward:
Eigen::Isometry2d t;
double x = t.translation().x();
double y = t.translation().y();
For the rotation, one can use a formula like:
double theta = atan2(t(1, 0), t(0, 0));
This is tested and works fine, but it's a bit inconvenient to write it all the times. Therefore my question is if someone knows a nicer way to get theta
by just calling Eigen methods.
You can construct a Rotation2Dd
object from the linear part of the transformation (and if you prefer having a scalar, extract the angle using .angle()
):
double theta = Eigen::Rotation2Dd(t.linear()).angle();