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

A 3-dimensional vector. More...

#include <Vector3.h>

Inheritance diagram for Passer::LinearAlgebra::Vector3:
Passer::LinearAlgebra::Vec3

Public Member Functions

 Vector3 ()
 A new 3-dimensional zero vector.
 
 Vector3 (float right, float up, float forward)
 A new 3-dimensional vector.
 
 Vector3 (Vector2 v)
 Convert a 2-dimenstional vector to a 3-dimensional vector.
 
 Vector3 (Spherical v)
 Convert vector in spherical coordinates to 3d carthesian coordinates.
 
 ~Vector3 ()
 Vector3 destructor.
 
float Forward () const
 
float Up () const
 
float Right () const
 
bool operator== (const Vector3 &v)
 Check if this vector to the given vector.
 
float magnitude () const
 The vector length.
 
float sqrMagnitude () const
 The squared vector length.
 
Vector3 normalized () const
 Convert the vector to a length of 1.
 
Vector3 operator- () const
 Negate te vector such that it points in the opposite direction.
 
Vector3 operator- (const Vector3 &v) const
 Subtract a vector from this vector.
 
Vector3 operator-= (const Vector3 &v)
 
Vector3 operator+ (const Vector3 &v) const
 Add a vector to this vector.
 
Vector3 operator+= (const Vector3 &v)
 
Vector3 operator*= (float f)
 
Vector3 operator/= (float f)
 

Static Public Member Functions

static float Magnitude (const Vector3 &v)
 The vector length.
 
static float SqrMagnitude (const Vector3 &v)
 The squared vector length.
 
static Vector3 Normalize (const Vector3 &v)
 Convert the vector to a length of 1.
 
static Vector3 Scale (const Vector3 &v1, const Vector3 &v2)
 Scale the vector using another vector.
 
static float Distance (const Vector3 &v1, const Vector3 &v2)
 The distance between two vectors.
 
static float Dot (const Vector3 &v1, const Vector3 &v2)
 The dot product of two vectors.
 
static Vector3 Cross (const Vector3 &v1, const Vector3 &v2)
 The cross product of two vectors.
 
static Vector3 Project (const Vector3 &v, const Vector3 &n)
 Project the vector on another vector.
 
static Vector3 ProjectOnPlane (const Vector3 &v, const Vector3 &n)
 Project the vector on a plane defined by a normal orthogonal to the plane.
 
static float Angle (const Vector3 &v1, const Vector3 &v2)
 The angle between two vectors.
 
static float SignedAngle (const Vector3 &v1, const Vector3 &v2, const Vector3 &axis)
 The signed angle between two vectors.
 
static Vector3 Lerp (const Vector3 &v1, const Vector3 &v2, float f)
 Lerp (linear interpolation) between two vectors.
 

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

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

Friends

struct Vec3
 3-dimensional Vector representation
 
Vector3 operator* (const Vector3 &v, float f)
 Scale the vector uniformly up.
 
Vector3 operator* (float f, const Vector3 &v)
 
Vector3 operator/ (const Vector3 &v, float f)
 Scale the vector uniformly down.
 
Vector3 operator/ (float f, const Vector3 &v)
 

Detailed Description

A 3-dimensional vector.

Remarks
This uses a right-handed carthesian coordinate system.
Note
This implementation intentionally avoids the use of x, y and z values.

Constructor & Destructor Documentation

◆ Vector3() [1/4]

Vector3::Vector3 ( )

A new 3-dimensional zero vector.

◆ Vector3() [2/4]

Vector3::Vector3 ( float  right,
float  up,
float  forward 
)

A new 3-dimensional vector.

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

◆ Vector3() [3/4]

Vector3::Vector3 ( Vector2  v)

Convert a 2-dimenstional vector to a 3-dimensional vector.

Parameters
vThe vector to convert

◆ Vector3() [4/4]

Passer::LinearAlgebra::Vector3::Vector3 ( Spherical  v)

Convert vector in spherical coordinates to 3d carthesian coordinates.

Parameters
vThe vector to convert

◆ ~Vector3()

Vector3::~Vector3 ( )

Vector3 destructor.

