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

A 3-dimensional vector. More...

#include <Vector3.h>

Inheritance diagram for Vector3:
Vec3

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)
 

Detailed Description

A 3-dimensional vector.

This uses the right-handed coordinate system.

Constructor & Destructor Documentation

◆ Vector3() [1/3]

Vector3::Vector3 ( )

Create a new 3-dimensinal zero vector.

◆ Vector3() [2/3]

Vector3::Vector3 ( float  x,
float  y,
float  z 
)

Create a new 3-dimensional vector.

Parameters
xx axis value
yy axis value
zz axis value

◆ Vector3() [3/3]

Vector3::Vector3 ( Vec3  v)

Create a vector from C-style Vec3.

Parameters
vThe C-style Vec

◆ ~Vector3()

Vector3::~Vector3 ( )

Member Function Documentation

◆ Magnitude()

float Vector3::Magnitude ( const Vector3 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 Vector3::magnitude ( ) const

The length of this vector.

Returns
The length of this vector

◆ SqrMagnitude()

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

Vector3 Vector3::Normalize ( Vector3  vector)
static

Connvert a vector to a length of 1.

Parameters
vectorThe vector to convert
Returns
The vector with length 1

◆ normalized()

Vector3 Vector3::normalized ( ) const

Convert the vector to a length of a.

Returns
The vector with length 1

◆ operator-() [1/2]

Vector3 Vector3::operator- ( )

Negate the vector.

Returns
The negated vector

This will result in a vector pointing in the opposite direction

◆ operator-() [2/2]

Vector3 Vector3::operator- ( const Vector3 vector) const

Subtract a vector from this vector.

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

◆ operator+()

Vector3 Vector3::operator+ ( const Vector3 vector2) const

Add another vector to this vector.

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

◆ Scale()

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

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

Vector3 Vector3::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 Vector3::Dot ( const Vector3 vector1,
const Vector3 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 Vector3::operator== ( const Vector3 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 Vector3::Distance ( const Vector3 vector1,
const Vector3 vector2 
)
static

The distance between two vectors.

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

◆ Cross()

Vector3 Vector3::Cross ( const Vector3 vector1,
const Vector3 vector2 
)
static

The cross product of two vectors.

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

◆ Project()

Vector3 Vector3::Project ( Vector3  vector,
Vector3  onNormal 
)
static

Project a vector on another vector.

Parameters
vectorThe vector to project
onNormalThe normal vector to project on
Returns
The projected vector

◆ ProjectOnPlane()

Vector3 Vector3::ProjectOnPlane ( Vector3  vector,
Vector3  planeNormal 
)
static

Projects a vector onto a plane defined by a normal orthogonal to the plane.

Parameters
vectorThe vector to project
planeNormalThe normal of the plane to project on
Returns

◆ Angle()

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

Calculate the angle between two vectors.

Parameters
vector1The first vector
vector2The second vector
Returns

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 ( Vector3  from,
Vector3  to,
Vector3  axis 
)
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

◆ Lerp()

Vector3 Vector3::Lerp ( Vector3  from,
Vector3  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.

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.

◆ right

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

A vector with values (1, 0, 0)

◆ left

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

A vector3 with values (-1, 0, 0)

◆ up

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

A vector with values (0, 1, 0)

◆ down

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

A vector with values (0, -1, 0)

◆ forward

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

A vector with values (0, 0, 1)

◆ back

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

A vector with values (0, 0, -1)

◆ x

float Vec3::x
inherited

The right axis of the vector.

◆ y

float Vec3::y
inherited

The upward axis of the vector.

◆ z

float Vec3::z
inherited

The forward axis of the vector.


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