Struct Vector2
A structure encapsulating two double values and provides hardware accelerated methods.
Inherited Members
Namespace: System.Numerics
Assembly: System.Numerics.dll
Syntax
public struct Vector2
Constructors
| Improve this Doc View SourceVector2(Double)
Constructs a vector whose elements are all the single specified value.
Declaration
public Vector2(double value)
Parameters
Type | Name | Description |
---|---|---|
Double | value | The element to fill the vector with. |
Vector2(Double, Double)
Constructs a vector with the given individual elements.
Declaration
public Vector2(double x, double y)
Parameters
Type | Name | Description |
---|---|---|
Double | x | The X component. |
Double | y | The Y component. |
Fields
| Improve this Doc View SourceX
The X component of the vector.
Declaration
public double X
Field Value
Type | Description |
---|---|
Double |
Y
The Y component of the vector.
Declaration
public double Y
Field Value
Type | Description |
---|---|
Double |
Properties
| Improve this Doc View SourceOne
Returns the vector (1,1).
Declaration
public static readonly Vector2 One { get; }
Property Value
Type | Description |
---|---|
Vector2 |
UnitX
Returns the vector (1,0).
Declaration
public static readonly Vector2 UnitX { get; }
Property Value
Type | Description |
---|---|
Vector2 |
UnitY
Returns the vector (0,1).
Declaration
public static readonly Vector2 UnitY { get; }
Property Value
Type | Description |
---|---|
Vector2 |
Zero
Returns the vector (0,0).
Declaration
public static readonly Vector2 Zero { get; }
Property Value
Type | Description |
---|---|
Vector2 |
Methods
| Improve this Doc View SourceAbs(Vector2)
Returns a vector whose elements are the absolute values of each of the source vector's elements.
Declaration
public static Vector2 Abs(Vector2 value)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The source vector. |
Returns
Type | Description |
---|---|
Vector2 | The absolute value vector. |
Add(Vector2, Vector2)
Adds two vectors together.
Declaration
public static Vector2 Add(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first source vector. |
Vector2 | right | The second source vector. |
Returns
Type | Description |
---|---|
Vector2 | The summed vector. |
Clamp(Vector2, Vector2, Vector2)
Restricts a vector between a min and max value.
Declaration
public static Vector2 Clamp(Vector2 value1, Vector2 min, Vector2 max)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value1 | The source vector. |
Vector2 | min | The minimum value. |
Vector2 | max | The maximum value. |
Returns
Type | Description |
---|---|
Vector2 |
CopyTo(Double[])
Copies the contents of the vector into the given array.
Declaration
public void CopyTo(double[] array)
Parameters
Type | Name | Description |
---|---|---|
Double[] | array | The destination array. |
CopyTo(Double[], Int32)
Copies the contents of the vector into the given array, starting from the given index.
Declaration
public void CopyTo(double[] array, int index)
Parameters
Type | Name | Description |
---|---|---|
Double[] | array | |
Int32 | index |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | If array is null. |
ArgumentOutOfRangeException | If index is greater than end of the array or index is less than zero. |
ArgumentException | If number of elements in source vector is greater than those available in destination array or if there are not enough elements to copy. |
Distance(Vector2, Vector2)
Returns the Euclidean distance between the two given points.
Declaration
public static double Distance(Vector2 value1, Vector2 value2)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value1 | The first point. |
Vector2 | value2 | The second point. |
Returns
Type | Description |
---|---|
Double | The distance. |
DistanceSquared(Vector2, Vector2)
Returns the Euclidean distance squared between the two given points.
Declaration
public static double DistanceSquared(Vector2 value1, Vector2 value2)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value1 | The first point. |
Vector2 | value2 | The second point. |
Returns
Type | Description |
---|---|
Double | The distance squared. |
Divide(Vector2, Double)
Divides the vector by the given scalar.
Declaration
public static Vector2 Divide(Vector2 left, double divisor)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The source vector. |
Double | divisor | The scalar value. |
Returns
Type | Description |
---|---|
Vector2 | The result of the division. |
Divide(Vector2, Vector2)
Divides the first vector by the second.
Declaration
public static Vector2 Divide(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first source vector. |
Vector2 | right | The second source vector. |
Returns
Type | Description |
---|---|
Vector2 | The vector resulting from the division. |
Dot(Vector2, Vector2)
Returns the dot product of two vectors.
Declaration
public static double Dot(Vector2 value1, Vector2 value2)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value1 | The first vector. |
Vector2 | value2 | The second vector. |
Returns
Type | Description |
---|---|
Double | The dot product. |
Equals(Vector2)
Returns a boolean indicating whether the given Vector2 is equal to this Vector2 instance.
Declaration
public bool Equals(Vector2 other)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | other | The Vector2 to compare this instance to. |
Returns
Type | Description |
---|---|
Boolean | True if the other Vector2 is equal to this instance; False otherwise. |
Equals(Object)
Returns a boolean indicating whether the given Object is equal to this Vector2 instance.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj | The Object to compare against. |
Returns
Type | Description |
---|---|
Boolean | True if the Object is equal to this Vector2; False otherwise. |
Overrides
| Improve this Doc View SourceGetHashCode()
Returns the hash code for this instance.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | The hash code. |
Overrides
| Improve this Doc View SourceLength()
Returns the length of the vector.
Declaration
public double Length()
Returns
Type | Description |
---|---|
Double | The vector's length. |
LengthSquared()
Returns the length of the vector squared. This operation is cheaper than Length().
Declaration
public double LengthSquared()
Returns
Type | Description |
---|---|
Double | The vector's length squared. |
Lerp(Vector2, Vector2, Double)
Linearly interpolates between two vectors based on the given weighting.
Declaration
public static Vector2 Lerp(Vector2 value1, Vector2 value2, double amount)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value1 | The first source vector. |
Vector2 | value2 | The second source vector. |
Double | amount | Value between 0 and 1 indicating the weight of the second source vector. |
Returns
Type | Description |
---|---|
Vector2 | The interpolated vector. |
Max(Vector2, Vector2)
Returns a vector whose elements are the maximum of each of the pairs of elements in the two source vectors
Declaration
public static Vector2 Max(Vector2 value1, Vector2 value2)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value1 | The first source vector |
Vector2 | value2 | The second source vector |
Returns
Type | Description |
---|---|
Vector2 | The maximized vector |
Min(Vector2, Vector2)
Returns a vector whose elements are the minimum of each of the pairs of elements in the two source vectors.
Declaration
public static Vector2 Min(Vector2 value1, Vector2 value2)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value1 | The first source vector. |
Vector2 | value2 | The second source vector. |
Returns
Type | Description |
---|---|
Vector2 | The minimized vector. |
Multiply(Double, Vector2)
Multiplies a vector by the given scalar.
Declaration
public static Vector2 Multiply(double left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Double | left | The scalar value. |
Vector2 | right | The source vector. |
Returns
Type | Description |
---|---|
Vector2 | The scaled vector. |
Multiply(Vector2, Double)
Multiplies a vector by the given scalar.
Declaration
public static Vector2 Multiply(Vector2 left, double right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The source vector. |
Double | right | The scalar value. |
Returns
Type | Description |
---|---|
Vector2 | The scaled vector. |
Multiply(Vector2, Vector2)
Multiplies two vectors together.
Declaration
public static Vector2 Multiply(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first source vector. |
Vector2 | right | The second source vector. |
Returns
Type | Description |
---|---|
Vector2 | The product vector. |
Negate(Vector2)
Negates a given vector.
Declaration
public static Vector2 Negate(Vector2 value)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The source vector. |
Returns
Type | Description |
---|---|
Vector2 | The negated vector. |
Normalize(Vector2)
Returns a vector with the same direction as the given vector, but with a length of 1.
Declaration
public static Vector2 Normalize(Vector2 value)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The vector to normalize. |
Returns
Type | Description |
---|---|
Vector2 | The normalized vector. |
Reflect(Vector2, Vector2)
Returns the reflection of a vector off a surface that has the specified normal.
Declaration
public static Vector2 Reflect(Vector2 vector, Vector2 normal)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | vector | The source vector. |
Vector2 | normal | The normal of the surface being reflected off. |
Returns
Type | Description |
---|---|
Vector2 | The reflected vector. |
SquareRoot(Vector2)
Returns a vector whose elements are the square root of each of the source vector's elements.
Declaration
public static Vector2 SquareRoot(Vector2 value)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The source vector. |
Returns
Type | Description |
---|---|
Vector2 | The square root vector. |
Subtract(Vector2, Vector2)
Subtracts the second vector from the first.
Declaration
public static Vector2 Subtract(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first source vector. |
Vector2 | right | The second source vector. |
Returns
Type | Description |
---|---|
Vector2 | The difference vector. |
ToString()
Returns a String representing this Vector2 instance.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | The string representation. |
Overrides
| Improve this Doc View SourceTransform(Vector2, Matrix3x2)
Transforms a vector by the given matrix.
Declaration
public static Vector2 Transform(Vector2 position, Matrix3x2 matrix)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | position | The source vector. |
Matrix3x2 | matrix | The transformation matrix. |
Returns
Type | Description |
---|---|
Vector2 | The transformed vector. |
Transform(Vector2, Quaternion)
Transforms a vector by the given Quaternion rotation value.
Declaration
public static Vector2 Transform(Vector2 value, Quaternion rotation)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The source vector to be rotated. |
Quaternion | rotation | The rotation to apply. |
Returns
Type | Description |
---|---|
Vector2 | The transformed vector. |
TransformNormal(Vector2, Matrix3x2)
Transforms a vector normal by the given matrix.
Declaration
public static Vector2 TransformNormal(Vector2 normal, Matrix3x2 matrix)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | normal | The source vector. |
Matrix3x2 | matrix | The transformation matrix. |
Returns
Type | Description |
---|---|
Vector2 | The transformed vector. |
Operators
| Improve this Doc View SourceAddition(Vector2, Vector2)
Adds two vectors together.
Declaration
public static Vector2 operator +(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first source vector. |
Vector2 | right | The second source vector. |
Returns
Type | Description |
---|---|
Vector2 | The summed vector. |
Division(Vector2, Double)
Divides the vector by the given scalar.
Declaration
public static Vector2 operator /(Vector2 value1, double value2)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value1 | The source vector. |
Double | value2 | The scalar value. |
Returns
Type | Description |
---|---|
Vector2 | The result of the division. |
Division(Vector2, Vector2)
Divides the first vector by the second.
Declaration
public static Vector2 operator /(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first source vector. |
Vector2 | right | The second source vector. |
Returns
Type | Description |
---|---|
Vector2 | The vector resulting from the division. |
Equality(Vector2, Vector2)
Returns a boolean indicating whether the two given vectors are equal.
Declaration
public static bool operator ==(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first vector to compare. |
Vector2 | right | The second vector to compare. |
Returns
Type | Description |
---|---|
Boolean | True if the vectors are equal; False otherwise. |
Inequality(Vector2, Vector2)
Returns a boolean indicating whether the two given vectors are not equal.
Declaration
public static bool operator !=(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first vector to compare. |
Vector2 | right | The second vector to compare. |
Returns
Type | Description |
---|---|
Boolean | True if the vectors are not equal; False if they are equal. |
Multiply(Double, Vector2)
Multiplies a vector by the given scalar.
Declaration
public static Vector2 operator *(double left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Double | left | The scalar value. |
Vector2 | right | The source vector. |
Returns
Type | Description |
---|---|
Vector2 | The scaled vector. |
Multiply(Vector2, Double)
Multiplies a vector by the given scalar.
Declaration
public static Vector2 operator *(Vector2 left, double right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The source vector. |
Double | right | The scalar value. |
Returns
Type | Description |
---|---|
Vector2 | The scaled vector. |
Multiply(Vector2, Vector2)
Multiplies two vectors together.
Declaration
public static Vector2 operator *(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first source vector. |
Vector2 | right | The second source vector. |
Returns
Type | Description |
---|---|
Vector2 | The product vector. |
Subtraction(Vector2, Vector2)
Subtracts the second vector from the first.
Declaration
public static Vector2 operator -(Vector2 left, Vector2 right)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | left | The first source vector. |
Vector2 | right | The second source vector. |
Returns
Type | Description |
---|---|
Vector2 | The difference vector. |
UnaryNegation(Vector2)
Negates a given vector.
Declaration
public static Vector2 operator -(Vector2 value)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | value | The source vector. |
Returns
Type | Description |
---|---|
Vector2 | The negated vector. |