Vector2 Struct
Namespace: Stride.Core.MathematicsAssembly: Stride.Core.Mathematics.dll
Represents a two dimensional mathematical vector.
[DataContract("float2")]
[DataStyle(DataStyle.Compact)]
public struct Vector2 : IEquatable<Vector2>, IFormattable
Name | Description | |
---|---|---|
Constructors | ||
Vector2(Single) | Initializes a new instance of the Vector2 struct. |
|
Vector2(Single, Single) | Initializes a new instance of the Vector2 struct. |
|
Vector2(Single[]) | Initializes a new instance of the Vector2 struct. |
|
Fields | ||
One | A Vector2 with all of its components set to one. |
|
SizeInBytes | The size of the Vector2 type, in bytes. |
|
UnitX | The X unit Vector2 (1, 0). |
|
UnitY | The Y unit Vector2 (0, 1). |
|
X | The X component of the vector. |
|
Y | The Y component of the vector. |
|
Zero | A Vector2 with all of its components set to zero. |
|
Properties | ||
IsNormalized | Gets a value indicting whether this instance is normalized. |
|
Item[Int32] | Gets or sets the component at the specified index. |
|
Methods | ||
Add(Vector2, Vector2) | Adds two vectors. |
|
Add(ref Vector2, ref Vector2, out Vector2) | Adds two vectors. |
|
Barycentric(Vector2, Vector2, Vector2, Single, Single) | Returns a Vector2 containing the 2D Cartesian coordinates of a point specified in Barycentric coordinates relative to a 2D triangle. |
|
Barycentric(ref Vector2, ref Vector2, ref Vector2, Single, Single, out Vector2) | Returns a Vector2 containing the 2D Cartesian coordinates of a point specified in Barycentric coordinates relative to a 2D triangle. |
|
CatmullRom(Vector2, Vector2, Vector2, Vector2, Single) | Performs a Catmull-Rom interpolation using the specified positions. |
|
CatmullRom(ref Vector2, ref Vector2, ref Vector2, ref Vector2, Single, out Vector2) | Performs a Catmull-Rom interpolation using the specified positions. |
|
Clamp(Vector2, Vector2, Vector2) | Restricts a value to be within a specified range. |
|
Clamp(ref Vector2, ref Vector2, ref Vector2, out Vector2) | Restricts a value to be within a specified range. |
|
Demodulate(Vector2, Vector2) | Demodulates a vector with another by performing component-wise division. |
|
Demodulate(ref Vector2, ref Vector2, out Vector2) | Demodulates a vector with another by performing component-wise division. |
|
Distance(Vector2, Vector2) | Calculates the distance between two vectors. |
|
Distance(ref Vector2, ref Vector2, out Single) | Calculates the distance between two vectors. |
|
DistanceSquared(Vector2, Vector2) | Calculates the squared distance between two vectors. |
|
DistanceSquared(ref Vector2, ref Vector2, out Single) | Calculates the squared distance between two vectors. |
|
Divide(Vector2, Single) | Scales a vector by the given value. |
|
Divide(ref Vector2, Single, out Vector2) | Scales a vector by the given value. |
|
Dot(Vector2, Vector2) | Calculates the dot product of two vectors. |
|
Dot(ref Vector2, ref Vector2, out Single) | Calculates the dot product of two vectors. |
|
Equals(Vector2) | Determines whether the specified Vector2 is equal to this instance. |
|
Equals(Object) | Determines whether the specified System.Object is equal to this instance. |
|
GetHashCode() | Returns a hash code for this instance. |
|
Hermite(Vector2, Vector2, Vector2, Vector2, Single) | Performs a Hermite spline interpolation. |
|
Hermite(ref Vector2, ref Vector2, ref Vector2, ref Vector2, Single, out Vector2) | Performs a Hermite spline interpolation. |
|
Length() | Calculates the length of the vector. |
|
LengthSquared() | Calculates the squared length of the vector. |
|
Lerp(Vector2, Vector2, Single) | Performs a linear interpolation between two vectors. |
|
Lerp(ref Vector2, ref Vector2, Single, out Vector2) | Performs a linear interpolation between two vectors. |
|
Max(Vector2, Vector2) | Returns a vector containing the largest components of the specified vectors. |
|
Max(ref Vector2, ref Vector2, out Vector2) | Returns a vector containing the smallest components of the specified vectors. |
|
Min(Vector2, Vector2) | Returns a vector containing the smallest components of the specified vectors. |
|
Min(ref Vector2, ref Vector2, out Vector2) | Returns a vector containing the smallest components of the specified vectors. |
|
Modulate(Vector2, Vector2) | Modulates a vector with another by performing component-wise multiplication. |
|
Modulate(ref Vector2, ref Vector2, out Vector2) | Modulates a vector with another by performing component-wise multiplication. |
|
Multiply(Vector2, Single) | Scales a vector by the given value. |
|
Multiply(ref Vector2, Single, out Vector2) | Scales a vector by the given value. |
|
Negate(Vector2) | Reverses the direction of a given vector. |
|
Negate(ref Vector2, out Vector2) | Reverses the direction of a given vector. |
|
Normalize() | Converts the vector into a unit vector. |
|
Normalize(Vector2) | Converts the vector into a unit vector. |
|
Normalize(ref Vector2, out Vector2) | Converts the vector into a unit vector. |
|
Orthogonalize(Vector2[], Vector2[]) | Orthogonalizes a list of vectors. |
|
Orthonormalize(Vector2[], Vector2[]) | Orthonormalizes a list of vectors. |
|
Reflect(Vector2, Vector2) | Returns the reflection of a vector off a surface that has the specified normal. |
|
Reflect(ref Vector2, ref Vector2, out Vector2) | Returns the reflection of a vector off a surface that has the specified normal. |
|
SmoothStep(Vector2, Vector2, Single) | Performs a cubic interpolation between two vectors. |
|
SmoothStep(ref Vector2, ref Vector2, Single, out Vector2) | Performs a cubic interpolation between two vectors. |
|
Subtract(Vector2, Vector2) | Subtracts two vectors. |
|
Subtract(ref Vector2, ref Vector2, out Vector2) | Subtracts two vectors. |
|
ToArray() | Creates an array containing the elements of the vector. |
|
ToString() | Returns a System.String that represents this instance. |
|
ToString(IFormatProvider) | Returns a System.String that represents this instance. |
|
ToString(String) | Returns a System.String that represents this instance. |
|
ToString(String, IFormatProvider) | Returns a System.String that represents this instance. |
|
Transform(Vector2, Matrix) | Transforms a 2D vector by the given Matrix. |
|
Transform(Vector2, Quaternion) | Transforms a 2D vector by the given Quaternion rotation. |
|
Transform(ref Vector2, ref Matrix, out Vector4) | Transforms a 2D vector by the given Matrix. |
|
Transform(ref Vector2, ref Quaternion, out Vector2) | Transforms a 2D vector by the given Quaternion rotation. |
|
Transform(Vector2[], ref Matrix, Vector4[]) | Transforms an array of 2D vectors by the given Matrix. |
|
Transform(Vector2[], ref Quaternion, Vector2[]) | Transforms an array of vectors by the given Quaternion rotation. |
|
TransformCoordinate(Vector2, Matrix) | Performs a coordinate transformation using the given Matrix. |
|
TransformCoordinate(ref Vector2, ref Matrix, out Vector2) | Performs a coordinate transformation using the given Matrix. |
|
TransformCoordinate(Vector2[], ref Matrix, Vector2[]) | Performs a coordinate transformation on an array of vectors using the given Matrix. |
|
TransformNormal(Vector2, Matrix) | Performs a normal transformation using the given Matrix. |
|
TransformNormal(ref Vector2, ref Matrix, out Vector2) | Performs a normal transformation using the given Matrix. |
|
TransformNormal(Vector2[], ref Matrix, Vector2[]) | Performs a normal transformation on an array of vectors using the given Matrix. |
|
Operators | ||
Addition(Vector2, Vector2) | Adds two vectors. |
|
Division(Vector2, Vector2) | Divides a vector by the given vector, component-wise. |
|
Division(Vector2, Single) | Scales a vector by the given value. |
|
Division(Single, Vector2) | Divides a numerator by a vector. |
|
Equality(Vector2, Vector2) | Tests for equality between two objects. |
|
Explicit(Vector2 to Vector3) | ||
Explicit(Vector2 to Vector4) | ||
Inequality(Vector2, Vector2) | Tests for inequality between two objects. |
|
Multiply(Vector2, Vector2) | Modulates a vector with another by performing component-wise multiplication. |
|
Multiply(Vector2, Single) | Scales a vector by the given value. |
|
Multiply(Single, Vector2) | Scales a vector by the given value. |
|
Subtraction(Vector2, Vector2) | Subtracts two vectors. |
|
UnaryNegation(Vector2) | Reverses the direction of a given vector. |
|
UnaryPlus(Vector2) | Assert a vector (return it unchanged). |
Constructors
Vector2(Single)
Initializes a new instance of the Vector2 struct.
public Vector2(float value)
Parameters
Type | Name | Description |
---|---|---|
System.Single | value | The value that will be assigned to all components. |
Vector2(Single, Single)
Initializes a new instance of the Vector2 struct.
public Vector2(float x, float y)
Parameters
Type | Name | Description |
---|---|---|
System.Single | x | Initial value for the X component of the vector. |
System.Single | y | Initial value for the Y component of the vector. |
Vector2(Single[])
Initializes a new instance of the Vector2 struct.
public Vector2(float[] values)
Parameters
Type | Name | Description |
---|---|---|
System.Single[] | values | The values to assign to the X and Y components of the vector. This must be an array with two elements. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when |
System.ArgumentOutOfRangeException | Thrown when |
Fields
One
A Vector2 with all of its components set to one.
public static readonly Vector2 One
Field Value
Type | Description |
---|---|
Vector2 |
SizeInBytes
The size of the Vector2 type, in bytes.
public static readonly int SizeInBytes
Field Value
Type | Description |
---|---|
System.Int32 |
UnitX
The X unit Vector2 (1, 0).
public static readonly Vector2 UnitX
Field Value
Type | Description |
---|---|
Vector2 |
UnitY
The Y unit Vector2 (0, 1).
public static readonly Vector2 UnitY
Field Value
Type | Description |
---|---|
Vector2 |
X
The X component of the vector.
[DataMember(0)]
public float X
Field Value
Type | Description |
---|---|
System.Single |
Y
The Y component of the vector.
[DataMember(1)]
public float Y
Field Value
Type | Description |
---|---|
System.Single |
Zero
A Vector2 with all of its components set to zero.
public static readonly Vector2 Zero
Field Value
Type | Description |
---|---|
Vector2 |
Properties
IsNormalized
Gets a value indicting whether this instance is normalized.
public readonly bool IsNormalized { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Item[Int32]
Gets or sets the component at the specified index.
public float this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of the component to access. Use 0 for the X component and 1 for the Y component. |
Property Value
Type | Description |
---|---|
System.Single | The value of the X or Y component, depending on the index. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Thrown when the |
Methods
Add(Vector2, Vector2)
Adds two vectors.
public static Vector2 Add(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first vector to add. |
Vector2 | right | The second vector to add. |
Returns
Type | Description |
---|---|
Vector2 | The sum of the two vectors. |
Add(ref Vector2, ref Vector2, out Vector2)
Adds two vectors.
public static void Add(ref Vector2 left, ref Vector2 right, out Vector2 result)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first vector to add. |
Vector2 | right | The second vector to add. |
Vector2 | result | When the method completes, contains the sum of the two vectors. |
Barycentric(Vector2, Vector2, Vector2, Single, Single)
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
Type | Name | Description |
---|---|---|
Vector2 | value1 | A Vector2 containing the 2D Cartesian coordinates of vertex 1 of the triangle. |
Vector2 | value2 | A Vector2 containing the 2D Cartesian coordinates of vertex 2 of the triangle. |
Vector2 | value3 | A Vector2 containing the 2D Cartesian coordinates of vertex 3 of the triangle. |
System.Single | amount1 | Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in |
System.Single | amount2 | Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in |
Returns
Type | Description |
---|---|
Vector2 | A new Vector2 containing the 2D Cartesian coordinates of the specified point. |
Barycentric(ref Vector2, ref Vector2, ref Vector2, Single, Single, 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
Type | Name | Description |
---|---|---|
Vector2 | value1 | A Vector2 containing the 2D Cartesian coordinates of vertex 1 of the triangle. |
Vector2 | value2 | A Vector2 containing the 2D Cartesian coordinates of vertex 2 of the triangle. |
Vector2 | value3 | A Vector2 containing the 2D Cartesian coordinates of vertex 3 of the triangle. |
System.Single | amount1 | Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in |
System.Single | amount2 | Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in |
Vector2 | result | When the method completes, contains the 2D Cartesian coordinates of the specified point. |
CatmullRom(Vector2, Vector2, Vector2, Vector2, Single)
Performs a Catmull-Rom interpolation using the specified positions.
public static Vector2 CatmullRom(Vector2 value1, Vector2 value2, Vector2 value3, Vector2 value4, float amount)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value1 | The first position in the interpolation. |
Vector2 | value2 | The second position in the interpolation. |
Vector2 | value3 | The third position in the interpolation. |
Vector2 | value4 | The fourth position in the interpolation. |
System.Single | amount | Weighting factor. |
Returns
Type | Description |
---|---|
Vector2 | A vector that is the result of the Catmull-Rom interpolation. |
CatmullRom(ref Vector2, ref Vector2, ref Vector2, ref Vector2, Single, 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
Type | Name | Description |
---|---|---|
Vector2 | value1 | The first position in the interpolation. |
Vector2 | value2 | The second position in the interpolation. |
Vector2 | value3 | The third position in the interpolation. |
Vector2 | value4 | The fourth position in the interpolation. |
System.Single | amount | Weighting factor. |
Vector2 | result | 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
Type | Name | Description |
---|---|---|
Vector2 | value | The value to clamp. |
Vector2 | min | The minimum value. |
Vector2 | max | The maximum value. |
Returns
Type | Description |
---|---|
Vector2 | The clamped value. |
Clamp(ref Vector2, ref Vector2, ref Vector2, out Vector2)
Restricts a value to be within a specified range.
public static void Clamp(ref Vector2 value, ref Vector2 min, ref Vector2 max, out Vector2 result)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The value to clamp. |
Vector2 | min | The minimum value. |
Vector2 | max | The maximum value. |
Vector2 | result | When the method completes, contains the clamped value. |
Demodulate(Vector2, Vector2)
Demodulates a vector with another by performing component-wise division.
public static Vector2 Demodulate(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first vector to demodulate. |
Vector2 | right | The second vector to demodulate. |
Returns
Type | Description |
---|---|
Vector2 | The demodulated vector. |
Demodulate(ref Vector2, ref Vector2, out Vector2)
Demodulates a vector with another by performing component-wise division.
public static void Demodulate(ref Vector2 left, ref Vector2 right, out Vector2 result)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first vector to demodulate. |
Vector2 | right | The second vector to demodulate. |
Vector2 | result | 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
Type | Name | Description |
---|---|---|
Vector2 | value1 | The first vector. |
Vector2 | value2 | The second vector. |
Returns
Type | Description |
---|---|
System.Single | 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 Vector2, ref Vector2, out Single)
Calculates the distance between two vectors.
public static void Distance(ref Vector2 value1, ref Vector2 value2, out float result)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value1 | The first vector. |
Vector2 | value2 | The second vector. |
System.Single | result | When the method completes, contains the distance between the two vectors. |
Remarks
DistanceSquared(ref Vector2, ref Vector2, out Single) 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
Type | Name | Description |
---|---|---|
Vector2 | value1 | The first vector. |
Vector2 | value2 | The second vector. |
Returns
Type | Description |
---|---|
System.Single | 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 Vector2, ref Vector2, out Single)
Calculates the squared distance between two vectors.
public static void DistanceSquared(ref Vector2 value1, ref Vector2 value2, out float result)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value1 | The first vector. |
Vector2 | value2 | The second vector |
System.Single | result | 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, Single)
Scales a vector by the given value.
public static Vector2 Divide(Vector2 value, float scale)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The vector to scale. |
System.Single | scale | The amount by which to scale the vector. |
Returns
Type | Description |
---|---|
Vector2 | The scaled vector. |
Divide(ref Vector2, Single, out Vector2)
Scales a vector by the given value.
public static void Divide(ref Vector2 value, float scale, out Vector2 result)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The vector to scale. |
System.Single | scale | The amount by which to scale the vector. |
Vector2 | result | 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
Type | Name | Description |
---|---|---|
Vector2 | left | First source vector. |
Vector2 | right | Second source vector. |
Returns
Type | Description |
---|---|
System.Single | The dot product of the two vectors. |
Dot(ref Vector2, ref Vector2, out Single)
Calculates the dot product of two vectors.
public static void Dot(ref Vector2 left, ref Vector2 right, out float result)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | First source vector. |
Vector2 | right | Second source vector. |
System.Single | result | When the method completes, contains the dot product of the two vectors. |
Equals(Vector2)
Determines whether the specified Vector2 is equal to this instance.
public bool Equals(Vector2 other)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | other | The Vector2 to compare with this instance. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Equals(Object)
Determines whether the specified System.Object is equal to this instance.
public override bool Equals(object value)
Parameters
Type | Name | Description |
---|---|---|
System.Object | value | The System.Object to compare with this instance. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Overrides
GetHashCode()
Returns a hash code for this instance.
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 | A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. |
Overrides
Hermite(Vector2, Vector2, Vector2, Vector2, Single)
Performs a Hermite spline interpolation.
public static Vector2 Hermite(Vector2 value1, Vector2 tangent1, Vector2 value2, Vector2 tangent2, float amount)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value1 | First source position vector. |
Vector2 | tangent1 | First source tangent vector. |
Vector2 | value2 | Second source position vector. |
Vector2 | tangent2 | Second source tangent vector. |
System.Single | amount | Weighting factor. |
Returns
Type | Description |
---|---|
Vector2 | The result of the Hermite spline interpolation. |
Hermite(ref Vector2, ref Vector2, ref Vector2, ref Vector2, Single, 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
Type | Name | Description |
---|---|---|
Vector2 | value1 | First source position vector. |
Vector2 | tangent1 | First source tangent vector. |
Vector2 | value2 | Second source position vector. |
Vector2 | tangent2 | Second source tangent vector. |
System.Single | amount | Weighting factor. |
Vector2 | result | When the method completes, contains the result of the Hermite spline interpolation. |
Length()
Calculates the length of the vector.
public float Length()
Returns
Type | Description |
---|---|
System.Single | 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
Type | Description |
---|---|
System.Single | 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, Single)
Performs a linear interpolation between two vectors.
public static Vector2 Lerp(Vector2 start, Vector2 end, float amount)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | start | Start vector. |
Vector2 | end | End vector. |
System.Single | amount | Value between 0 and 1 indicating the weight of |
Returns
Type | Description |
---|---|
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 Vector2, ref Vector2, Single, out Vector2)
Performs a linear interpolation between two vectors.
public static void Lerp(ref Vector2 start, ref Vector2 end, float amount, out Vector2 result)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | start | Start vector. |
Vector2 | end | End vector. |
System.Single | amount | Value between 0 and 1 indicating the weight of |
Vector2 | result | 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
Type | Name | Description |
---|---|---|
Vector2 | left | The first source vector. |
Vector2 | right | The second source vector. |
Returns
Type | Description |
---|---|
Vector2 | A vector containing the largest components of the source vectors. |
Max(ref Vector2, ref Vector2, out Vector2)
Returns a vector containing the smallest components of the specified vectors.
public static void Max(ref Vector2 left, ref Vector2 right, out Vector2 result)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first source vector. |
Vector2 | right | The second source vector. |
Vector2 | result | 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
Type | Name | Description |
---|---|---|
Vector2 | left | The first source vector. |
Vector2 | right | The second source vector. |
Returns
Type | Description |
---|---|
Vector2 | A vector containing the smallest components of the source vectors. |
Min(ref Vector2, ref Vector2, out Vector2)
Returns a vector containing the smallest components of the specified vectors.
public static void Min(ref Vector2 left, ref Vector2 right, out Vector2 result)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first source vector. |
Vector2 | right | The second source vector. |
Vector2 | result | 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
Type | Name | Description |
---|---|---|
Vector2 | left | The first vector to modulate. |
Vector2 | right | The second vector to modulate. |
Returns
Type | Description |
---|---|
Vector2 | The modulated vector. |
Modulate(ref Vector2, ref Vector2, out Vector2)
Modulates a vector with another by performing component-wise multiplication.
public static void Modulate(ref Vector2 left, ref Vector2 right, out Vector2 result)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first vector to modulate. |
Vector2 | right | The second vector to modulate. |
Vector2 | result | When the method completes, contains the modulated vector. |
Multiply(Vector2, Single)
Scales a vector by the given value.
public static Vector2 Multiply(Vector2 value, float scale)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The vector to scale. |
System.Single | scale | The amount by which to scale the vector. |
Returns
Type | Description |
---|---|
Vector2 | The scaled vector. |
Multiply(ref Vector2, Single, out Vector2)
Scales a vector by the given value.
public static void Multiply(ref Vector2 value, float scale, out Vector2 result)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The vector to scale. |
System.Single | scale | The amount by which to scale the vector. |
Vector2 | result | When the method completes, contains the scaled vector. |
Negate(Vector2)
Reverses the direction of a given vector.
public static Vector2 Negate(Vector2 value)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The vector to negate. |
Returns
Type | Description |
---|---|
Vector2 | A vector facing in the opposite direction. |
Negate(ref Vector2, out Vector2)
Reverses the direction of a given vector.
public static void Negate(ref Vector2 value, out Vector2 result)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The vector to negate. |
Vector2 | result | 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
Type | Name | Description |
---|---|---|
Vector2 | value | The vector to normalize. |
Returns
Type | Description |
---|---|
Vector2 | The normalized vector. |
Normalize(ref Vector2, out Vector2)
Converts the vector into a unit vector.
public static void Normalize(ref Vector2 value, out Vector2 result)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The vector to normalize. |
Vector2 | result | When the method completes, contains the normalized vector. |
Orthogonalize(Vector2[], Vector2[])
Orthogonalizes a list of vectors.
public static void Orthogonalize(Vector2[] destination, params Vector2[] source)
Parameters
Type | Name | Description |
---|---|---|
Vector2[] | destination | The list of orthogonalized vectors. |
Vector2[] | source | 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
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when |
System.ArgumentOutOfRangeException | Thrown when |
Orthonormalize(Vector2[], Vector2[])
Orthonormalizes a list of vectors.
public static void Orthonormalize(Vector2[] destination, params Vector2[] source)
Parameters
Type | Name | Description |
---|---|---|
Vector2[] | destination | The list of orthonormalized vectors. |
Vector2[] | source | 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
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when |
System.ArgumentOutOfRangeException | Thrown when |
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
Type | Name | Description |
---|---|---|
Vector2 | vector | The source vector. |
Vector2 | normal | Normal of the surface. |
Returns
Type | Description |
---|---|
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 Vector2, ref Vector2, out Vector2)
Returns the reflection of a vector off a surface that has the specified normal.
public static void Reflect(ref Vector2 vector, ref Vector2 normal, out Vector2 result)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | vector | The source vector. |
Vector2 | normal | Normal of the surface. |
Vector2 | result | 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, Single)
Performs a cubic interpolation between two vectors.
public static Vector2 SmoothStep(Vector2 start, Vector2 end, float amount)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | start | Start vector. |
Vector2 | end | End vector. |
System.Single | amount | Value between 0 and 1 indicating the weight of |
Returns
Type | Description |
---|---|
Vector2 | The cubic interpolation of the two vectors. |
SmoothStep(ref Vector2, ref Vector2, Single, 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
Type | Name | Description |
---|---|---|
Vector2 | start | Start vector. |
Vector2 | end | End vector. |
System.Single | amount | Value between 0 and 1 indicating the weight of |
Vector2 | result | When the method completes, contains the cubic interpolation of the two vectors. |
Subtract(Vector2, Vector2)
Subtracts two vectors.
public static Vector2 Subtract(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first vector to subtract. |
Vector2 | right | The second vector to subtract. |
Returns
Type | Description |
---|---|
Vector2 | The difference of the two vectors. |
Subtract(ref Vector2, ref Vector2, out Vector2)
Subtracts two vectors.
public static void Subtract(ref Vector2 left, ref Vector2 right, out Vector2 result)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first vector to subtract. |
Vector2 | right | The second vector to subtract. |
Vector2 | result | 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
Type | Description |
---|---|
System.Single[] | A two-element array containing the components of the vector. |
ToString()
Returns a System.String that represents this instance.
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A System.String that represents this instance. |
Overrides
ToString(IFormatProvider)
Returns a System.String that represents this instance.
public string ToString(IFormatProvider formatProvider)
Parameters
Type | Name | Description |
---|---|---|
System.IFormatProvider | formatProvider | The format provider. |
Returns
Type | Description |
---|---|
System.String | A System.String that represents this instance. |
ToString(String)
Returns a System.String that represents this instance.
public string ToString(string format)
Parameters
Type | Name | Description |
---|---|---|
System.String | format | The format. |
Returns
Type | Description |
---|---|
System.String | A System.String that represents this instance. |
ToString(String, IFormatProvider)
Returns a System.String that represents this instance.
public string ToString(string format, IFormatProvider formatProvider)
Parameters
Type | Name | Description |
---|---|---|
System.String | format | The format. |
System.IFormatProvider | formatProvider | The format provider. |
Returns
Type | Description |
---|---|
System.String | A System.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
Type | Name | Description |
---|---|---|
Vector2 | vector | The source vector. |
Matrix | transform | The transformation Matrix. |
Returns
Type | Description |
---|---|
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
Type | Name | Description |
---|---|---|
Vector2 | vector | The vector to rotate. |
Quaternion | rotation | The Quaternion rotation to apply. |
Returns
Type | Description |
---|---|
Vector2 | The transformed Vector4. |
Transform(ref Vector2, ref Matrix, out Vector4)
Transforms a 2D vector by the given Matrix.
public static void Transform(ref Vector2 vector, ref Matrix transform, out Vector4 result)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | vector | The source vector. |
Matrix | transform | The transformation Matrix. |
Vector4 | result | When the method completes, contains the transformed Vector4. |
Transform(ref Vector2, ref Quaternion, out Vector2)
Transforms a 2D vector by the given Quaternion rotation.
public static void Transform(ref Vector2 vector, ref Quaternion rotation, out Vector2 result)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | vector | The vector to rotate. |
Quaternion | rotation | The Quaternion rotation to apply. |
Vector2 | result | When the method completes, contains the transformed Vector4. |
Transform(Vector2[], ref Matrix, Vector4[])
Transforms an array of 2D vectors by the given Matrix.
public static void Transform(Vector2[] source, ref Matrix transform, Vector4[] destination)
Parameters
Type | Name | Description |
---|---|---|
Vector2[] | source | The array of vectors to transform. |
Matrix | transform | The transformation Matrix. |
Vector4[] | destination | The array for which the transformed vectors are stored. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when |
System.ArgumentOutOfRangeException | Thrown when |
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
Type | Name | Description |
---|---|---|
Vector2[] | source | The array of vectors to transform. |
Quaternion | rotation | The Quaternion rotation to apply. |
Vector2[] | destination | The array for which the transformed vectors are stored.
This array may be the same array as |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when |
System.ArgumentOutOfRangeException | Thrown when |
TransformCoordinate(Vector2, Matrix)
Performs a coordinate transformation using the given Matrix.
public static Vector2 TransformCoordinate(Vector2 coordinate, Matrix transform)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | coordinate | The coordinate vector to transform. |
Matrix | transform | The transformation Matrix. |
Returns
Type | Description |
---|---|
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 wcomponent to be one and therefore makes the vector homogeneous. The homogeneous vector is often prefered when working with coordinates as the w component can safely be ignored.
TransformCoordinate(ref Vector2, ref Matrix, out Vector2)
Performs a coordinate transformation using the given Matrix.
public static void TransformCoordinate(ref Vector2 coordinate, ref Matrix transform, out Vector2 result)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | coordinate | The coordinate vector to transform. |
Matrix | transform | The transformation Matrix. |
Vector2 | result | 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 wcomponent to be one and therefore makes the vector homogeneous. The homogeneous vector is often prefered when working with coordinates as the w component can safely be ignored.
TransformCoordinate(Vector2[], ref Matrix, Vector2[])
Performs a coordinate transformation on an array of vectors using the given Matrix.
public static void TransformCoordinate(Vector2[] source, ref Matrix transform, Vector2[] destination)
Parameters
Type | Name | Description |
---|---|---|
Vector2[] | source | The array of coordinate vectors to trasnform. |
Matrix | transform | The transformation Matrix. |
Vector2[] | destination | The array for which the transformed vectors are stored.
This array may be the same array as |
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 wcomponent to be one and therefore makes the vector homogeneous. The homogeneous vector is often prefered when working with coordinates as the w component can safely be ignored.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when |
System.ArgumentOutOfRangeException | Thrown when |
TransformNormal(Vector2, Matrix)
Performs a normal transformation using the given Matrix.
public static Vector2 TransformNormal(Vector2 normal, Matrix transform)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | normal | The normal vector to transform. |
Matrix | transform | The transformation Matrix. |
Returns
Type | Description |
---|---|
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 collumn 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 prefered for normal vectors as normals purely represent direction rather than location because normal vectors should not be translated.
TransformNormal(ref Vector2, ref Matrix, out Vector2)
Performs a normal transformation using the given Matrix.
public static void TransformNormal(ref Vector2 normal, ref Matrix transform, out Vector2 result)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | normal | The normal vector to transform. |
Matrix | transform | The transformation Matrix. |
Vector2 | result | 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 collumn 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 prefered for normal vectors as normals purely represent direction rather than location because normal vectors should not be translated.
TransformNormal(Vector2[], ref Matrix, Vector2[])
Performs a normal transformation on an array of vectors using the given Matrix.
public static void TransformNormal(Vector2[] source, ref Matrix transform, Vector2[] destination)
Parameters
Type | Name | Description |
---|---|---|
Vector2[] | source | The array of normal vectors to transform. |
Matrix | transform | The transformation Matrix. |
Vector2[] | destination | The array for which the transformed vectors are stored.
This array may be the same array as |
Remarks
A normal transform performs the transformation with the assumption that the w component is zero. This causes the fourth row and fourth collumn 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 prefered for normal vectors as normals purely represent direction rather than location because normal vectors should not be translated.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when |
System.ArgumentOutOfRangeException | Thrown when |
Operators
Addition(Vector2, Vector2)
Adds two vectors.
public static Vector2 operator +(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first vector to add. |
Vector2 | right | The second vector to add. |
Returns
Type | Description |
---|---|
Vector2 | The sum of the two vectors. |
Division(Vector2, Vector2)
Divides a vector by the given vector, component-wise.
public static Vector2 operator /(Vector2 value, Vector2 by)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The vector to scale. |
Vector2 | by | The by. |
Returns
Type | Description |
---|---|
Vector2 | The scaled vector. |
Division(Vector2, Single)
Scales a vector by the given value.
public static Vector2 operator /(Vector2 value, float scale)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The vector to scale. |
System.Single | scale | The amount by which to scale the vector. |
Returns
Type | Description |
---|---|
Vector2 | The scaled vector. |
Division(Single, Vector2)
Divides a numerator by a vector.
public static Vector2 operator /(float numerator, Vector2 value)
Parameters
Type | Name | Description |
---|---|---|
System.Single | numerator | The numerator. |
Vector2 | value | The value. |
Returns
Type | Description |
---|---|
Vector2 | The scaled vector. |
Equality(Vector2, Vector2)
Tests for equality between two objects.
public static bool operator ==(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first value to compare. |
Vector2 | right | The second value to compare. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Explicit(Vector2 to Vector3)
public static explicit operator Vector3(Vector2 value)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The value. |
Returns
Type | Description |
---|---|
Vector3 | The result of the conversion. |
Explicit(Vector2 to Vector4)
public static explicit operator Vector4(Vector2 value)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The value. |
Returns
Type | Description |
---|---|
Vector4 | The result of the conversion. |
Inequality(Vector2, Vector2)
Tests for inequality between two objects.
public static bool operator !=(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first value to compare. |
Vector2 | right | The second value to compare. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Multiply(Vector2, Vector2)
Modulates a vector with another by performing component-wise multiplication.
public static Vector2 operator *(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first vector to multiply. |
Vector2 | right | The second vector to multiply. |
Returns
Type | Description |
---|---|
Vector2 | The multiplication of the two vectors. |
Multiply(Vector2, Single)
Scales a vector by the given value.
public static Vector2 operator *(Vector2 value, float scale)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The vector to scale. |
System.Single | scale | The amount by which to scale the vector. |
Returns
Type | Description |
---|---|
Vector2 | The scaled vector. |
Multiply(Single, Vector2)
Scales a vector by the given value.
public static Vector2 operator *(float scale, Vector2 value)
Parameters
Type | Name | Description |
---|---|---|
System.Single | scale | The amount by which to scale the vector. |
Vector2 | value | The vector to scale. |
Returns
Type | Description |
---|---|
Vector2 | The scaled vector. |
Subtraction(Vector2, Vector2)
Subtracts two vectors.
public static Vector2 operator -(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first vector to subtract. |
Vector2 | right | The second vector to subtract. |
Returns
Type | Description |
---|---|
Vector2 | The difference of the two vectors. |
UnaryNegation(Vector2)
Reverses the direction of a given vector.
public static Vector2 operator -(Vector2 value)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The vector to negate. |
Returns
Type | Description |
---|---|
Vector2 | A vector facing in the opposite direction. |
UnaryPlus(Vector2)
Assert a vector (return it unchanged).
public static Vector2 operator +(Vector2 value)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The vector to assert (unchange). |
Returns
Type | Description |
---|---|
Vector2 | The asserted (unchanged) vector. |