Nano Brain for Unity v0.1
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Properties | List of all members
LinearAlgebra.Vector2Float Struct Reference

Description

2-dimensional vectors

Public Member Functions

 Vector2Float (float x, float y)
 Create a new 2-dimensional vector.
 
 Vector2Float (Vector2Int v)
 Convert a Vector2Int into a Vector2Float.
 
override readonly bool Equals (object obj)
 Tests if the vector is equal to the given object.
 
override readonly int GetHashCode ()
 Get an hash code for the vector.
 

Static Public Member Functions

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

Public Attributes

float horizontal
 The right axis of the vector.
 
float vertical
 The upward/forward axis of the vector.
 

Static Public Attributes

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

Properties

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

Constructor & Destructor Documentation

◆ Vector2Float() [1/2]

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

Create a new 2-dimensional vector.

Parameters
xx axis value
yy axis value

◆ Vector2Float() [2/2]

LinearAlgebra.Vector2Float.Vector2Float ( Vector2Int  v)

Convert a Vector2Int into a Vector2Float.

Parameters
vThe Vector2Int

Member Function Documentation

◆ operator+()

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

Add two vectors.

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

◆ operator-() [1/2]

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

Subtract two vectors.

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

◆ operator-() [2/2]

static Vector2Float LinearAlgebra.Vector2Float.operator- ( Vector2Float  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/()

static Vector2Float LinearAlgebra.Vector2Float.operator/ ( Vector2Float  v,
float  f 
)
static

Scale a vector uniformly down.

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

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

◆ operator*() [1/2]

static Vector2Float LinearAlgebra.Vector2Float.operator* ( Vector2Float  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 Vector2Float LinearAlgebra.Vector2Float.operator* ( float  f,
Vector2Float  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.

◆ Scale()

static Vector2Float LinearAlgebra.Vector2Float.Scale ( Vector2Float  v1,
Vector2Float  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==()

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

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

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.Vector2Float.operator!= ( Vector2Float  v1,
Vector2Float  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

◆ Equals()

override readonly bool LinearAlgebra.Vector2Float.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

◆ GetHashCode()

override readonly int LinearAlgebra.Vector2Float.GetHashCode ( )

Get an hash code for the vector.

Returns
The hash code

◆ Distance()

static float LinearAlgebra.Vector2Float.Distance ( Vector2Float  v1,
Vector2Float  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.Vector2Float.Dot ( Vector2Float  v1,
Vector2Float  v2 
)
static

The dot product of two vectors.

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

◆ SignedAngle()

static float LinearAlgebra.Vector2Float.SignedAngle ( Vector2Float  from,
Vector2Float  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 Vector2Float LinearAlgebra.Vector2Float.Rotate ( Vector2Float  v1,
AngleFloat  angle 
)
static

Rotates the vector with the given angle.

Parameters
v1The vector to rotate
angleThe angle in degrees
Returns

◆ Lerp()

static Vector2Float LinearAlgebra.Vector2Float.Lerp ( Vector2Float  v1,
Vector2Float  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.

◆ ToFactor()

static float LinearAlgebra.Vector2Float.ToFactor ( Vector2Float  v1,
Vector2Float  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

readonly float LinearAlgebra.Vector2Float.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

readonly float LinearAlgebra.Vector2Float.magnitude
get

The length of this vector.

Returns
The length of this vector

◆ normalized

Vector2Float LinearAlgebra.Vector2Float.normalized
get

Convert the vector to a length of a 1.

Returns
The vector with length 1

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