PX4 Firmware
PX4 Autopilot Software http://px4.io
Vector2.hpp
Go to the documentation of this file.
1 /**
2  * @file Vector2.hpp
3  *
4  * 2D vector class.
5  *
6  * @author James Goppert <james.goppert@gmail.com>
7  */
8 
9 #pragma once
10 
11 #include "math.hpp"
12 
13 namespace matrix
14 {
15 
16 template <typename Type, size_t M>
17 class Vector;
18 
19 template<typename Type>
20 class Vector2 : public Vector<Type, 2>
21 {
22 public:
23 
26 
27  Vector2() = default;
28 
29  Vector2(const Matrix21 & other) :
30  Vector<Type, 2>(other)
31  {
32  }
33 
34  explicit Vector2(const Type data_[2]) :
35  Vector<Type, 2>(data_)
36  {
37  }
38 
39  Vector2(Type x, Type y)
40  {
41  Vector2 &v(*this);
42  v(0) = x;
43  v(1) = y;
44  }
45 
46  template<size_t P, size_t Q>
47  Vector2(const Slice<Type, 2, 1, P, Q>& slice_in) : Vector<Type, 2>(slice_in)
48  {
49  }
50 
51  explicit Vector2(const Vector3 & other)
52  {
53  Vector2 &v(*this);
54  v(0) = other(0);
55  v(1) = other(1);
56  }
57 
58  Type cross(const Matrix21 & b) const {
59  const Vector2 &a(*this);
60  return a(0)*b(1, 0) - a(1)*b(0, 0);
61  }
62 
63  Type operator%(const Matrix21 & b) const {
64  return (*this).cross(b);
65  }
66 
67 };
68 
70 
71 } // namespace matrix
72 
73 /* vim: set et fenc=utf-8 ff=unix sts=0 sw=4 ts=4 : */
Vector< Type, 3 > Vector3
Definition: Vector2.hpp:25
Vector2(const Slice< Type, 2, 1, P, Q > &slice_in)
Definition: Vector2.hpp:47
Type cross(const Matrix21 &b) const
Definition: Vector2.hpp:58
Matrix< Type, 2, 1 > Matrix21
Definition: Vector2.hpp:24
Vector2(const Type data_[2])
Definition: Vector2.hpp:34
Vector2< float > Vector2f
Definition: Vector2.hpp:69
Vector2()=default
Vector2(const Matrix21 &other)
Definition: Vector2.hpp:29
Vector2(const Vector3 &other)
Definition: Vector2.hpp:51
Vector2(Type x, Type y)
Definition: Vector2.hpp:39
Type operator%(const Matrix21 &b) const
Definition: Vector2.hpp:63