RoboidControl
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Friends | List of all members
Passer::LinearAlgebra::Vector2 Struct Reference

A 2=dimensional vector. More...

#include <Vector2.h>

Inheritance diagram for Passer::LinearAlgebra::Vector2:
Vec2

Public Member Functions

 Vector2 ()
 A new 2-dimensional zero vector.
 
 Vector2 (float right, float forward)
 A new 2-dimensional vector.
 
 Vector2 (Vector3 v)
 Convert a Vector3 to a Vector2.
 
 Vector2 (Polar v)
 Convert a Polar vector to a 2-dimensional vector.
 
 ~Vector2 ()
 Vector2 destructor.
 
bool operator== (const Vector2 &v)
 Check if this vector to the given vector.
 
float magnitude () const
 The vector length.
 
float sqrMagnitude () const
 The squared vector length.
 
Vector2 normalized () const
 Convert the vector to a length 1.
 
Vector2 operator- ()
 Negate the vector such that it points in the opposite direction.
 
Vector2 operator- (const Vector2 &v) const
 Subtract a vector from this vector.
 
Vector2 operator-= (const Vector2 &v)
 
Vector2 operator+ (const Vector2 &v) const
 Add a vector to this vector.
 
Vector2 operator+= (const Vector2 &v)
 
Vector2 operator*= (float f)
 
Vector2 operator/= (float f)
 

Static Public Member Functions

static float Magnitude (const Vector2 &v)
 The vector length.
 
static float SqrMagnitude (const Vector2 &v)
 The squared vector length.
 
static Vector2 Normalize (const Vector2 &v)
 Convert the vector to a length of 1.
 
static Vector2 Scale (const Vector2 &v1, const Vector2 &v2)
 Scale the vector using another vector.
 
static float Dot (const Vector2 &v1, const Vector2 &v2)
 The dot product of two vectors.
 
static float Distance (const Vector2 &v1, const Vector2 &v2)
 The distance between two vectors.
 
static float Angle (const Vector2 &v1, const Vector2 &v2)
 The angle between two vectors.
 
static float SignedAngle (const Vector2 &v1, const Vector2 &v2)
 The signed angle between two vectors.
 
static Vector2 Rotate (const Vector2 &v, Passer::LinearAlgebra::Angle a)
 Rotate the vector.
 
static Vector2 Lerp (const Vector2 &v1, const Vector2 &v2, float f)
 Lerp (linear interpolation) between two vectors.
 

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 one for all axis.
 
static const Vector2 forward = Vector2(0, 1)
 A normalized forward-oriented vector.
 
static const Vector2 back = Vector2(0, -1)
 A normalized back-oriented vector.
 
static const Vector2 right = Vector2(1, 0)
 A normalized right-oriented vector.
 
static const Vector2 left = Vector2(-1, 0)
 A normalized left-oriented vector.
 
static const Vector2 up = Vector2(0, 1)
 A normalized up-oriented vector.
 
static const Vector2 down = Vector2(0, -1)
 A normalized down-oriented vector.
 

Friends

struct Vec2
 2-dimensional Vector representation
 
Vector2 operator* (const Vector2 &v, float f)
 Scale the vector uniformly up.
 
Vector2 operator* (float f, const Vector2 &v)
 
Vector2 operator/ (const Vector2 &v, float f)
 Scale the vector uniformly down.
 
Vector2 operator/ (float f, const Vector2 &v)
 

Detailed Description

A 2=dimensional vector.

Remarks
This uses the right=handed carthesian coordinate system.
Note
This implementation intentionally avoids the use of x and y

Constructor & Destructor Documentation

◆ Vector2() [1/4]

Vector2::Vector2 ( )

A new 2-dimensional zero vector.

◆ Vector2() [2/4]

Passer::LinearAlgebra::Vector2::Vector2 ( float  right,
float  forward 
)

A new 2-dimensional vector.

Parameters
rightThe distance in the right direction in meters
forwardThe distance in the forward direction in meters

◆ Vector2() [3/4]

Vector2::Vector2 ( Vector3  v)

Convert a Vector3 to a Vector2.

Parameters
vThe 3D vector
Note
This will project the vector to the horizontal plane

◆ Vector2() [4/4]

Passer::LinearAlgebra::Vector2::Vector2 ( Polar  v)

Convert a Polar vector to a 2-dimensional vector.

Parameters
vThe vector in polar coordinates

◆ ~Vector2()

Vector2::~Vector2 ( )

Vector2 destructor.

Member Function Documentation

◆ operator==()

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

Check if this vector to the given vector.

Parameters
vThe 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 floats should be avoided.

◆ Magnitude()

float Vector2::Magnitude ( const Vector2 v)
static

The vector length.

Parameters
vThe vector for which you need the length
Returns
The vector length

◆ magnitude()

float Vector2::magnitude ( ) const

The vector length.

Returns
The vector length

◆ SqrMagnitude()

float Vector2::SqrMagnitude ( const Vector2 v)
static

The squared vector length.

