Table of Contents

Struct Vector2

Namespace
Stride.Core.Mathematics
Assembly
Stride.Core.Mathematics.dll

Represents a two dimensional mathematical vector.

[DataContract("float2")]
[DataStyle(DataStyle.Compact)]
public struct Vector2 : IEquatable<Vector2>, IFormattable
Implements
Extension Methods

Constructors

Vector2(float)

Initializes a new instance of the Vector2 struct.

public Vector2(float value)

Parameters

value float

The value that will be assigned to all components.

Vector2(float, float)

Initializes a new instance of the Vector2 struct.

public Vector2(float x, float y)

Parameters

x float

Initial value for the X component of the vector.

y float

Initial value for the Y component of the vector.

Vector2(float[])

Initializes a new instance of the Vector2 struct.

public Vector2(float[] values)

Parameters

values float[]

The values to assign to the X and Y components of the vector. This must be an array with two elements.

Exceptions

ArgumentNullException

Thrown when values is null.

ArgumentOutOfRangeException

Thrown when values contains more or less than two elements.

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

X

The X component of the vector.

[DataMember(0)]
public float X

Field Value

float

Y

The Y component of the vector.

[DataMember(1)]
public float Y

Field Value

float

Zero

A Vector2 with all of its components set to zero.

public static readonly Vector2 Zero

Field Value

Vector2

Properties

IsNormalized

Gets a value indicting whether this instance is normalized.

public bool IsNormalized { get; }

Property Value

bool

this[int]

Gets or sets the component at the specified index.

public float this[int index] { get; set; }

Parameters

index int

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

Property Value

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].

Methods

Add(Vector2, Vector2)

Adds two vectors.

public static Vector2 Add(Vector2 left, Vector2 right)

Parameters

left Vector2

The first vector to add.

right Vector2

The second vector to add.

Returns

Vector2

The sum of the two vectors.

Add(ref readonly Vector2, ref readonly Vector2, out Vector2)

Adds two vectors.

public static void Add(ref readonly Vector2 left, ref readonly Vector2 right, out Vector2 result)

Parameters

left Vector2

The first vector to add.

right Vector2

The second vector to add.

result Vector2

When the method completes, contains the sum of the two vectors.

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 readonly Vector2, ref readonly Vector2, ref readonly 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 readonly Vector2 value1, ref readonly Vector2 value2, ref readonly 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 readonly Vector2, ref readonly Vector2, ref readonly Vector2, ref readonly Vector2, float, out Vector2)

Performs a Catmull-Rom interpolation using the specified positions.