Member Function Documentation

◆ Forward()

float Passer::LinearAlgebra::Vector3::Forward ( ) const
inline

◆ Up()

float Passer::LinearAlgebra::Vector3::Up ( ) const
inline

◆ Right()

float Passer::LinearAlgebra::Vector3::Right ( ) const
inline

◆ operator==()

bool Vector3::operator== ( const Vector3 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 Vector3::Magnitude ( const Vector3 v)
static

The vector length.

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

◆ magnitude()

float Vector3::magnitude ( ) const

The vector length.

Returns
The vector length

◆ SqrMagnitude()

float Vector3::SqrMagnitude ( const Vector3 v)
static

The squared vector length.

Parameters
vThe vector for which you need the 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 leaves out the calculation of the squared root of C.

◆ sqrMagnitude()

float Vector3::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 leaves out the calculation of the squared root of C.

◆ Normalize()

Vector3 Vector3::Normalize ( const Vector3 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()

Vector3 Vector3::normalized ( ) const

Convert the vector to a length of 1.

Returns
The vector normalized to a length of 1

◆ operator-() [1/2]

Vector3 Vector3::operator- ( ) const

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

Returns
The negated vector

◆ operator-() [2/2]

Vector3 Vector3::operator- ( const Vector3 v) const

Subtract a vector from this vector.

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

◆ operator-=()

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

◆ operator+()

Vector3 Vector3::operator+ ( const Vector3 v) const

Add a vector to this vector.

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

◆ operator+=()

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

◆ Scale()

Vector3 Vector3::Scale ( const Vector3 v1,
const Vector3 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*=()

Vector3 Vector3::operator*= ( float  f)

◆ operator/=()

Vector3 Vector3::operator/= ( float  f)

◆ Distance()

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

The distance between two vectors.

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

◆ Dot()

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

The dot product of two vectors.

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

◆ Cross()

Vector3 Vector3::Cross ( const Vector3 v1,
const Vector3 v2 
)
static

The cross product of two vectors.

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

◆ Project()

Vector3 Vector3::Project ( const Vector3 v,
const Vector3 n 
)
static

Project the vector on another vector.

Parameters
vThe vector to project
nThe normal vecto to project on
Returns
The projected vector

◆ ProjectOnPlane()

Vector3 Vector3::ProjectOnPlane ( const Vector3 v,
const Vector3 n 
)
static

Project the vector on a plane defined by a normal orthogonal to the plane.

Parameters
vThe vector to project
nThe normal of the plane to project on
Returns
Teh projected vector

◆ Angle()

float Vector3::Angle ( const Vector3 v1,
const Vector3 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 Vector3::SignedAngle if a signed angle is needed.

◆ SignedAngle()

float Vector3::SignedAngle ( const Vector3 v1,
const Vector3 v2,
const Vector3 axis 
)
static

The signed angle between two vectors.

Parameters
v1The starting vector
v2The ending vector
axisThe axis to rotate around
Returns
The signed angle between the two vectors

◆ Lerp()

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

Lerp (linear interpolation) between two vectors.

Parameters
v1The starting vector
v2The ending 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

◆ Vec3

friend struct Vec3
friend

3-dimensional Vector representation

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

◆ operator* [1/2]

Vector3 operator* ( const Vector3 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]

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

◆ operator/ [1/2]

Vector3 operator/ ( const Vector3 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]

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

Member Data Documentation

◆ zero

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

A vector with zero for all axis.

◆ one

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

A vector with one for all axis.

◆ forward

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

A normalized forward-oriented vector.

◆ back

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

A normalized back-oriented vector.

◆ right

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

A normalized right-oriented vector.

◆ left

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

A normalized left-oriented vector.

◆ up

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

A normalized up-oriented vector.

◆ down

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

A normalized down-oriented vector.

◆ x

float Passer::LinearAlgebra::Vec3::x
protectedinherited

The right axis of the vector.

◆ y

float Passer::LinearAlgebra::Vec3::y
protectedinherited

The upward axis of the vector.

◆ z

float Passer::LinearAlgebra::Vec3::z
protectedinherited

The forward axis of the vector.


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