mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-19 13:13:34 +08:00
Catch quaternion canonical corner cases (#116)
This commit is contained in:
@@ -367,11 +367,13 @@ public:
|
||||
Quaternion canonical() const
|
||||
{
|
||||
const Quaternion &q = *this;
|
||||
if (q(0) < Type(0)) {
|
||||
return Quaternion(-q(0),-q(1),-q(2),-q(3));
|
||||
} else {
|
||||
return Quaternion(q(0),q(1),q(2),q(3));
|
||||
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
if (fabs(q(i)) > FLT_EPSILON) {
|
||||
return q * Type(matrix::sign(q(i)));
|
||||
}
|
||||
}
|
||||
return q;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -78,4 +78,10 @@ Type wrap_2pi(Type x)
|
||||
return wrap(x, Type(0), Type(M_TWOPI));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int sign(T val)
|
||||
{
|
||||
return (T(FLT_EPSILON) < val) - (val < T(FLT_EPSILON));
|
||||
}
|
||||
|
||||
} // namespace matrix
|
||||
|
||||
Reference in New Issue
Block a user