Skip to content
Open
22 changes: 19 additions & 3 deletions src/RotationSpline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
*/
#include "gz/math/Quaternion.hh"
#include "gz/math/RotationSpline.hh"
#include "cmath"
Comment thread
sdhar04 marked this conversation as resolved.
Outdated

using namespace gz;
using namespace math;

using namespace std;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this

/// \internal
/// \brief Private data for RotationSpline
class RotationSpline::Implementation
Expand Down Expand Up @@ -88,11 +90,25 @@ Quaterniond RotationSpline::Interpolate(const unsigned int _fromIndex,
// Use squad using tangents we've already set up
Quaterniond &p = this->dataPtr->points[_fromIndex];
Quaterniond &q = this->dataPtr->points[_fromIndex+1];
Quaterniond &a = this->dataPtr->tangents[_fromIndex];
Quaterniond &b = this->dataPtr->tangents[_fromIndex+1];

Vector3d peu(p.Euler());
Vector3d qeu(q.Euler());

double diffX = abs(peu.X()-qeu.X());
double diffY = abs(peu.Y()-qeu.Y());
double diffZ = abs(peu.Z()-qeu.Z());

// NB interpolate to nearest rotation
return Quaterniond::Squad(_t, p, a, b, q, _useShortestPath);
if ((diffX < 0.16) || (diffY < 0.16) || (diffZ < 0.16))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparing euler angles like this doesn't seem like a safe thing to do. I would suggest calculating the auto diffQ = p.Inverse()*q and then doing const double diff = 2*acos(diffQ.W())) and check the threshold against that.

{
return Quaterniond::Slerp(_t, p, q, _useShortestPath);
}
else
{
Quaterniond &a = this->dataPtr->tangents[_fromIndex];
Quaterniond &b = this->dataPtr->tangents[_fromIndex+1];
return Quaterniond::Squad(_t, p, a, b, q, _useShortestPath);
}
}

/////////////////////////////////////////////////
Expand Down