RoboidControl for Arduino
|
A 3-dimensional vector. More...
#include <Vector3.h>
Public Member Functions | |
Vector3 () | |
Create a new 3-dimensinal zero vector. | |
Vector3 (float x, float y, float z) | |
Create a new 3-dimensional vector. | |
Vector3 (Vec3 v) | |
Create a vector from C-style Vec3. | |
~Vector3 () | |
float | magnitude () const |
The length of this vector. | |
float | sqrMagnitude () const |
The squared length of this vector. | |
Vector3 | normalized () const |
Convert the vector to a length of a. | |
Vector3 | operator- () |
Negate the vector. | |
Vector3 | operator- (const Vector3 &vector) const |
Subtract a vector from this vector. | |
Vector3 | operator+ (const Vector3 &vector2) const |
Add another vector to this vector. | |
Vector3 | operator* (float factor) const |
Scale a vector uniformly up. | |
Vector3 | operator/ (const float &factor) |
Scale a vector uniformy down. | |
bool | operator== (const Vector3 &vector) |
Check is this vector is equal to the given vector. | |
Static Public Member Functions | |
static float | Magnitude (const Vector3 &vector) |
The length of a vector. | |
static float | SqrMagnitude (const Vector3 &vector) |
The squared length of a vector. | |
static Vector3 | Normalize (Vector3 vector) |
Connvert a vector to a length of 1. | |
static Vector3 | Scale (const Vector3 &vector1, const Vector3 &vector2) |
Scale a vector using another vector. | |
static float | Dot (const Vector3 &vector1, const Vector3 &vector2) |
The dot product of two vectors. | |
static float | Distance (const Vector3 &vector1, const Vector3 &vector2) |
The distance between two vectors. | |
static Vector3 | Cross (const Vector3 &vector1, const Vector3 &vector2) |
The cross product of two vectors. | |
static Vector3 | Project (Vector3 vector, Vector3 onNormal) |
Project a vector on another vector. | |
static Vector3 | ProjectOnPlane (Vector3 vector, Vector3 planeNormal) |
Projects a vector onto a plane defined by a normal orthogonal to the plane. | |
static float | Angle (Vector3 vector1, Vector3 vector2) |
Calculate the angle between two vectors. | |
static float | SignedAngle (Vector3 from, Vector3 to, Vector3 axis) |
Calculate the angle between two vectors rotation around an axis. | |
static Vector3 | Lerp (Vector3 from, Vector3 to, float f) |
Lerp between two vectors. | |
Public Attributes | |
float | x |
The right axis of the vector. | |
float | y |
The upward axis of the vector. | |
float | z |
The forward axis of the vector. | |
Static Public Attributes | |
static const Vector3 | zero = Vector3(0, 0, 0) |
A vector with zero for all axis. | |
static const Vector3 | one = Vector3(1, 1, 1) |
A vector with one for all axis. | |
static const Vector3 | right = Vector3(1, 0, 0) |
A vector with values (1, 0, 0) | |
static const Vector3 | left = Vector3(-1, 0, 0) |
A vector3 with values (-1, 0, 0) | |
static const Vector3 | up = Vector3(0, 1, 0) |
A vector with values (0, 1, 0) | |
static const Vector3 | down = Vector3(0, -1, 0) |
A vector with values (0, -1, 0) | |
static const Vector3 | forward = Vector3(0, 0, 1) |
A vector with values (0, 0, 1) | |
static const Vector3 | back = Vector3(0, 0, -1) |
A vector with values (0, 0, -1) | |
A 3-dimensional vector.
This uses the right-handed coordinate system.
Vector3::Vector3 | ( | ) |
Create a new 3-dimensinal zero vector.
Vector3::Vector3 | ( | float | x, |
float | y, | ||
float | z | ||
) |
Create a new 3-dimensional vector.
x | x axis value |
y | y axis value |
z | z axis value |
Vector3::~Vector3 | ( | ) |
|
static |
The length of a vector.
vector | The vector for which you need the length |
float Vector3::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 Vector3::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 |
Vector3 Vector3::normalized | ( | ) | const |
Convert the vector to a length of a.
Vector3 Vector3::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.
Vector3 Vector3::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.
Vector3 Vector3::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 Vector3::operator== | ( | const Vector3 & | 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 |
The cross product of two vectors.
vector1 | The first vector |
vector2 | The second vector |
Project a vector on another vector.
vector | The vector to project |
onNormal | The normal vector to project on |
Projects a vector onto a plane defined by a normal orthogonal to the plane.
vector | The vector to project |
planeNormal | The normal of the plane to project on |
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 |
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 axis of the vector.
|
inherited |
The forward axis of the vector.