public static void CatmullRom(ref readonly Vector2 value1, ref readonly Vector2 value2, ref readonly Vector2 value3, ref readonly 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.

Clamp(Vector2, Vector2, Vector2)

Restricts a value to be within a specified range.

public static Vector2 Clamp(Vector2 value, Vector2 min, Vector2 max)

Parameters

value Vector2

The value to clamp.

min Vector2

The minimum value.

max Vector2

The maximum value.

Returns

Vector2

The clamped value.

Clamp(ref readonly Vector2, ref readonly Vector2, ref readonly Vector2, out Vector2)

Restricts a value to be within a specified range.

public static void Clamp(ref readonly Vector2 value, ref readonly Vector2 min, ref readonly Vector2 max, out Vector2 result)

Parameters

value Vector2

The value to clamp.

min Vector2

The minimum value.

max Vector2

The maximum value.

result Vector2

When the method completes, contains the clamped value.

Deconstruct(out float, out float)

Deconstructs the vector's components into named variables.

public void Deconstruct(out float x, out float y)

Parameters

x float

The X component

y float

The Y component

Demodulate(Vector2, Vector2)

Demodulates a vector with another by performing component-wise division.

public static Vector2 Demodulate(Vector2 left, Vector2 right)

Parameters

left Vector2

The first vector to demodulate.

right Vector2

The second vector to demodulate.

Returns

Vector2

The demodulated vector.

Demodulate(ref readonly Vector2, ref readonly Vector2, out Vector2)

Demodulates a vector with another by performing component-wise division.

public static void Demodulate(ref readonly Vector2 left, ref readonly Vector2 right, out Vector2 result)

Parameters

left Vector2

The first vector to demodulate.

right Vector2

The second vector to demodulate.

result Vector2

When the method completes, contains the demodulated vector.

Distance(Vector2, Vector2)

Calculates the distance between two vectors.

public static float Distance(Vector2 value1, Vector2 value2)

Parameters

value1 Vector2

The first vector.

value2 Vector2

The second vector.

Returns

float

The distance between the two vectors.

Remarks

DistanceSquared(Vector2, Vector2) may be preferred when only the relative distance is needed and speed is of the essence.

Distance(ref readonly Vector2, ref readonly Vector2, out float)

Calculates the distance between two vectors.

public static void Distance(ref readonly Vector2 value1, ref readonly Vector2 value2, out float result)

Parameters

value1 Vector2

The first vector.

value2 Vector2

The second vector.

result float

When the method completes, contains the distance between the two vectors.

Remarks

DistanceSquared(ref readonly Vector2, ref readonly Vector2, out float) may be preferred when only the relative distance is needed and speed is of the essence.

DistanceSquared(Vector2, Vector2)

Calculates the squared distance between two vectors.

public static float DistanceSquared(Vector2 value1, Vector2 value2)

Parameters

value1 Vector2

The first vector.

value2 Vector2

The second vector.

Returns

float

The squared distance between the two vectors.

Remarks

Distance squared is the value before taking the square root. Distance squared can often be used in place of distance if relative comparisons are being made. For example, consider three points A, B, and C. To determine whether B or C is further from A, compare the distance between A and B to the distance between A and C. Calculating the two distances involves two square roots, which are computationally expensive. However, using distance squared provides the same information and avoids calculating two square roots.

DistanceSquared(ref readonly Vector2, ref readonly Vector2, out float)

Calculates the squared distance between two vectors.

public static void DistanceSquared(ref readonly Vector2 value1, ref readonly Vector2 value2, out float result)

Parameters

value1 Vector2

The first vector.

value2 Vector2

The second vector

result float

When the method completes, contains the squared distance between the two vectors.

Remarks

Distance squared is the value before taking the square root. Distance squared can often be used in place of distance if relative comparisons are being made. For example, consider three points A, B, and C. To determine whether B or C is further from A, compare the distance between A and B to the distance between A and C. Calculating the two distances involves two square roots, which are computationally expensive. However, using distance squared provides the same information and avoids calculating two square roots.

Divide(Vector2, float)

Scales a vector by the given value.

public static Vector2 Divide(Vector2 value, float scale)

Parameters

value Vector2

The vector to scale.

scale float

The amount by which to scale the vector.

Returns

Vector2

The scaled vector.

Divide(ref readonly Vector2, float, out Vector2)

Scales a vector by the given value.

public static void Divide(ref readonly Vector2 value, float scale, out Vector2 result)

Parameters

value Vector2

The vector to scale.

scale float

The amount by which to scale the vector.

result Vector2

When the method completes, contains the scaled vector.

Dot(Vector2, Vector2)

Calculates the dot product of two vectors.

public static float Dot(Vector2 left, Vector2 right)

Parameters

left Vector2

First source vector.

right Vector2

Second source vector.

Returns

float

The dot product of the two vectors.

Dot(ref readonly Vector2, ref readonly Vector2, out float)

Calculates the dot product of two vectors.

public static void Dot(ref readonly Vector2 left, ref readonly Vector2 right, out float result)

Parameters

left Vector2

First source vector.

right Vector2

Second source vector.

result float

When the method completes, contains the dot product of the two vectors.

Equals(Vector2)

Determines whether the specified Vector2 is within ZeroTolerance for equality to this instance.

public bool Equals(Vector2 other)

Parameters

other Vector2

The Vector2 to compare with this instance.

Returns

bool

true if the specified Vector2 is equal or almost equal to this instance; otherwise, false.

Equals(object)

Determines whether the specified object is within ZeroTolerance for equality to this instance.

public override bool Equals(object value)

Parameters

value object

The object to compare with this instance.

Returns

bool

true if the specified object is equal or almost equal to this instance; otherwise, false.

EqualsStrict(Vector2)

Determines whether the specified Vector2 is exactly equal to this instance.

public bool EqualsStrict(Vector2 other)

Parameters

other Vector2

The Vector2 to compare with this instance.

Returns

bool

true if the specified Vector2 is exactly equal to this instance; otherwise, false.

GetHashCode()

Returns a hash code for this instance.

public override int GetHashCode()

Returns

int

A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.

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 readonly Vector2, ref readonly Vector2, ref readonly Vector2, ref readonly Vector2, float, out Vector2)

