Skip to content
Snippets Groups Projects
Commit 8285b225 authored by Oliver Sander's avatar Oliver Sander Committed by sander@FU-BERLIN.DE
Browse files

make the 'distance' method simpler and faster

[[Imported from SVN: r8366]]
parent 17f93124
No related branches found
No related tags found
No related merge requests found
...@@ -544,22 +544,17 @@ public: ...@@ -544,22 +544,17 @@ public:
} }
static T distance(const Rotation<T,3>& a, const Rotation<T,3>& b) { static T distance(const Rotation<T,3>& a, const Rotation<T,3>& b) {
Quaternion<T> diff = a;
// Distance in the unit quaternions: 2*arccos( ((a^{-1) b)_3 )
// But note that (a^{-1}b)_3 is actually <a,b> (in R^4)
T sp = a.globalCoordinates() * b.globalCoordinates();
diff.invert(); // Scalar product may be larger than 1.0, due to numerical dirt
diff = diff.mult(b); T dist = 2*std::acos( std::min(sp,1.0) );
// Make sure we do the right thing if a and b are not in the same sheet // Make sure we do the right thing if a and b are not in the same sheet
// of the double covering of the unit quaternions over SO(3) // of the double covering of the unit quaternions over SO(3)
T dist = 2*std::acos( std::min(diff[3],1.0) ); return (dist>=M_PI) ? (2*M_PI - dist) : dist;
if (dist>=M_PI)
return 2*M_PI - dist;
// Compute the geodesical distance between a and b on SO(3)
// Due to numerical dirt, diff[3] may be larger than 1.
// In that case, use 1 instead of diff[3].
return 2*std::acos( std::min(diff[3],1.0) );
} }
/** \brief Compute the vector in T_aSO(3) that is mapped by the exponential map /** \brief Compute the vector in T_aSO(3) that is mapped by the exponential map
......
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