Skip to content
Snippets Groups Projects
Commit dbe7ea5c authored by Christian Dreher's avatar Christian Dreher
Browse files

Fix: Orientation now correct if dot product < 0.

parent 335ec150
No related branches found
No related tags found
No related merge requests found
......@@ -46,12 +46,20 @@ namespace armarx::viz
dir = dir.normalized();
Eigen::Vector3f naturalDir = Eigen::Vector3f::UnitY();
Eigen::Vector3f cross = naturalDir.cross(dir);
float angle = std::acos(naturalDir.dot(dir));
float dot = naturalDir.dot(dir);
float angle = std::acos(dot);
if (cross.squaredNorm() < 1.0e-12)
{
// Directions are almost colinear ==> Do no rotation
cross = Eigen::Vector3f::UnitX();
angle = 0.0f;
if (dot < 0)
{
angle = M_PI;
}
else
{
angle = 0.0f;
}
}
Eigen::Vector3f axis = cross.normalized();
Eigen::Quaternionf ori(Eigen::AngleAxisf(angle, axis));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment