Table of Contents

Class Vector2Helper

Namespace
HelixToolkit.Maths
Assembly
HelixToolkit.Maths.dll

Represents a two dimensional mathematical vector.

public static class Vector2Helper
Inheritance
Vector2Helper
Inherited Members

Fields

One

A Vector2 with all of its components set to one.

public static readonly Vector2 One

Field Value

Vector2

SizeInBytes

The size of the Vector2 type, in bytes.

public static readonly int SizeInBytes

Field Value

int

UnitX

The X unit Vector2 (1, 0).

public static readonly Vector2 UnitX

Field Value

Vector2

UnitY

The Y unit Vector2 (0, 1).

public static readonly Vector2 UnitY

Field Value

Vector2

Zero

A Vector2 with all of its components set to zero.

public static readonly Vector2 Zero

Field Value

Vector2

Methods

Barycentric(Vector2, Vector2, Vector2, float, float)

Returns a Vector2 containing the 2D Cartesian coordinates of a point specified in Barycentric coordinates relative to a 2D triangle.

public static Vector2 Barycentric(Vector2 value1, Vector2 value2, Vector2 value3, float amount1, float amount2)

Parameters

value1 Vector2

A Vector2 containing the 2D Cartesian coordinates of vertex 1 of the triangle.

value2 Vector2

A Vector2 containing the 2D Cartesian coordinates of vertex 2 of the triangle.

value3 Vector2

A Vector2 containing the 2D Cartesian coordinates of vertex 3 of the triangle.

amount1 float

Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in value2).

amount2 float

Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in value3).

Returns

Vector2

A new Vector2 containing the 2D Cartesian coordinates of the specified point.

Barycentric(ref Vector2, ref Vector2, ref Vector2, float, float, out Vector2)

Returns a Vector2 containing the 2D Cartesian coordinates of a point specified in Barycentric coordinates relative to a 2D triangle.

public static void Barycentric(ref Vector2 value1, ref Vector2 value2, ref Vector2 value3, float amount1, float amount2, out Vector2 result)

Parameters

value1 Vector2

A Vector2 containing the 2D Cartesian coordinates of vertex 1 of the triangle.

value2 Vector2

A Vector2 containing the 2D Cartesian coordinates of vertex 2 of the triangle.

value3 Vector2

A Vector2 containing the 2D Cartesian coordinates of vertex 3 of the triangle.

amount1 float

Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in value2).

amount2 float

Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in value3).

result Vector2

When the method completes, contains the 2D Cartesian coordinates of the specified point.

CatmullRom(Vector2, Vector2, Vector2, Vector2, float)

Performs a Catmull-Rom interpolation using the specified positions.

public static Vector2 CatmullRom(Vector2 value1, Vector2 value2, Vector2 value3, Vector2 value4, float amount)

Parameters

value1 Vector2

The first position in the interpolation.

value2 Vector2

The second position in the interpolation.

value3 Vector2

The third position in the interpolation.

value4 Vector2

The fourth position in the interpolation.

amount float

Weighting factor.

Returns

Vector2

A vector that is the result of the Catmull-Rom interpolation.

CatmullRom(ref Vector2, ref Vector2, ref Vector2, ref Vector2, float, out Vector2)

Performs a Catmull-Rom interpolation using the specified positions.

public static void CatmullRom(ref Vector2 value1, ref Vector2 value2, ref Vector2 value3, ref Vector2 value4, float amount, out Vector2 result)

Parameters

value1 Vector2

The first position in the interpolation.

value2 Vector2

The second position in the interpolation.

value3 Vector2

The third position in the interpolation.

value4 Vector2

The fourth position in the interpolation.

amount float

Weighting factor.

result Vector2

When the method completes, contains the result of the Catmull-Rom interpolation.

Get(Vector2, int)

Gets or sets the component at the specified index.

public static float Get(this Vector2 v, int index)

Parameters

v Vector2
index int

The index of the component to access. Use 0 for the X component and 1 for the Y component.