Performs a Hermite spline interpolation.

public static void Hermite(ref readonly Vector2 value1, ref readonly Vector2 tangent1, ref readonly Vector2 value2, ref readonly 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.

Length()

Calculates the length of the vector.

public readonly float Length()

Returns

float

The length of the vector.

Remarks

LengthSquared() may be preferred when only the relative length is needed and speed is of the essence.

LengthSquared()

Calculates the squared length of the vector.

public float LengthSquared()

Returns

float

The squared length of the vector.

Remarks

This method may be preferred to Length() when only a relative length is needed and speed is of the essence.

Lerp(Vector2, Vector2, float)

Performs a linear interpolation between two vectors.

public static Vector2 Lerp(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 linear interpolation of the two vectors.

Remarks

This method performs the linear interpolation based on the following formula.

start + (end - start) * amount

Passing amount a value of 0 will cause start to be returned; a value of 1 will cause end to be returned.

Lerp(ref readonly Vector2, ref readonly Vector2, float, out Vector2)

Performs a linear interpolation between two vectors.

public static void Lerp(ref readonly Vector2 start, ref readonly 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 linear interpolation of the two vectors.

Remarks

This method performs the linear interpolation based on the following formula.

start + (end - start) * amount

Passing amount a value of 0 will cause start to be returned; a value of 1 will cause end to be returned.

Max(Vector2, Vector2)

Returns a vector containing the largest components of the specified vectors.

public static Vector2 Max(Vector2 left, Vector2 right)

Parameters

left Vector2

The first source vector.

right Vector2

The second source vector.

Returns

Vector2

A vector containing the largest components of the source vectors.

Max(ref readonly Vector2, ref readonly Vector2, out Vector2)

Returns a vector containing the smallest components of the specified vectors.

public static void Max(ref readonly Vector2 left, ref readonly Vector2 right, out Vector2 result)

Parameters

left Vector2

The first source vector.

right Vector2

The second source vector.

result Vector2

When the method completes, contains an new vector composed of the largest components of the source vectors.

Min(Vector2, Vector2)

Returns a vector containing the smallest components of the specified vectors.

public static Vector2 Min(Vector2 left, Vector2 right)

Parameters

left Vector2

The first source vector.

right Vector2

The second source vector.

Returns

Vector2

A vector containing the smallest components of the source vectors.

Min(ref readonly Vector2, ref readonly Vector2, out Vector2)

Returns a vector containing the smallest components of the specified vectors.

public static void Min(ref readonly Vector2 left, ref readonly Vector2 right, out Vector2 result)

Parameters

left Vector2

The first source vector.

right Vector2

The second source vector.

result Vector2

When the method completes, contains an new vector composed of the smallest components of the source vectors.

Modulate(Vector2, Vector2)

Modulates a vector with another by performing component-wise multiplication.

public static Vector2 Modulate(Vector2 left, Vector2 right)

Parameters

left Vector2

The first vector to modulate.

right Vector2

The second vector to modulate.

Returns

Vector2

The modulated vector.

Modulate(ref readonly Vector2, ref readonly Vector2, out Vector2)

Modulates a vector with another by performing component-wise multiplication.

public static void Modulate(ref readonly Vector2 left, ref readonly Vector2 right, out Vector2 result)

Parameters

left Vector2

The first vector to modulate.

right Vector2

The second vector to modulate.

result Vector2

When the method completes, contains the modulated vector.

MoveTo(in Vector2, in Vector2, float)

Moves the first vector2 to the second one in a straight line.

public static Vector2 MoveTo(in Vector2 from, in Vector2 to, float maxTravelDistance)

Parameters

from Vector2

The first point.

to Vector2

The second point.

maxTravelDistance float

The rate at which the first point is going to move towards the second point.

Returns

Vector2

Multiply(Vector2, float)

Scales a vector by the given value.

public static Vector2 Multiply(Vector2 value, float scale)

Parameters

value Vector2

The vector to scale.

scale float

The amount by which to scale the vector.

Returns

Vector2

The scaled vector.

Multiply(ref readonly Vector2, float, out Vector2)

Scales a vector by the given value.

public static void Multiply(ref readonly Vector2 value, float scale, out Vector2 result)

Parameters

value Vector2

The vector to scale.

scale float

The amount by which to scale the vector.

result Vector2

When the method completes, contains the scaled vector.

Negate(Vector2)

Reverses the direction of a given vector.

public static Vector2 Negate(Vector2 value)

Parameters

value Vector2

The vector to negate.

Returns

Vector2

A vector facing in the opposite direction.

Negate(ref readonly Vector2, out Vector2)

Reverses the direction of a given vector.

public static void Negate(ref readonly Vector2 value, out Vector2 result)

Parameters

value Vector2

The vector to negate.

result Vector2

When the method completes, contains a vector facing in the opposite direction.

Normalize()

Converts the vector into a unit vector.

public void Normalize()

Normalize(Vector2)

Converts the vector into a unit vector.

public static Vector2 Normalize(Vector2 value)

Parameters

value Vector2

The vector to normalize.

Returns

Vector2

The normalized vector.

Normalize(ref readonly Vector2, out Vector2)

Converts the vector into a unit vector.

public static void Normalize(ref readonly Vector2 value, out Vector2 result)

Parameters

value Vector2

The vector to normalize.

result Vector2

When the method completes, contains the normalized vector.

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.

Reflect(Vector2, Vector2)

Returns the reflection of a vector off a surface that has the specified normal.

public static Vector2 Reflect(Vector2 vector, Vector2 normal)

Parameters

vector Vector2

The source vector.

normal Vector2

Normal of the surface.

Returns

Vector2

The reflected vector.

Remarks

Reflect only gives the direction of a reflection off a surface, it does not determine whether the original vector was close enough to the surface to hit it.

Reflect(ref readonly Vector2, ref readonly Vector2, out Vector2)

Returns the reflection of a vector off a surface that has the specified normal.

public static void Reflect(ref readonly Vector2 vector, ref readonly Vector2 normal, out Vector2 result)

Parameters

vector Vector2

The source vector.

normal Vector2

Normal of the surface.

result Vector2

When the method completes, contains the reflected vector.

Remarks

Reflect only gives the direction of a reflection off a surface, it does not determine whether the original vector was close enough to the surface to hit it.

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 readonly Vector2, ref readonly Vector2, float, out Vector2)

Performs a cubic interpolation between two vectors.

public static void SmoothStep(ref readonly Vector2 start, ref readonly 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.

Subtract(in Vector2, in Vector2)

Subtracts two vectors.

public static Vector2 Subtract(in Vector2 left, in Vector2 right)

Parameters

left Vector2

The first vector to subtract.

right Vector2

The second vector to subtract.

Returns

Vector2

The difference of the two vectors.

Subtract(ref readonly Vector2, ref readonly Vector2, out Vector2)

Subtracts two vectors.

public static void Subtract(ref readonly Vector2 left, ref readonly Vector2 right, out Vector2 result)

Parameters

left Vector2

The first vector to subtract.

right Vector2

The second vector to subtract.

result Vector2

When the method completes, contains the difference of the two vectors.

ToArray()

Creates an array containing the elements of the vector.

public float[] ToArray()

Returns

float[]

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

ToString()

Returns a string that represents this instance.

public override string ToString()

Returns

string

A string that represents this instance.

ToString(IFormatProvider)

Returns a string that represents this instance.

public string ToString(IFormatProvider formatProvider)

Parameters

formatProvider IFormatProvider

The format provider.

Returns

string

A string that represents this instance.

ToString(string)

Returns a string that represents this instance.

public string ToString(string format)

Parameters

format string

The format.

Returns

string

A string that represents this instance.

ToString(string, IFormatProvider)

Returns a string that represents this instance.

public string ToString(string format, IFormatProvider formatProvider)

Parameters

format string

The format.

formatProvider IFormatProvider

The format provider.

Returns

string

A string that represents this instance.

Transform(Vector2, Matrix)

Transforms a 2D vector by the given Matrix.

public static Vector4 Transform(Vector2 vector, Matrix transform)

Parameters

vector Vector2

The source vector.

transform Matrix

The transformation Matrix.

Returns

Vector4

The transformed Vector4.

Transform(Vector2, Quaternion)

Transforms a 2D vector by the given Quaternion rotation.

public static Vector2 Transform(Vector2 vector, Quaternion rotation)

Parameters

vector Vector2

The vector to rotate.

rotation Quaternion

The Quaternion rotation to apply.

Returns

Vector2

The transformed Vector4.

Transform(ref readonly Vector2, ref readonly Matrix, out Vector4)

Transforms a 2D vector by the given Matrix.

public static void Transform(ref readonly Vector2 vector, ref readonly Matrix transform, out Vector4 result)

Parameters

vector Vector2

The source vector.

transform Matrix

The transformation Matrix.

result Vector4

When the method completes, contains the transformed Vector4.

Transform(ref readonly Vector2, ref readonly Quaternion, out Vector2)

Transforms a 2D vector by the given Quaternion rotation.

public static void Transform(ref readonly Vector2 vector, ref readonly Quaternion rotation, out Vector2 result)

Parameters

vector Vector2

The vector to rotate.

rotation Quaternion

The Quaternion rotation to apply.

result Vector2

When the method completes, contains the transformed Vector4.

Transform(Vector2[], ref readonly Matrix, Vector4[])

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

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

Parameters

source Vector2[]

The array of vectors to transform.

transform Matrix

The transformation Matrix.

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 readonly Quaternion, Vector2[])

Transforms an array of vectors by the given Quaternion rotation.

public static void Transform(Vector2[] source, ref readonly 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, Matrix)

Performs a coordinate transformation using the given Matrix.

public static Vector2 TransformCoordinate(Vector2 coordinate, Matrix transform)

Parameters

coordinate Vector2

The coordinate vector to transform.

transform Matrix

The transformation Matrix.

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 readonly Vector2, ref readonly Matrix, out Vector2)

Performs a coordinate transformation using the given Matrix.

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

Parameters

coordinate Vector2

The coordinate vector to transform.

transform Matrix

The transformation Matrix.

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 readonly Matrix, Vector2[])

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

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

