RoboidControl
Loading...
Searching...
No Matches
Vector2.h
Go to the documentation of this file.
1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0.If a copy of the MPL was not distributed with this
3// file, You can obtain one at https ://mozilla.org/MPL/2.0/.
4
5#ifndef VECTOR2_H
6#define VECTOR2_H
7
8#include "Angle.h"
9
10extern "C" {
16typedef struct Vec2 {
20 float x;
24 float y;
25
26} Vec2;
27}
28
29namespace Passer {
30namespace LinearAlgebra {
31
32struct Vector3;
33struct Polar;
34
38struct Vector2 : Vec2 {
39 friend struct Vec2;
40
41public:
43 Vector2();
47 Vector2(float right, float forward);
55
57 ~Vector2();
58
60 const static Vector2 zero;
62 const static Vector2 one;
64 const static Vector2 forward;
66 const static Vector2 back;
68 const static Vector2 right;
70 const static Vector2 left;
73 const static Vector2 up;
76 const static Vector2 down;
77
83 bool operator==(const Vector2 &v);
84
88 static float Magnitude(const Vector2 &v);
91 float magnitude() const;
98 static float SqrMagnitude(const Vector2 &v);
104 float sqrMagnitude() const;
105
109 static Vector2 Normalize(const Vector2 &v);
112 Vector2 normalized() const;
113
117
121 Vector2 operator-(const Vector2 &v) const;
122 Vector2 operator-=(const Vector2 &v);
126 Vector2 operator+(const Vector2 &v) const;
127 Vector2 operator+=(const Vector2 &v);
128
135 static Vector2 Scale(const Vector2 &v1, const Vector2 &v2);
141 friend Vector2 operator*(const Vector2 &v, float f);
142 friend Vector2 operator*(float f, const Vector2 &v);
143 Vector2 operator*=(float f);
148 friend Vector2 operator/(const Vector2 &v, float f);
149 friend Vector2 operator/(float f, const Vector2 &v);
150 Vector2 operator/=(float f);
151
156 static float Dot(const Vector2 &v1, const Vector2 &v2);
157
162 static float Distance(const Vector2 &v1, const Vector2 &v2);
163
171 static float Angle(const Vector2 &v1, const Vector2 &v2);
176 static float SignedAngle(const Vector2 &v1, const Vector2 &v2);
177
183
192 static Vector2 Lerp(const Vector2 &v1, const Vector2 &v2, float f);
193};
194
195} // namespace LinearAlgebra
196} // namespace Passer
197using namespace Passer::LinearAlgebra;
198
199#include "Polar.h"
200
201#endif
Definition Angle.h:9
AngleOf< float > Angle
Definition Angle.h:42
Definition AbsoluteEncoder.h:5
A polar vector.
Definition Polar.h:19
A 2=dimensional vector.
Definition Vector2.h:38
static const Vector2 up
A normalized up-oriented vector.
Definition Vector2.h:73
Vector2 operator+(const Vector2 &v) const
Add a vector to this vector.
Definition Vector2.cpp:90
Vector2 normalized() const
Convert the vector to a length 1.
Definition Vector2.cpp:71
friend Vector2 operator*(float f, const Vector2 &v)
Vector2()
A new 2-dimensional zero vector.
Definition Vector2.cpp:16
static Vector2 Normalize(const Vector2 &v)
Convert the vector to a length of 1.
Definition Vector2.cpp:63
static const Vector2 zero
A vector with zero for all axis.
Definition Vector2.h:60
static Vector2 Rotate(const Vector2 &v, Passer::LinearAlgebra::Angle a)
Rotate the vector.
Definition Vector2.cpp:154
static const Vector2 one
A vector with one for all axis.
Definition Vector2.h:62
Vector2 operator*=(float f)
Definition Vector2.cpp:108
static float SignedAngle(const Vector2 &v1, const Vector2 &v2)
The signed angle between two vectors.
Definition Vector2.cpp:136
Vector2 operator-()
Negate the vector such that it points in the opposite direction.
Definition Vector2.cpp:80
static float Dot(const Vector2 &v1, const Vector2 &v2)
The dot product of two vectors.
Definition Vector2.cpp:125
static const Vector2 down
A normalized down-oriented vector.
Definition Vector2.h:76
Vector2 operator/=(float f)
Definition Vector2.cpp:119
static Vector2 Scale(const Vector2 &v1, const Vector2 &v2)
Scale the vector using another vector.
Definition Vector2.cpp:99
Vector2(float right, float forward)
A new 2-dimensional vector.
Vector2 operator+=(const Vector2 &v)
Definition Vector2.cpp:93
Vector2 operator-=(const Vector2 &v)
Definition Vector2.cpp:85
static Vector2 Lerp(const Vector2 &v1, const Vector2 &v2, float f)
Lerp (linear interpolation) between two vectors.
Definition Vector2.cpp:171
static const Vector2 right
A normalized right-oriented vector.
Definition Vector2.h:68
static const Vector2 left
A normalized left-oriented vector.
Definition Vector2.h:70
float magnitude() const
The vector length.
Definition Vector2.cpp:59
friend Vector2 operator*(const Vector2 &v, float f)
Scale the vector uniformly up.
float sqrMagnitude() const
The squared vector length.
Definition Vector2.cpp:61
static float Distance(const Vector2 &v1, const Vector2 &v2)
The distance between two vectors.
Definition Vector2.cpp:129
Vector2(Polar v)
Convert a Polar vector to a 2-dimensional vector.
friend Vector2 operator/(const Vector2 &v, float f)
Scale the vector uniformly down.
friend Vector2 operator/(float f, const Vector2 &v)
~Vector2()
Vector2 destructor.
Definition Vector2.cpp:41
static float Magnitude(const Vector2 &v)
The vector length.
Definition Vector2.cpp:56
bool operator==(const Vector2 &v)
Check if this vector to the given vector.
Definition Vector2.cpp:52
static const Vector2 back
A normalized back-oriented vector.
Definition Vector2.h:66
static const Vector2 forward
A normalized forward-oriented vector.
Definition Vector2.h:64
static float SqrMagnitude(const Vector2 &v)
The squared vector length.
Definition Vector2.cpp:60
A 3-dimensional vector.
Definition Vector3.h:42
2-dimensional Vector representation
Definition Vector2.h:16
float y
The upward/forward axis of the vector.
Definition Vector2.h:24
float x
The right axis of the vector.
Definition Vector2.h:20