Returns

float

The value of the X or Y component, depending on the index.

Exceptions

ArgumentOutOfRangeException

Thrown when the index is out of the range [0, 1].

Hermite(Vector2, Vector2, Vector2, Vector2, float)

Performs a Hermite spline interpolation.

public static Vector2 Hermite(Vector2 value1, Vector2 tangent1, Vector2 value2, Vector2 tangent2, float amount)

Parameters

value1 Vector2

First source position vector.

tangent1 Vector2

First source tangent vector.

value2 Vector2

Second source position vector.

tangent2 Vector2

Second source tangent vector.

amount float

Weighting factor.

Returns

Vector2

The result of the Hermite spline interpolation.

Hermite(ref Vector2, ref Vector2, ref Vector2, ref Vector2, float, out Vector2)

Performs a Hermite spline interpolation.

public static void Hermite(ref Vector2 value1, ref Vector2 tangent1, ref Vector2 value2, ref Vector2 tangent2, float amount, out Vector2 result)

Parameters

value1 Vector2

First source position vector.

tangent1 Vector2

First source tangent vector.

value2 Vector2

Second source position vector.

tangent2 Vector2

Second source tangent vector.

amount float

Weighting factor.

result Vector2

When the method completes, contains the result of the Hermite spline interpolation.

IsNormalized(Vector2)

Gets a value indicting whether this instance is normalized.

public static bool IsNormalized(this Vector2 v)

Parameters

v Vector2

Returns

bool

IsZero(Vector2)

Gets a value indicting whether this vector is zero

public static bool IsZero(this Vector2 v)

Parameters

v Vector2

Returns

bool

Max(Vector2, Vector2)

public static Vector2 Max(this Vector2 v1, Vector2 v2)

Parameters

v1 Vector2
v2 Vector2

Returns

Vector2

Max(Vector2, ref Vector2)

public static Vector2 Max(this Vector2 v1, ref Vector2 v2)

Parameters

v1 Vector2
v2 Vector2

Returns

Vector2

Min(Vector2, Vector2)

public static Vector2 Min(this Vector2 v1, Vector2 v2)

Parameters

v1 Vector2
v2 Vector2

Returns

Vector2

Min(Vector2, ref Vector2)

public static Vector2 Min(this Vector2 v1, ref Vector2 v2)

Parameters

v1 Vector2
v2 Vector2

Returns

Vector2

NearEqual(Vector2, Vector2, Vector2)

Tests whether one 2D vector is near another 2D vector.

public static bool NearEqual(Vector2 left, Vector2 right, Vector2 epsilon)

Parameters

left Vector2

The left vector.

right Vector2

The right vector.

epsilon Vector2

The epsilon.

Returns

bool

true if left and right are near another 2D, false otherwise

NearEqual(ref Vector2, ref Vector2, ref Vector2)

Tests whether one 2D vector is near another 2D vector.

public static bool NearEqual(ref Vector2 left, ref Vector2 right, ref Vector2 epsilon)

Parameters

left Vector2

The left vector.

right Vector2

The right vector.

epsilon Vector2

The epsilon.

Returns

bool

true if left and right are near another 2D, false otherwise

Orthogonalize(Vector2[], params Vector2[])

Orthogonalizes a list of vectors.

public static void Orthogonalize(Vector2[] destination, params Vector2[] source)

Parameters

destination Vector2[]

The list of orthogonalized vectors.

source Vector2[]

The list of vectors to orthogonalize.

Remarks

Orthogonalization is the process of making all vectors orthogonal to each other. This means that any given vector in the list will be orthogonal to any other given vector in the list.

Because this method uses the modified Gram-Schmidt process, the resulting vectors tend to be numerically unstable. The numeric stability decreases according to the vectors position in the list so that the first vector is the most stable and the last vector is the least stable.

Exceptions

ArgumentNullException

Thrown when source or destination is null.

ArgumentOutOfRangeException