Parameters

source Vector2[]

The array of coordinate vectors to transform.

transform Matrix

The transformation Matrix.

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, Matrix)

Performs a normal transformation using the given Matrix.

public static Vector2 TransformNormal(Vector2 normal, Matrix transform)

Parameters

normal Vector2

The normal vector to transform.

transform Matrix

The transformation Matrix.

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 readonly Vector2, ref readonly Matrix, out Vector2)

Performs a normal transformation using the given Matrix.

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

Parameters

normal Vector2

The normal vector to transform.

transform Matrix

The transformation Matrix.

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 readonly Matrix, Vector2[])

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

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

Parameters

source Vector2[]

The array of normal vectors to transform.

transform Matrix

The transformation Matrix.

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.

Operators

operator +(Vector2, Vector2)

Adds two vectors.

public static Vector2 operator +(Vector2 left, Vector2 right)

Parameters

left Vector2

The first vector to add.

right Vector2

The second vector to add.

Returns

Vector2

The sum of the two vectors.

operator /(Vector2, Vector2)

Divides a vector by the given vector, component-wise.

public static Vector2 operator /(Vector2 value, Vector2 by)

Parameters

value Vector2

The vector to scale.

by Vector2

The by.

Returns

Vector2

The scaled vector.

operator /(Vector2, float)

