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
SizeInBytes
The size of the Vector2 type, in bytes.
public static readonly int SizeInBytes
Field Value
UnitX
The X unit Vector2 (1, 0).
public static readonly Vector2 UnitX
Field Value
UnitY
The Y unit Vector2 (0, 1).
public static readonly Vector2 UnitY
Field Value
Zero
A Vector2 with all of its components set to zero.
public static readonly Vector2 Zero
Field Value
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
value1Vector2A Vector2 containing the 2D Cartesian coordinates of vertex 1 of the triangle.
value2Vector2A Vector2 containing the 2D Cartesian coordinates of vertex 2 of the triangle.
value3Vector2A Vector2 containing the 2D Cartesian coordinates of vertex 3 of the triangle.
amount1floatBarycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in
value2).amount2floatBarycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in
value3).
Returns
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
value1Vector2A Vector2 containing the 2D Cartesian coordinates of vertex 1 of the triangle.
value2Vector2A Vector2 containing the 2D Cartesian coordinates of vertex 2 of the triangle.
value3Vector2A Vector2 containing the 2D Cartesian coordinates of vertex 3 of the triangle.
amount1floatBarycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in
value2).amount2floatBarycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in
value3).resultVector2When 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
value1Vector2The first position in the interpolation.
value2Vector2The second position in the interpolation.
value3Vector2The third position in the interpolation.
value4Vector2The fourth position in the interpolation.
amountfloatWeighting 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
value1Vector2The first position in the interpolation.
value2Vector2The second position in the interpolation.
value3Vector2The third position in the interpolation.
value4Vector2The fourth position in the interpolation.
amountfloatWeighting factor.
resultVector2When 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
vVector2indexintThe 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
indexis 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
value1Vector2First source position vector.
tangent1Vector2First source tangent vector.
value2Vector2Second source position vector.
tangent2Vector2Second source tangent vector.
amountfloatWeighting 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
value1Vector2First source position vector.
tangent1Vector2First source tangent vector.
value2Vector2Second source position vector.
tangent2Vector2Second source tangent vector.
amountfloatWeighting factor.
resultVector2When 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
vVector2
Returns
IsZero(Vector2)
Gets a value indicting whether this vector is zero
public static bool IsZero(this Vector2 v)
Parameters
vVector2
Returns
Max(Vector2, Vector2)
public static Vector2 Max(this Vector2 v1, Vector2 v2)
Parameters
Returns
Max(Vector2, ref Vector2)
public static Vector2 Max(this Vector2 v1, ref Vector2 v2)
Parameters
Returns
Min(Vector2, Vector2)
public static Vector2 Min(this Vector2 v1, Vector2 v2)
Parameters
Returns
Min(Vector2, ref Vector2)
public static Vector2 Min(this Vector2 v1, ref Vector2 v2)
Parameters
Returns
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
Returns
- bool
trueif left and right are near another 2D,falseotherwise
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
Returns
- bool
trueif left and right are near another 2D,falseotherwise
Orthogonalize(Vector2[], params Vector2[])
Orthogonalizes a list of vectors.
public static void Orthogonalize(Vector2[] destination, params Vector2[] source)
Parameters
destinationVector2[]The list of orthogonalized vectors.
sourceVector2[]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
sourceordestinationisnull.- ArgumentOutOfRangeException
Thrown when
destinationis shorter in length thansource.
Orthonormalize(Vector2[], params Vector2[])
Orthonormalizes a list of vectors.
public static void Orthonormalize(Vector2[] destination, params Vector2[] source)
Parameters
destinationVector2[]The list of orthonormalized vectors.
sourceVector2[]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
sourceordestinationisnull.- ArgumentOutOfRangeException
Thrown when
destinationis shorter in length thansource.
Saturate(ref Vector2)
Saturates this instance in the range [0,1]
public static void Saturate(ref Vector2 v)
Parameters
vVector2
Set(ref Vector2, int, float)
public static void Set(ref Vector2 v, int index, float value)
Parameters
SmoothStep(Vector2, Vector2, float)
Performs a cubic interpolation between two vectors.
public static Vector2 SmoothStep(Vector2 start, Vector2 end, float amount)
Parameters
startVector2Start vector.
endVector2End vector.
amountfloatValue 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
startVector2Start vector.
endVector2End vector.
amountfloatValue between 0 and 1 indicating the weight of
end.resultVector2When 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
vVector2
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
sourceVector2[]The array of vectors to transform.
transformMatrix4x4The transformation Matrix4x4.
destinationVector4[]The array for which the transformed vectors are stored.
Exceptions
- ArgumentNullException
Thrown when
sourceordestinationisnull.- ArgumentOutOfRangeException
Thrown when
destinationis shorter in length thansource.
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
sourceVector2[]The array of vectors to transform.
rotationQuaternionThe Quaternion rotation to apply.
destinationVector2[]The array for which the transformed vectors are stored. This array may be the same array as
source.
Exceptions
- ArgumentNullException
Thrown when
sourceordestinationisnull.- ArgumentOutOfRangeException
Thrown when
destinationis shorter in length thansource.
TransformCoordinate(Vector2, Matrix4x4)
Performs a coordinate transformation using the given Matrix4x4.
public static Vector2 TransformCoordinate(Vector2 coordinate, Matrix4x4 transform)
Parameters
coordinateVector2The coordinate vector to transform.
transformMatrix4x4The 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
coordinateVector2The coordinate vector to transform.
transformMatrix4x4The transformation Matrix4x4.
resultVector2When 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
sourceVector2[]The array of coordinate vectors to transform.
transformMatrix4x4The transformation Matrix4x4.
destinationVector2[]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
sourceordestinationisnull.- ArgumentOutOfRangeException
Thrown when
destinationis shorter in length thansource.
TransformNormal(Vector2, Matrix4x4)
Performs a normal transformation using the given Matrix4x4.
public static Vector2 TransformNormal(Vector2 normal, Matrix4x4 transform)
Parameters
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
normalVector2The normal vector to transform.
transformMatrix4x4The transformation Matrix4x4.
resultVector2When 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
sourceVector2[]The array of normal vectors to transform.
transformMatrix4x4The transformation Matrix4x4.
destinationVector2[]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
sourceordestinationisnull.- ArgumentOutOfRangeException
Thrown when
destinationis shorter in length thansource.