Stowy Physics Engine 0.1.0
Loading...
Searching...
No Matches
stw::Vector2 Struct Reference

A struct representing a 2D Vector. More...

#include <Vector2.hpp>

Public Member Functions

constexpr Vector2 ()
 
constexpr Vector2 (const float x, const float y)
 
float Magnitude () const
 Gets the magnitude of this vector.
 
float SqrMagnitude () const
 Gets the squared magnitude of this vector. It is faster that Magnitude, so it should be used for size comparison.
 
Vector2 Normalized () const
 Gets this vector normalized.
 
float Dot (const Vector2 &other) const
 Computes the dot product between this and other.
 
float Distance (const Vector2 &other) const
 Computes the distance between this and other.
 
float Angle (const Vector2 &other) const
 Computes the angle between this and other.
 
float Major () const
 Gets the biggest component of this vector.
 
Vector2 PositivePerpendicular () const
 Computes the perpendicular vector in +90 degrees.
 
Vector2 NegativePerpendicular () const
 Computes the perpendicular vector in -90 degrees.
 
Vector2 NewMagnitude (float newMagnitude) const
 Sets the magnitude of this vector.
 
void RotateAround (const Vector2 &center, float angle)
 Rotates this vector around the provided axis.
 
std::string ToString () const
 Gets a string representing this vector.
 
Vector2 operator+ (const Vector2 &other) const
 
Vector2 operator- (const Vector2 &other) const
 
Vector2 operator+= (const Vector2 &other)
 
Vector2 operator-= (const Vector2 &other)
 
Vector2 operator+= (float scalar)
 
Vector2 operator-= (float scalar)
 
Vector2 operator*= (float scalar)
 
Vector2 operator/= (float scalar)
 
bool operator== (const Vector2 &other) const
 
Vector2 operator- () const
 

Static Public Member Functions

static Vector2 Normalize (const Vector2 &v)
 Normalizes the given vector.
 
static Vector2 Lerp (const Vector2 &a, const Vector2 &b, float t)
 Linearly interpolates between A and B.
 
static Vector2 TripleProduct (const Vector2 &a, const Vector2 &b, const Vector2 &c)
 Compute the triple product with all of these vectors as 3d vectors with z = 0. p = a x (b x c)
 
static constexpr Vector2 Zero ()
 

Public Attributes

float x
 The X component of the 2D Vector.
 
float y
 The Y component of the 2D Vector.
 

Friends

Vector2 operator+ (Vector2 vec, float scalar)
 
Vector2 operator- (Vector2 vec, float scalar)
 
Vector2 operator* (Vector2 vec, float scalar)
 
Vector2 operator* (float scalar, Vector2 vec)
 
Vector2 operator/ (Vector2 vec, float scalar)
 

Detailed Description

A struct representing a 2D Vector.

Constructor & Destructor Documentation

◆ Vector2() [1/2]

constexpr stw::Vector2::Vector2 ( )
inlineconstexpr

◆ Vector2() [2/2]

constexpr stw::Vector2::Vector2 ( const float x,
const float y )
inlineconstexpr

Member Function Documentation

◆ Angle()

float stw::Vector2::Angle ( const Vector2 & other) const

Computes the angle between this and other.

Parameters
otherThe other vector.
Returns
The angle between this and other.
Here is the call graph for this function:

◆ Distance()

float stw::Vector2::Distance ( const Vector2 & other) const

Computes the distance between this and other.

Parameters
otherThe other vector.
Returns
The distance between this and other.

◆ Dot()

float stw::Vector2::Dot ( const Vector2 & other) const

Computes the dot product between this and other.

Parameters
otherThe other vector.
Returns
The dot product between this and other.

◆ Lerp()

Vector2 stw::Vector2::Lerp ( const Vector2 & a,
const Vector2 & b,
float t )
static

Linearly interpolates between A and B.

Parameters
aStart vector.
bEnd vector.
tValue indicating the progression between a and b. Should be between 0 and 1.
Returns
The linear interpolation between a and b.

◆ Magnitude()

