PX4 Firmware
PX4 Autopilot Software http://px4.io
vector3.cpp
Go to the documentation of this file.
1 #include "test_macros.hpp"
2 
3 #include <matrix/math.hpp>
4 
5 using namespace matrix;
6 
7 int main()
8 {
9  Vector3f a(1, 0, 0);
10  Vector3f b(0, 1, 0);
11  Vector3f c = a.cross(b);
12  TEST(isEqual(c, Vector3f(0,0,1)));
13  c = a % b;
14  TEST(isEqual(c, Vector3f(0,0,1)));
16  Vector3f e(d);
17  TEST(isEqual(e, d));
18  float data[] = {4, 5, 6};
19  Vector3f f(data);
20  TEST(isEqual(f, Vector3f(4, 5, 6)));
21 
22  TEST(isEqual(a + b, Vector3f(1, 1, 0)));
23  TEST(isEqual(a - b, Vector3f(1, -1, 0)));
24  TEST(isEqualF(a * b, 0.0f));
25  TEST(isEqual(-a, Vector3f(-1, 0, 0)));
26  TEST(isEqual(a.unit(), a));
27  TEST(isEqual(a.unit(), a.normalized()));
28  TEST(isEqual(a*2.0, Vector3f(2, 0, 0)));
29 
30  Vector2f g2(1,3);
31  Vector3f g3(7, 11, 17);
32  g3.xy() = g2;
33  TEST(isEqual(g3, Vector3f(1, 3, 17)));
34 
35  const Vector3f g4(g3);
36  Vector2f g5 = g4.xy();
37  TEST(isEqual(g5,g2));
38  TEST(isEqual(g2,Vector2f(g4.xy())));
39 
40  Vector3f h;
41  TEST(isEqual(h,Vector3f(0,0,0)));
42 
44  j(0) = 1;
45  j(1) = 2;
46  j(2) = 3;
47  j(3) = 4;
48 
49  Vector3f k = j.slice<3,1>(0,0);
50  Vector3f k_test(1,2,3);
51  TEST(isEqual(k,k_test));
52 
53  return 0;
54 }
55 
56 /* vim: set et fenc=utf-8 ff=unix sts=0 sw=4 ts=4 : */
Vector3 cross(const Matrix31 &b) const
Definition: Vector3.hpp:59
int main()
Definition: vector3.cpp:7
const Slice< Type, P, Q, M, N > slice(size_t x0, size_t y0) const
Definition: Matrix.hpp:374
bool isEqual(const Matrix< Type, M, N > &x, const Matrix< Type, M, N > &y, const Type eps=1e-4f)
Definition: Matrix.hpp:571
uint8_t * data
Definition: dataman.cpp:149
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
Definition: integration.cpp:8
Vector2< float > Vector2f
Definition: Vector2.hpp:69
Vector3< float > Vector3f
Definition: Vector3.hpp:136
Vector3 normalized() const
Definition: Vector3.hpp:104
#define TEST(X)
Definition: test_macros.hpp:14
const Slice< Type, 2, 1, 3, 1 > xy() const
Definition: Vector3.hpp:108
bool isEqualF(const Type x, const Type y, const Type eps=1e-4f)
Compare if two floating point numbers are equal.
Vector3 unit() const
Override vector ops so Vector3 type is returned.
Definition: Vector3.hpp:100