Scales a vector by the given value.

public static Vector2 operator /(Vector2 value, float scale)

Parameters

value Vector2

The vector to scale.

scale float

The amount by which to scale the vector.

Returns

Vector2

The scaled vector.

operator /(float, Vector2)

Divides a numerator by a vector.

public static Vector2 operator /(float numerator, Vector2 value)

Parameters

numerator float

The numerator.

value Vector2

The value.

Returns

Vector2

The scaled vector.

operator ==(Vector2, Vector2)

Tests for equality between two objects.

public static bool operator ==(Vector2 left, Vector2 right)

Parameters

left Vector2

The first value to compare.

right Vector2

The second value to compare.

Returns

bool

true if left has the same value as right; otherwise, false.

Remarks

Comparison is not strict, a difference of ZeroTolerance will return as equal.

explicit operator Vector3(Vector2)

Performs an explicit conversion from Vector2 to Vector3.

public static explicit operator Vector3(Vector2 value)

Parameters

value Vector2

The value.

Returns

Vector3

The result of the conversion.

explicit operator Vector4(Vector2)

Performs an explicit conversion from Vector2 to Vector4.

public static explicit operator Vector4(Vector2 value)

Parameters

value Vector2

The value.

Returns

Vector4

The result of the conversion.

operator !=(Vector2, Vector2)

