mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-29 15:03:33 +08:00
Added unit function that returns normalized vector.
This commit is contained in:
+6
-2
@@ -66,8 +66,12 @@ public:
|
|||||||
return Type(sqrt(a.dot(a)));
|
return Type(sqrt(a.dot(a)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector normalize() const {
|
inline void normalize() {
|
||||||
return (*this) / norm();
|
(*this) /= norm();
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector unit() const {
|
||||||
|
return (*this) / norm();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector pow(Type v) const {
|
Vector pow(Type v) const {
|
||||||
|
|||||||
+4
-2
@@ -42,16 +42,18 @@ int main()
|
|||||||
TEST(isEqual(euler_copy, euler_check));
|
TEST(isEqual(euler_copy, euler_check));
|
||||||
|
|
||||||
// quaternion ctor
|
// quaternion ctor
|
||||||
Quatf q(1, 2, 3, 4);
|
Quatf q0(1, 2, 3, 4);
|
||||||
|
Quatf q(q0);
|
||||||
TEST(fabs(q(0) - 1) < eps);
|
TEST(fabs(q(0) - 1) < eps);
|
||||||
TEST(fabs(q(1) - 2) < eps);
|
TEST(fabs(q(1) - 2) < eps);
|
||||||
TEST(fabs(q(2) - 3) < eps);
|
TEST(fabs(q(2) - 3) < eps);
|
||||||
TEST(fabs(q(3) - 4) < eps);
|
TEST(fabs(q(3) - 4) < eps);
|
||||||
|
|
||||||
// quat normalization
|
// quat normalization
|
||||||
q = q.normalize();
|
q.normalize();
|
||||||
TEST(isEqual(q, Quatf(0.18257419f, 0.36514837f,
|
TEST(isEqual(q, Quatf(0.18257419f, 0.36514837f,
|
||||||
0.54772256f, 0.73029674f)));
|
0.54772256f, 0.73029674f)));
|
||||||
|
TEST(isEqual(q0.unit(), q));
|
||||||
|
|
||||||
// quat default ctor
|
// quat default ctor
|
||||||
q = Quatf();
|
q = Quatf();
|
||||||
|
|||||||
Reference in New Issue
Block a user