float stw::Vector2::Magnitude ( ) const

Gets the magnitude of this vector.

Returns
The magnitude of this vector.
Here is the call graph for this function:

◆ Major()

float stw::Vector2::Major ( ) const

Gets the biggest component of this vector.

Returns
The biggest component of this vector.

◆ NegativePerpendicular()

Vector2 stw::Vector2::NegativePerpendicular ( ) const

Computes the perpendicular vector in -90 degrees.

Returns
The perpendicular vector in the negative direction.

◆ NewMagnitude()

Vector2 stw::Vector2::NewMagnitude ( float newMagnitude) const

Sets the magnitude of this vector.

Parameters
newMagnitudeThe new magnitude.
Here is the call graph for this function:

◆ Normalize()

Vector2 stw::Vector2::Normalize ( const Vector2 & v)
static

Normalizes the given vector.

Parameters
vThe vector to normalize.
Returns
The normalized vector.
Here is the call graph for this function:

◆ Normalized()

Vector2 stw::Vector2::Normalized ( ) const

Gets this vector normalized.

Returns
This vector normalized.
Here is the call graph for this function:

◆ operator*=()

Vector2 stw::Vector2::operator*= ( float scalar)

◆ operator+()

Vector2 stw::Vector2::operator+ ( const Vector2 & other) const

◆ operator+=() [1/2]

Vector2 stw::Vector2::operator+= ( const Vector2 & other)

◆ operator+=() [2/2]

Vector2 stw::Vector2::operator+= ( float scalar)

◆ operator-() [1/2]

Vector2 stw::Vector2::operator- ( ) const

◆ operator-() [2/2]

Vector2 stw::Vector2::operator- ( const Vector2 & other) const

◆ operator-=() [1/2]

Vector2 stw::Vector2::operator-= ( const Vector2 & other)

◆ operator-=() [2/2]

Vector2 stw::Vector2::operator-= ( float scalar)

◆ operator/=()

Vector2 stw::Vector2::operator/= ( float scalar)

◆ operator==()

bool stw::Vector2::operator== ( const Vector2 & other) const

◆ PositivePerpendicular()

Vector2 stw::Vector2::PositivePerpendicular ( ) const

Computes the perpendicular vector in +90 degrees.

Returns
The perpendicular vector in the positive direction.

◆ RotateAround()

void stw::Vector2::RotateAround ( const Vector2 & center,
float angle )

Rotates this vector around the provided axis.

Parameters
centerThe axis to rotate around.
angleThe angle by which this vector should be rotated.
Here is the call graph for this function:

◆ SqrMagnitude()

float stw::Vector2::SqrMagnitude ( ) const

Gets the squared magnitude of this vector. It is faster that Magnitude, so it should be used for size comparison.

Returns
The squared magnitude of this vector.

◆ ToString()

std::string stw::Vector2::ToString ( ) const

Gets a string representing this vector.

Returns
A string representing this vector.

◆ TripleProduct()

Vector2 stw::Vector2::TripleProduct ( const Vector2 & a,
const Vector2 & b,
const Vector2 & c )
static

Compute the triple product with all of these vectors as 3d vectors with z = 0. p = a x (b x c)

Parameters
aVector a.
bVector b.
cVector c.
Returns
The triple product with a, b and c.

◆ Zero()

constexpr Vector2 stw::Vector2::Zero ( )
staticconstexpr

Friends And Related Symbol Documentation

◆ operator* [1/2]

Vector2 operator* ( float scalar,
Vector2 vec )
friend

◆ operator* [2/2]

Vector2 operator* ( Vector2 vec,
float scalar )
friend

◆ operator+

Vector2 operator+ ( Vector2 vec,
float scalar )
friend

◆ operator-

Vector2 operator- ( Vector2 vec,
float scalar )
friend

◆ operator/

Vector2 operator/ ( Vector2 vec,
float scalar )
friend

Member Data Documentation

◆ x

float stw::Vector2::x

The X component of the 2D Vector.

◆ y

float stw::Vector2::y

The Y component of the 2D Vector.


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