Tests for inequality between two objects.

public static bool operator !=(Vector2 left, Vector2 right)

Parameters

left Vector2

The first value to compare.

right Vector2

The second value to compare.

Returns

bool

true if left has a different value than right; otherwise, false.

Remarks

Comparison is not strict, a difference of ZeroTolerance will return as equal.

operator *(Vector2, Vector2)

Modulates a vector with another by performing component-wise multiplication.

public static Vector2 operator *(Vector2 left, Vector2 right)

Parameters

left Vector2

The first vector to multiply.

right Vector2

The second vector to multiply.

Returns

Vector2

The multiplication of the two vectors.

operator *(Vector2, float)

Scales a vector by the given value.

public static Vector2 operator *(Vector2 value, float scale)

Parameters

value Vector2

The vector to scale.

scale float

The amount by which to scale the vector.

Returns

Vector2

The scaled vector.

operator *(float, Vector2)

Scales a vector by the given value.

public static Vector2 operator *(float scale, Vector2 value)

Parameters

scale float

The amount by which to scale the vector.

value Vector2

The vector to scale.

Returns

Vector2

The scaled vector.

operator -(Vector2, Vector2)

Subtracts two vectors.

public static Vector2 operator -(Vector2 left, Vector2 right)

Parameters

left Vector2

The first vector to subtract.

right Vector2

The second vector to subtract.

Returns

Vector2

The difference of the two vectors.

operator -(Vector2)

Reverses the direction of a given vector.

public static Vector2 operator -(Vector2 value)

Parameters

value Vector2

The vector to negate.

Returns

Vector2

A vector facing in the opposite direction.

operator +(Vector2)

Assert a vector (return it unchanged).

public static Vector2 operator +(Vector2 value)

Parameters

value Vector2

The vector to assert (unchanged).

Returns

Vector2

The asserted (unchanged) vector.