Roboid Control for C#
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Properties | List of all members
LinearAlgebra.Vector2 Struct Reference

Detailed Description

2-dimensional vectors

Inherits IEquatable< Vector2 >.

Public Member Functions

 Vector2 (float x, float y)
 Create a new 2-dimensional vector.
 
bool Equals (Vector2 v1)
 Tests if the vector has equal values as the given vector.
 
override bool Equals (object obj)
 Tests if the vector is equal to the given object.
 
override int GetHashCode ()
 Get an hash code for the vector.
 

Static Public Member Functions

static Vector2 operator+ (Vector2 v1, Vector2 v2)
 Add two vectors.
 
static Vector2 operator- (Vector2 v1, Vector2 v2)
 Subtract two vectors.
 
static Vector2 operator- (Vector2 v1)
 Negate the vector.
 
static Vector2 operator* (Vector2 v1, float f)
 Scale a vector uniformly up.
 
static Vector2 operator* (float f, Vector2 v1)
 Scale a vector uniformly up.
 
static Vector2 operator/ (Vector2 v1, float f)
 Scale a vector uniformly down.
 
static bool operator== (Vector2 v1, Vector2 v2)
 Tests if the two vectors have equal values.
 
static bool operator!= (Vector2 v1, Vector2 v2)
 Tests if two vectors have different values.
 
static float Distance (Vector2 v1, Vector2 v2)
 Get the distance between two vectors.
 
static float Dot (Vector2 v1, Vector2 v2)
 The dot product of two vectors.
 
static Vector2 Lerp (Vector2 v1, Vector2 v2, float f)
 Lerp between two vectors.
 
static float SignedAngle (Vector2 from, Vector2 to)
 Calculate the signed angle between two vectors.
 
static Vector2 Rotate (Vector2 v1, float angle)
 Rotates the vector with the given angle.
 
static float ToFactor (Vector2 v1, Vector2 v2)
 Map interval of angles between vectors [0..Pi] to interval [0..1].
 

Public Attributes

float x
 The right axis of the vector.
 
float y
 The upward/forward axis of the vector.
 

Static Public Attributes

static readonly Vector2 zero = new Vector2(0, 0)
 A vector with zero for all axis.
 
static readonly Vector2 one = new Vector2(1, 1)
 A vector with values (1, 1)
 
static readonly Vector2 up = new Vector2(0, 1)
 A vector with values (0, 1)
 
static readonly Vector2 down = new Vector2(0, -1)
 A vector with values (0, -1)
 
static readonly Vector2 forward = new Vector2(0, 1)
 A vector with values (0, 1)
 
static readonly Vector2 back = new Vector2(0, -1)
 A vector with values (0, -1)
 
static readonly Vector2 left = new Vector2(-1, 0)
 A vector3 with values (-1, 0)
 
static readonly Vector2 right = new Vector2(1, 0)
 A vector with values (1, 0)
 

Properties

float sqrMagnitude [get]
 The squared length of this vector.
 
float magnitude [get]
 The length of this vector.
 
Vector2 normalized [get]
 Convert the vector to a length of a 1.
 

Constructor & Destructor Documentation

◆ Vector2()

LinearAlgebra.Vector2.Vector2 ( float  x,
float  y 
)

Create a new 2-dimensional vector.

Parameters
xx axis value
yy axis value

Member Function Documentation

◆ operator+()

static Vector2 LinearAlgebra.Vector2.operator+ ( Vector2  v1,
Vector2  v2 
)
static

Add two vectors.

Parameters
v1The first vector
v2The second vector
Returns
The result of adding the two vectors

◆ operator-() [1/2]

static Vector2 LinearAlgebra.Vector2.operator- ( Vector2  v1,
Vector2  v2 
)
static

Subtract two vectors.

Parameters
v1The first vector
v2The second vector
Returns
The result of adding the two vectors

◆ operator-() [2/2]

static Vector2 LinearAlgebra.Vector2.operator- ( Vector2  v1)
static

Negate the vector.

Parameters
v1The vector to negate
Returns
The negated vector

This will result in a vector pointing in the opposite direction

◆ operator*() [1/2]

static Vector2 LinearAlgebra.Vector2.operator* ( Vector2  v1,
float  f 
)
static