Thrown when destination is shorter in length than source.

Orthonormalize(Vector2[], params Vector2[])

Orthonormalizes a list of vectors.

public static void Orthonormalize(Vector2[] destination, params Vector2[] source)

Parameters

destination Vector2[]

The list of orthonormalized vectors.

source Vector2[]

The list of vectors to orthonormalize.

Remarks

Orthonormalization is the process of making all vectors orthogonal to each other and making all vectors of unit length. This means that any given vector will be orthogonal to any other given vector in the list.

Because this method uses the modified Gram-Schmidt process, the resulting vectors tend to be numerically unstable. The numeric stability decreases according to the vectors position in the list so that the first vector is the most stable and the last vector is the least stable.

Exceptions

ArgumentNullException

Thrown when source or destination is null.

ArgumentOutOfRangeException

Thrown when destination is shorter in length than source.

Saturate(ref Vector2)

Saturates this instance in the range [0,1]

public static void Saturate(ref Vector2 v)

Parameters

v Vector2

Set(ref Vector2, int, float)

public static void Set(ref Vector2 v, int index, float value)

Parameters

v Vector2
index int
value float

SmoothStep(Vector2, Vector2, float)

Performs a cubic interpolation between two vectors.

public static Vector2 SmoothStep(Vector2 start, Vector2 end, float amount)

Parameters

start Vector2

Start vector.

end Vector2

End vector.

amount float

Value between 0 and 1 indicating the weight of end.

Returns

Vector2

The cubic interpolation of the two vectors.

SmoothStep(ref Vector2, ref Vector2, float, out Vector2)

Performs a cubic interpolation between two vectors.

public static void SmoothStep(ref Vector2 start, ref Vector2 end, float amount, out Vector2 result)

Parameters

start Vector2

Start vector.

end Vector2

End vector.

amount float

Value between 0 and 1 indicating the weight of end.

result Vector2

When the method completes, contains the cubic interpolation of the two vectors.

ToArray(Vector2)

Creates an array containing the elements of the vector.

public static float[] ToArray(this Vector2 v)

Parameters

v Vector2

Returns

float[]

A two-element array containing the components of the vector.

Transform(Vector2[], ref Matrix4x4, Vector4[])

Transforms an array of 2D vectors by the given Matrix4x4.

public static void Transform(Vector2[] source, ref Matrix4x4 transform, Vector4[] destination)

Parameters

source Vector2[]

The array of vectors to transform.

transform Matrix4x4

The transformation Matrix4x4.

destination Vector4[]

The array for which the transformed vectors are stored.

Exceptions

ArgumentNullException

Thrown when source or destination is null.

ArgumentOutOfRangeException

Thrown when destination is shorter in length than source.

Transform(Vector2[], ref Quaternion, Vector2[])

Transforms an array of vectors by the given Quaternion rotation.

public static void Transform(Vector2[] source, ref Quaternion rotation, Vector2[] destination)

Parameters

source Vector2[]

The array of vectors to transform.

rotation Quaternion

The Quaternion rotation to apply.

destination Vector2[]

The array for which the transformed vectors are stored. This array may be the same array as source.

Exceptions

ArgumentNullException

Thrown when source or destination is null.

ArgumentOutOfRangeException

Thrown when destination is shorter in length than source.

TransformCoordinate(Vector2, Matrix4x4)

Performs a coordinate transformation using the given Matrix4x4.

public static Vector2 TransformCoordinate(Vector2 coordinate, Matrix4x4 transform)

Parameters

coordinate Vector2

The coordinate vector to transform.

transform Matrix4x4

The transformation Matrix4x4.

Returns

Vector2

The transformed coordinates.

Remarks

A coordinate transform performs the transformation with the assumption that the w component is one. The four dimensional vector obtained from the transformation operation has each component in the vector divided by the w component. This forces the w component to be one and therefore makes the vector homogeneous. The homogeneous vector is often preferred when working with coordinates as the w component can safely be ignored.