Parameters
vThe vector for which you need the squared length
Returns
The squared vector length
Remarks
The squared length is computationally simpler than the real length. Think of Pythagoras A^2 + B^2 = C^2. This prevents the calculation of the squared root of C.

◆ sqrMagnitude()

float Vector2::sqrMagnitude ( ) const

The squared vector length.

Returns
The squared vector length
Remarks
The squared length is computationally simpler than the real length. Think of Pythagoras A^2 + B^2 = C^2. This prevents the calculation of the squared root of C.

◆ Normalize()

Vector2 Vector2::Normalize ( const Vector2 v)
static

Convert the vector to a length of 1.

Parameters
vThe vector to convert
Returns
The vector normalized to a length of 1

◆ normalized()

Vector2 Vector2::normalized ( ) const

Convert the vector to a length 1.

Returns
The vector normalized to a length of 1

◆ operator-() [1/2]

Vector2 Vector2::operator- ( )

Negate the vector such that it points in the opposite direction.

Returns
The negated vector

◆ operator-() [2/2]

Vector2 Vector2::operator- ( const Vector2 v) const

Subtract a vector from this vector.

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

◆ operator-=()

Vector2 Vector2::operator-= ( const Vector2 v)

◆ operator+()

Vector2 Vector2::operator+ ( const Vector2 v) const

Add a vector to this vector.

Parameters
vThe vector to add to this vector
Returns
The result of the addition

◆ operator+=()

Vector2 Vector2::operator+= ( const Vector2 v)

◆ Scale()

Vector2 Vector2::Scale ( const Vector2 v1,
const Vector2 v2 
)
static

Scale the vector using another vector.

Parameters
v1The vector to scale
v2A vector with the scaling factors
Returns
The scaled vector
Remarks
Each component of the vector v1 will be multiplied with the matching component from the scaling vector v2.

◆ operator*=()

Vector2 Vector2::operator*= ( float  f)

◆ operator/=()

Vector2 Vector2::operator/= ( float  f)

◆ Dot()

float Vector2::Dot ( const Vector2 v1,
const Vector2 v2 
)
static

The dot product of two vectors.

Parameters
v1The first vector
v2The second vector
Returns
The dot product of the two vectors

◆ Distance()

float Vector2::Distance ( const Vector2 v1,
const Vector2 v2 
)
static

The distance between two vectors.

Parameters
v1The first vector
v2The second vector
Returns
The distance between the two vectors

◆ Angle()

float Vector2::Angle ( const Vector2 v1,
const Vector2 v2 
)
static

The angle between two vectors.

Parameters
v1The first vector
v2The second vector
Returns
The angle between the two vectors
Remarks
This reterns an unsigned angle which is the shortest distance between the two vectors. Use Vector2::SignedAngle if a signed angle is needed.

◆ SignedAngle()

float Vector2::SignedAngle ( const Vector2 v1,
const Vector2 v2 
)
static

The signed angle between two vectors.

Parameters
v1The starting vector
v2The ending vector
Returns
The signed angle between the two vectors

◆ Rotate()

Vector2 Vector2::Rotate ( const Vector2 v,
Passer::LinearAlgebra::Angle  a 
)
static

Rotate the vector.

Parameters
vThe vector to rotate
aThe angle in degrees to rotate
Returns
The rotated vector

◆ Lerp()

Vector2 Vector2::Lerp ( const Vector2 v1,
const Vector2 v2,
float  f 
)
static

Lerp (linear interpolation) between two vectors.

Parameters
v1The starting vector
v2The end vector
fThe interpolation distance
Returns
The lerped vector
Remarks
The factor f is unclamped. Value 0 matches the vector v1, Value 1 matches vector v2. Value -1 is vector v1 minus the difference between v1 and v2 etc.

Friends And Related Symbol Documentation

◆ Vec2

friend struct Vec2
friend

2-dimensional Vector representation

This is a C-style implementation This uses the right-handed coordinate system.

◆ operator* [1/2]

Vector2 operator* ( const Vector2 v,
float  f 
)
friend

Scale the vector uniformly up.

Parameters
fThe scaling factor
Returns
The scaled vector
Remarks
Each component of the vector will be multipled with the same factor f.

◆ operator* [2/2]

Vector2 operator* ( float  f,
const Vector2 v 
)
friend

◆ operator/ [1/2]

Vector2 operator/ ( const Vector2 v,
float  f 
)
friend

Scale the vector uniformly down.

Parameters
fThe scaling factor
Returns
The scaled vector
Remarks
Each componet of the vector will be divided by the same factor.

◆ operator/ [2/2]

Vector2 operator/ ( float  f,
const Vector2 v 
)
friend

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 one for all axis.

◆ forward

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

A normalized forward-oriented vector.

◆ back

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

A normalized back-oriented vector.

◆ right

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

A normalized right-oriented vector.

◆ left

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

A normalized left-oriented vector.

◆ up

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

A normalized up-oriented vector.

Note
This is a convenience function which is equal to Vector2::forward

◆ down

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

A normalized down-oriented vector.

Note
This is a convenience function which is equal to Vector2::down

◆ 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: