RoboidControl for Arduino
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
Vector2 Struct Reference

A 2-dimensional vector. More...

#include <Vector2.h>

Inheritance diagram for Vector2:
Vec2

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)
 

Detailed Description

A 2-dimensional vector.

This uses the right-handed coordinate system.

Constructor & Destructor Documentation

◆ Vector2() [1/3]

Vector2::Vector2 ( )

Create a new 2-dimensinal zero vector.

◆ Vector2() [2/3]

Vector2::Vector2 ( float  x,
float  y 
)

Create a new 2-dimensional vector.

Parameters
xx axis value
yy axis value

◆ Vector2() [3/3]

Vector2::Vector2 ( Vec2  v)

Create a vector from C-style Vec2.

Parameters
vThe C-style Vec

◆ ~Vector2()

Vector2::~Vector2 ( )

Member Function Documentation

◆ Magnitude()

float Vector2::Magnitude ( const Vector2 vector)
static

The length of a vector.

Parameters
vectorThe vector for which you need the length
Returns
The length of the given vector

◆ magnitude()

float Vector2::magnitude ( ) const

The length of this vector.

Returns
The length of this vector

◆ SqrMagnitude()

float Vector2::SqrMagnitude ( const Vector2 vector)
static

The squared length of a vector.

Parameters
vectorThe vector for which you need the squared length
Returns
The squatred 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.

◆ sqrMagnitude()

float Vector2::sqrMagnitude ( ) const

The squared length of this vector.

Returns
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.

◆ Normalize()

Vector2 Vector2::Normalize ( Vector2  vector)
static

Connvert a vector to a length of 1.

Parameters
vectorThe vector to convert
Returns
The vector with length 1

◆ normalized()

Vector2 Vector2::normalized ( ) const

Convert the vector to a length of a.

Returns
The vector with length 1

◆ operator-() [1/2]

Vector2 Vector2::operator- ( )

Negate the vector.

Returns
The negated vector

This will result in a vector pointing in the opposite direction

◆ operator-() [2/2]

Vector2 Vector2::operator- ( const Vector2 vector) const

Subtract a vector from this vector.

Parameters
vectorThe vector to subtract from this vector
Returns
The result of the subtraction

◆ operator+()

Vector2 Vector2::operator+ ( const Vector2 vector2) const

Add another vector to this vector.

Parameters
vector2The vector to add
Returns
The result of adding the vector

◆ Scale()

Vector2 Vector2::Scale ( const Vector2 vector1,
const Vector2 vector2 
)
static

Scale a vector using another vector.

Parameters
vector1The vector to scale
vector2A vector with scaling factors
Returns
The scaled vector

Each component of the vector v1 will be multiplied with the component from the scaling vector v2.

◆ operator*()

Vector2 Vector2::operator* ( float  factor) const

Scale a vector uniformly up.

Parameters
factorThe scaling factor
Returns
The scaled vector

Each component of the vector will be multipled with the same factor.

◆ operator/()

Vector2 Vector2::operator/ ( const float &  factor)

Scale a vector uniformy down.

Parameters
factorThe scaling factor
Returns
The scaled vector

Each componet of the vector will be divided by the same factor.

◆ Dot()

float Vector2::Dot ( const Vector2 vector1,
const Vector2 vector2 
)
static

The dot product of two vectors.

Parameters
vector1The first vector
vector2The second vector
Returns
The dot product of the two vectors

◆ operator==()

bool Vector2::operator== ( const Vector2 vector)

Check is this vector is equal to the given vector.

Parameters
vectorThe vector to check against
Returns
True if it is identical to the given vector

Note this uses float comparison to check equality which may have strange effects. Equality on float should be avoided.

◆ Distance()

float Vector2::Distance ( const Vector2 vector1,
const Vector2 vector2 
)
static

The distance between two vectors.

Parameters
vector1The first vector
vector2The second vectors
Returns
The distance between the two vectors

◆ Angle()

float Vector2::Angle ( Vector2  vector1,
Vector2  vector2 
)
static

Calculate the angle between two vectors.

Parameters
vector1The first vector
vector2The second vector
Returns
The angle

This reterns an unsigned angle which is the shortest distance between the two vectors. Use Vector3::SignedAngle if a signed angle is needed.

◆ SignedAngle()

float Vector2::SignedAngle ( Vector2  from,
Vector2  to 
)
static

Calculate the angle between two vectors rotation around an axis.

Parameters
fromThe starting vector
toThe ending vector
axisThe axis to rotate around
Returns
The signed angle

◆ Rotate()

Vector2 Vector2::Rotate ( Vector2  v,
float  angle 
)
static

Rotate the vector.

Parameters
vThe vector to rotate
angleAngle in radias to rotate
Returns
The rotated vector

◆ Lerp()

Vector2 Vector2::Lerp ( Vector2  from,
Vector2  to,
float  f 
)
static

Lerp between two vectors.

Parameters
fromThe from vector
toThe to vector
fThe interpolation distance (0..1)
Returns
The lerped vector

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.

◆ ToFactor()

float Vector2::ToFactor ( Vector2  a,
Vector2  b 
)
static

Member Data Documentation

◆ zero

const Vector2 Vector2::zero = Vector2(0, 0)
static

A vector with zero for all axis.

◆ one

const Vector2 Vector2::one = Vector2(1, 1)
static

A vector with values (1, 1)

◆ right

const Vector2 Vector2::right = Vector2(1, 0)
static

A vector with values (1, 0)

◆ left

const Vector2 Vector2::left = Vector2(-1, 0)
static

A vector3 with values (-1, 0)

◆ up

const Vector2 Vector2::up = Vector2(0, 1)
static

A vector with values (0, 1)

◆ down

const Vector2 Vector2::down = Vector2(0, -1)
static

A vector with values (0, -1)

◆ forward

const Vector2 Vector2::forward = Vector2(0, 1)
static

A vector with values (0, 1)

◆ back

const Vector2 Vector2::back = Vector2(0, -1)
static

A vector with values (0, -1)

◆ x

float Vec2::x
inherited

The right axis of the vector.

◆ y

float Vec2::y
inherited

The upward/forward axis of the vector.


The documentation for this struct was generated from the following files: