mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-17 22:53:33 +08:00
Quaternion/Vector: Small refactor for review: put more comments, switched type conversions, took out default destination vector because confusing
This commit is contained in:
@@ -189,18 +189,19 @@ public:
|
||||
/**
|
||||
* Quaternion from two vectors
|
||||
* Generates shortest rotation from source to destination vector
|
||||
* Default destination if not specified is [0,0,1]
|
||||
*
|
||||
* @param dst destination vector (no need to normalize)
|
||||
* @param src source vector (no need to normalize)
|
||||
* @param eps epsilon threshold which decides if a value is considered zero
|
||||
*/
|
||||
Quaternion(const Vector3<Type> &src, const Vector<Type, 3> dst = Vector3<Type>(0, 0, 1), const Type eps = 1e-5f) :
|
||||
Quaternion(const Vector3<Type> &src, const Vector3<Type> &dst, const Type eps = Type(1e-5)) :
|
||||
Vector<Type, 4>()
|
||||
{
|
||||
Quaternion &q = *this;
|
||||
Vector3<Type> cr = src.cross(dst);
|
||||
float dt = src.dot(dst);
|
||||
/* If the two vectors are parallel, cross product is zero
|
||||
* If they point opposite, the dot product is negative */
|
||||
if (cr.norm() < eps && dt < 0) {
|
||||
cr = src.abs();
|
||||
if (cr(0) < cr(1)) {
|
||||
@@ -219,6 +220,7 @@ public:
|
||||
q(0) = Type(0);
|
||||
cr = src.cross(cr);
|
||||
} else {
|
||||
/* Half-Way Quaternion Solution */
|
||||
q(0) = src.dot(dst) + sqrt(src.norm_squared() * dst.norm_squared());
|
||||
}
|
||||
q(1) = cr(0);
|
||||
|
||||
+2
-2
@@ -73,7 +73,7 @@ public:
|
||||
|
||||
Type norm_squared() const {
|
||||
const Vector &a(*this);
|
||||
return Type(a.dot(a));
|
||||
return a.dot(a);
|
||||
}
|
||||
|
||||
inline Type length() const {
|
||||
@@ -88,7 +88,7 @@ public:
|
||||
return (*this) / norm();
|
||||
}
|
||||
|
||||
Vector unit_or_zero(const Type eps = 1e-5f) {
|
||||
Vector unit_or_zero(const Type eps = Type(1e-5)) {
|
||||
const Type n = norm();
|
||||
if (n > eps) {
|
||||
return (*this) / n;
|
||||
|
||||
Reference in New Issue
Block a user