TransformCoordinate(ref Vector2, ref Matrix4x4, out Vector2)

Performs a coordinate transformation using the given Matrix4x4.

public static void TransformCoordinate(ref Vector2 coordinate, ref Matrix4x4 transform, out Vector2 result)

Parameters

coordinate Vector2

The coordinate vector to transform.

transform Matrix4x4

The transformation Matrix4x4.

result Vector2

When the method completes, contains the transformed coordinates.

Remarks

A coordinate transform performs the transformation with the assumption that the w component is one. The four dimensional vector obtained from the transformation operation has each component in the vector divided by the w component. This forces the w component to be one and therefore makes the vector homogeneous. The homogeneous vector is often preferred when working with coordinates as the w component can safely be ignored.

TransformCoordinate(Vector2[], ref Matrix4x4, Vector2[])

Performs a coordinate transformation on an array of vectors using the given Matrix4x4.

public static void TransformCoordinate(Vector2[] source, ref Matrix4x4 transform, Vector2[] destination)

Parameters

source Vector2[]

The array of coordinate vectors to transform.

transform Matrix4x4

The transformation Matrix4x4.

destination Vector2[]

The array for which the transformed vectors are stored. This array may be the same array as source.

Remarks

A coordinate transform performs the transformation with the assumption that the w component is one. The four dimensional vector obtained from the transformation operation has each component in the vector divided by the w component. This forces the w component to be one and therefore makes the vector homogeneous. The homogeneous vector is often preferred when working with coordinates as the w component can safely be ignored.

Exceptions

ArgumentNullException

Thrown when source or destination is null.

ArgumentOutOfRangeException

Thrown when destination is shorter in length than source.

TransformNormal(Vector2, Matrix4x4)

Performs a normal transformation using the given Matrix4x4.

public static Vector2 TransformNormal(Vector2 normal, Matrix4x4 transform)

Parameters

normal Vector2

The normal vector to transform.

transform Matrix4x4

The transformation Matrix4x4.

Returns

Vector2

The transformed normal.

Remarks

A normal transform performs the transformation with the assumption that the w component is zero. This causes the fourth row and fourth column of the matrix to be unused. The end result is a vector that is not translated, but all other transformation properties apply. This is often preferred for normal vectors as normals purely represent direction rather than location because normal vectors should not be translated.

TransformNormal(ref Vector2, ref Matrix4x4, out Vector2)

Performs a normal transformation using the given Matrix4x4.

public static void TransformNormal(ref Vector2 normal, ref Matrix4x4 transform, out Vector2 result)

Parameters

normal Vector2

The normal vector to transform.

transform Matrix4x4

The transformation Matrix4x4.

result Vector2

When the method completes, contains the transformed normal.

Remarks

A normal transform performs the transformation with the assumption that the w component is zero. This causes the fourth row and fourth column of the matrix to be unused. The end result is a vector that is not translated, but all other transformation properties apply. This is often preferred for normal vectors as normals purely represent direction rather than location because normal vectors should not be translated.

TransformNormal(Vector2[], ref Matrix4x4, Vector2[])

Performs a normal transformation on an array of vectors using the given Matrix4x4.

public static void TransformNormal(Vector2[] source, ref Matrix4x4 transform, Vector2[] destination)

Parameters

source Vector2[]

The array of normal vectors to transform.

transform Matrix4x4

The transformation Matrix4x4.

destination Vector2[]

The array for which the transformed vectors are stored. This array may be the same array as source.

Remarks

A normal transform performs the transformation with the assumption that the w component is zero. This causes the fourth row and fourth column of the matrix to be unused. The end result is a vector that is not translated, but all other transformation properties apply. This is often preferred for normal vectors as normals purely represent direction rather than location because normal vectors should not be translated.

Exceptions

ArgumentNullException

Thrown when source or destination is null.

ArgumentOutOfRangeException

Thrown when destination is shorter in length than source.