RoboidControl for Arduino
|
A 2-dimensional vector. More...
#include <Vector2.h>
Public Member Functions | |
Vector2 () | |
Create a new 2-dimensinal zero vector. | |
Vector2 (float x, float y) | |
Create a new 2-dimensional vector. | |
Vector2 (Vec2 v) | |
Create a vector from C-style Vec2. | |
~Vector2 () | |
float | magnitude () const |
The length of this vector. | |
float | sqrMagnitude () const |
The squared length of this vector. | |
Vector2 | normalized () const |
Convert the vector to a length of a. | |
Vector2 | operator- () |
Negate the vector. | |
Vector2 | operator- (const Vector2 &vector) const |
Subtract a vector from this vector. | |
Vector2 | operator+ (const Vector2 &vector2) const |
Add another vector to this vector. | |
Vector2 | operator* (float factor) const |
Scale a vector uniformly up. | |
Vector2 | operator/ (const float &factor) |
Scale a vector uniformy down. | |
bool | operator== (const Vector2 &vector) |
Check is this vector is equal to the given vector. | |
Static Public Member Functions | |
static float | Magnitude (const Vector2 &vector) |
The length of a vector. | |
static float | SqrMagnitude (const Vector2 &vector) |
The squared length of a vector. | |
static Vector2 | Normalize (Vector2 vector) |
Connvert a vector to a length of 1. | |
static Vector2 | Scale (const Vector2 &vector1, const Vector2 &vector2) |
Scale a vector using another vector. | |
static float | Dot (const Vector2 &vector1, const Vector2 &vector2) |
The dot product of two vectors. | |
static float | Distance (const Vector2 &vector1, const Vector2 &vector2) |
The distance between two vectors. | |
static float | Angle (Vector2 vector1, Vector2 vector2) |
Calculate the angle between two vectors. | |
static float | SignedAngle (Vector2 from, Vector2 to) |
Calculate the angle between two vectors rotation around an axis. | |
static Vector2 | Rotate (Vector2 v, float angle) |
Rotate the vector. | |
static Vector2 | Lerp (Vector2 from, Vector2 to, float f) |
Lerp between two vectors. | |
static float | ToFactor (Vector2 a, Vector2 b) |
Public Attributes | |
float | x |
The right axis of the vector. | |
float | y |
The upward/forward axis of the vector. | |
Static Public Attributes | |
static const Vector2 | zero = Vector2(0, 0) |
A vector with zero for all axis. | |
static const Vector2 | one = Vector2(1, 1) |
A vector with values (1, 1) | |
static const Vector2 | right = Vector2(1, 0) |
A vector with values (1, 0) | |
static const Vector2 | left = Vector2(-1, 0) |
A vector3 with values (-1, 0) | |
static const Vector2 | up = Vector2(0, 1) |
A vector with values (0, 1) | |
static const Vector2 | down = Vector2(0, -1) |
A vector with values (0, -1) | |
static const Vector2 | forward = Vector2(0, 1) |
A vector with values (0, 1) | |
static const Vector2 | back = Vector2(0, -1) |
A vector with values (0, -1) | |
A 2-dimensional vector.
This uses the right-handed coordinate system.
Vector2::Vector2 | ( | ) |
Create a new 2-dimensinal zero vector.
Vector2::Vector2 | ( | float | x, |
float | y | ||
) |
Create a new 2-dimensional vector.
x | x axis value |
y | y axis value |
Vector2::~Vector2 | ( | ) |
|
static |
The length of a vector.
vector | The vector for which you need the length |
float Vector2::magnitude | ( | ) | const |
The length of this vector.
|
static |
The squared length of a vector.
vector | The vector for which you need the squared length |
The squared length is computationally simpler than the real length. Think of Pythagoras A^2 + B^2 = C^2. This leaves out the calculation of the squared root of C.
float Vector2::sqrMagnitude | ( | ) | const |
The squared length of this vector.
The squared length is computationally simpler than the real length. Think of Pythagoras A^2 + B^2 = C^2. This leaves out the calculation of the squared root of C.
Connvert a vector to a length of 1.
vector | The vector to convert |
Vector2 Vector2::normalized | ( | ) | const |
Convert the vector to a length of a.
Vector2 Vector2::operator- | ( | ) |
Negate the vector.
This will result in a vector pointing in the opposite direction
Subtract a vector from this vector.
vector | The vector to subtract from this vector |
Add another vector to this vector.
vector2 | The vector to add |
Scale a vector using another vector.
vector1 | The vector to scale |
vector2 | A vector with scaling factors |
Each component of the vector v1 will be multiplied with the component from the scaling vector v2.
Vector2 Vector2::operator* | ( | float | factor | ) | const |
Scale a vector uniformly up.
factor | The scaling factor |
Each component of the vector will be multipled with the same factor.
Vector2 Vector2::operator/ | ( | const float & | factor | ) |
Scale a vector uniformy down.
factor | The scaling factor |
Each componet of the vector will be divided by the same factor.
The dot product of two vectors.
vector1 | The first vector |
vector2 | The second vector |
bool Vector2::operator== | ( | const Vector2 & | vector | ) |
Check is this vector is equal to the given vector.
vector | The vector to check against |
Note this uses float comparison to check equality which may have strange effects. Equality on float should be avoided.
The distance between two vectors.
vector1 | The first vector |
vector2 | The second vectors |
Calculate the angle between two vectors.
vector1 | The first vector |
vector2 | The second vector |
This reterns an unsigned angle which is the shortest distance between the two vectors. Use Vector3::SignedAngle if a signed angle is needed.
Calculate the angle between two vectors rotation around an axis.
from | The starting vector |
to | The ending vector |
axis | The axis to rotate around |
Rotate the vector.
v | The vector to rotate |
angle | Angle in radias to rotate |
Lerp between two vectors.
from | The from vector |
to | The to vector |
f | The interpolation distance (0..1) |
The factor f is unclamped. Value 0 matches the from vector, Value 1 matches the to vector Value -1 is from vector minus the difference between from and to etc.
|
inherited |
The right axis of the vector.
|
inherited |
The upward/forward axis of the vector.