mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-15 20:13:35 +08:00
Implemented vector 3 cross product.
This commit is contained in:
+5
-7
@@ -50,14 +50,12 @@ public:
|
||||
v(2) = z;
|
||||
}
|
||||
|
||||
Vector3 cross(const Vector3 & b) {
|
||||
// TODO
|
||||
Vector3 &a(*this);
|
||||
(void)a;
|
||||
Vector3 cross(const Vector3 & b) const {
|
||||
const Vector3 &a(*this);
|
||||
Vector3 c;
|
||||
c(0) = 0;
|
||||
c(1) = 0;
|
||||
c(2) = 0;
|
||||
c(0) = a(1)*b(2) - a(2)*b(1);
|
||||
c(1) = -a(0)*b(2) + a(2)*b(0);
|
||||
c(2) = a(0)*b(1) - a(1)*b(0);
|
||||
return c;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -12,6 +12,8 @@ int main()
|
||||
Vector3f a(1, 0, 0);
|
||||
Vector3f b(0, 1, 0);
|
||||
Vector3f c = a.cross(b);
|
||||
c.print();
|
||||
assert (c == Vector3f(0,0,1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user