Scale a vector uniformly up.

Parameters
v1The vector to scale
fThe scaling factor
Returns
The scaled vector

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

◆ operator*() [2/2]

static Vector2 LinearAlgebra.Vector2.operator* ( float  f,
Vector2  v1 
)
static

Scale a vector uniformly up.

Parameters
fThe scaling factor
v1The vector to scale
Returns
The scaled vector

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

◆ operator/()

static Vector2 LinearAlgebra.Vector2.operator/ ( Vector2  v1,
float  f 
)
static

Scale a vector uniformly down.

Parameters
v1The vector to scale
fThe scaling factor
Returns
The scaled vector

Each component of the vector will be devided by the same factor.

◆ Equals() [1/2]

bool LinearAlgebra.Vector2.Equals ( Vector2  v1)

Tests if the vector has equal values as the given vector.

Parameters
v1The vector to compare to
Returns
true if the vector values are equal

◆ Equals() [2/2]

override bool LinearAlgebra.Vector2.Equals ( object  obj)

Tests if the vector is equal to the given object.

Parameters
objThe object to compare to
Returns
false when the object is not a Vector2 or does not have equal values

◆ operator==()

static bool LinearAlgebra.Vector2.operator== ( Vector2  v1,
Vector2  v2 
)
static

Tests if the two vectors have equal values.

Parameters
v1The first vector
v2The second vector
Returns
truewhen the vectors have equal values

Note that this uses a Float equality check which cannot be not exact in all cases. In most cases it is better to check if the Vector2.Distance between the vectors is smaller than Float.epsilon Or more efficient: (v1 - v2).sqrMagnitude < Float.sqrEpsilon

◆ operator!=()

static bool LinearAlgebra.Vector2.operator!= ( Vector2  v1,
Vector2  v2 
)
static

Tests if two vectors have different values.

Parameters
v1The first vector
v2The second vector
Returns
truewhen the vectors have different values

Note that this uses a Float equality check which cannot be not exact in all case. In most cases it is better to check if the Vector2.Distance between the vectors is smaller than Float.epsilon. Or more efficient: (v1 - v2).sqrMagnitude < Float.sqrEpsilon

◆ GetHashCode()

override int LinearAlgebra.Vector2.GetHashCode ( )

Get an hash code for the vector.

Returns
The hash code

◆ Distance()

static float LinearAlgebra.Vector2.Distance ( Vector2  v1,
Vector2  v2 
)
static

Get the distance between two vectors.

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

◆ Dot()

static float LinearAlgebra.Vector2.Dot ( Vector2  v1,
Vector2  v2 
)
static

The dot product of two vectors.

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

◆ Lerp()

static Vector2 LinearAlgebra.Vector2.Lerp ( Vector2  v1,
Vector2  v2,
float  f 
)
static

Lerp between two vectors.

Parameters
v1The from vector
v2The to vector
fThe interpolation distance [0..1]
Returns
The lerped vector

The factor f is unclamped. Value 0 matches the v1 vector, Value 1 matches the v2 vector Value -1 is v1 vector minus the difference between v1 and v2 etc.

◆ SignedAngle()

static float LinearAlgebra.Vector2.SignedAngle ( Vector2  from,
Vector2  to 
)
static

Calculate the signed angle between two vectors.

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

◆ Rotate()

static Vector2 LinearAlgebra.Vector2.Rotate ( Vector2  v1,
float  angle 
)
static

Rotates the vector with the given angle.

Parameters
v1The vector to rotate
angleThe angle in degrees
Returns

◆ ToFactor()

static float LinearAlgebra.Vector2.ToFactor ( Vector2  v1,
Vector2  v2 
)
static

Map interval of angles between vectors [0..Pi] to interval [0..1].

Parameters
v1The first vector
v2The second vector
Returns
The resulting factor in interval [0..1]

Vectors a and b must be normalized

Property Documentation

◆ sqrMagnitude

float LinearAlgebra.Vector2.sqrMagnitude
get

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.

◆ magnitude

float LinearAlgebra.Vector2.magnitude
get

The length of this vector.

Returns
The length of this vector

◆ normalized

Vector2 LinearAlgebra.Vector2.normalized
get

Convert the vector to a length of a 1.

Returns
The vector with length 1