Class Vector2
Represents a two dimensional mathematical vector.
Inheritance
Implements
Namespace: FlaxEngine
Assembly: FlaxEngine.CSharp.dll
Syntax
[Unmanaged]
public sealed class Vector2 : ValueType, IEquatable<Vector2>, IFormattable
Constructors
Vector2(Vector3)
Initializes a new instance of the Vector2 struct.
Declaration
public Vector2(Vector3 value)
Parameters
Vector3
value
A vector containing the values with which to initialize the X and Y components. |
Vector2(Vector4)
Initializes a new instance of the Vector2 struct.
Declaration
public Vector2(Vector4 value)
Parameters
Vector4
value
A vector containing the values with which to initialize the X and Y components. |
Vector2(Double)
Initializes a new instance of the Vector2 struct.
Declaration
public Vector2(double value)
Parameters
System.Double
value
The value that will be assigned to all components. |
Vector2(Double, Double)
Initializes a new instance of the Vector2 struct.
Declaration
public Vector2(double x, double y)
Parameters
System.Double
x
Initial value for the X component of the vector. |
System.Double
y
Initial value for the Y component of the vector. |
Vector2(Single)
Initializes a new instance of the Vector2 struct.
Declaration
public Vector2(float value)
Parameters
System.Single
value
The value that will be assigned to all components. |
Vector2(Single, Single)
Initializes a new instance of the Vector2 struct.
Declaration
public Vector2(float x, float y)
Parameters
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.
Declaration
public Vector2(float[] values)
Parameters
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
System.ArgumentNullException
Thrown when |
System.ArgumentOutOfRangeException
Thrown when |
Fields
Half
A Vector2 with all of its components set to half.
Declaration
public static readonly Vector2 Half
Field Value
Vector2
|
Maximum
A Vector2 with all components equal to System.Double.MaxValue (or System.Single.MaxValue if using 32-bit precision).
Declaration
public static readonly Vector2 Maximum
Field Value
Vector2
|
Minimum
A Vector2 with all components equal to System.Double.MinValue (or System.Single.MinValue if using 32-bit precision).
Declaration
public static readonly Vector2 Minimum
Field Value
Vector2
|
One
A Vector2 with all of its components set to one.
Declaration
public static readonly Vector2 One
Field Value
Vector2
|
SizeInBytes
The size of the Vector2 type, in bytes.
Declaration
public static readonly int SizeInBytes
Field Value
System.Int32
|
UnitX
UnitY
X
The X component.
Declaration
public float X
Field Value
System.Single
|
Y
The Y component.
Declaration
public float Y
Field Value
System.Single
|
Zero
A Vector2 with all of its components set to zero.
Declaration
public static readonly Vector2 Zero
Field Value
Vector2
|
Properties
Absolute
Gets a vector with values being absolute values of that vector.
Declaration
public Vector2 Absolute { get; }
Property Value
Vector2
|
AvgValue
Gets an arithmetic average value of all vector components.
Declaration
public float AvgValue { get; }
Property Value
System.Single
|
IsNormalized
Gets a value indicting whether this instance is normalized.
Declaration
public bool IsNormalized { get; }
Property Value
System.Boolean
|
IsZero
Gets a value indicting whether this vector is zero
Declaration
public bool IsZero { get; }
Property Value
System.Boolean
|
Item[Int32]
Gets or sets the component at the specified index.
Declaration
public float this[int index] { get; set; }
Parameters
System.Int32
index
The index of the component to access. Use 0 for the X component and 1 for the Y component. |
Property Value
System.Single
The value of the X or Y component, depending on the index. |
Exceptions
System.ArgumentOutOfRangeException
Thrown when the |
Length
Calculates the length of the vector.
Declaration
public float Length { get; }
Property Value
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.
Declaration
public float LengthSquared { get; }
Property Value
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.
MaxValue
Gets a maximum component value
Declaration
public float MaxValue { get; }
Property Value
System.Single
|
MinValue
Gets a minimum component value
Declaration
public float MinValue { get; }
Property Value
System.Single
|
Negative
Gets a vector with values being opposite to values of that vector.
Declaration
public Vector2 Negative { get; }
Property Value
Vector2
|
Normalized
Gets the normalized vector. Returned vector has length equal 1.
Declaration
public Vector2 Normalized { get; }
Property Value
Vector2
|
ValuesSum
Gets a sum of the component values.
Declaration
public float ValuesSum { get; }
Property Value
System.Single
|
Methods
Abs(Vector2)
Returns the absolute value of a vector.
Declaration
public static Vector2 Abs(Vector2 v)
Parameters
Vector2
v
The value. |
Returns
Vector2
A vector which components are less or equal to 0. |
Add(Vector2, Vector2)
Adds two vectors.
Declaration
public static Vector2 Add(Vector2 left, Vector2 right)
Parameters
Vector2
left
The first vector to add. |
Vector2
right
The second vector to add. |
Returns
Vector2
The sum of the two vectors. |
Add(Vector2, Single)
Performs a component-wise addition.
Declaration
public static Vector2 Add(Vector2 left, float right)
Parameters
Vector2
left
The input vector |
System.Single
right
The scalar value to be added to elements |
Returns
Vector2
The vector with added scalar for each element. |
Add(ref Vector2, ref Vector2, out Vector2)
Adds two vectors.
Declaration
public static void Add(ref Vector2 left, ref Vector2 right, out Vector2 result)
Parameters
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. |
Add(ref Vector2, ref Single, out Vector2)
Performs a component-wise addition.
Declaration
public static void Add(ref Vector2 left, ref float right, out Vector2 result)
Parameters
Vector2
left
The input vector |
System.Single
right
The scalar value to be added to elements |
Vector2
result
The vector with added scalar for each element. |
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.
Declaration
public static Vector2 Barycentric(Vector2 value1, Vector2 value2, Vector2 value3, float amount1, float amount2)
Parameters
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
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.
Declaration
public static void Barycentric(ref Vector2 value1, ref Vector2 value2, ref Vector2 value3, float amount1, float amount2, out Vector2 result)
Parameters
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.
Declaration
public static Vector2 CatmullRom(Vector2 value1, Vector2 value2, Vector2 value3, Vector2 value4, float amount)
Parameters
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
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.
Declaration
public static void CatmullRom(ref Vector2 value1, ref Vector2 value2, ref Vector2 value3, ref Vector2 value4, float amount, out Vector2 result)
Parameters
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. |
Ceil(Vector2)
Returns the vector with components containing the smallest integer greater to or equal to the original value.
Declaration
public static Vector2 Ceil(Vector2 v)
Parameters
Vector2
v
The value. |
Returns
Vector2
The result. |
Clamp(Vector2, Vector2, Vector2)
Restricts a value to be within a specified range.
Declaration
public static Vector2 Clamp(Vector2 value, Vector2 min, Vector2 max)
Parameters
Vector2
value
The value to clamp. |
Vector2
min
The minimum value. |
Vector2
max
The maximum value. |
Returns
Vector2
The clamped value. |
Clamp(ref Vector2, ref Vector2, ref Vector2, out Vector2)
Restricts a value to be within a specified range.
Declaration
public static void Clamp(ref Vector2 value, ref Vector2 min, ref Vector2 max, out Vector2 result)
Parameters
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. |
ClampLength(Vector2, Single)
Makes sure that Length of the output vector is always below max and above 0.
Declaration
public static Vector2 ClampLength(Vector2 vector, float max)
Parameters
Vector2
vector
Input Vector. |
System.Single
max
Max Length |
Returns
Vector2
|
ClampLength(Vector2, Single, Single)
Makes sure that Length of the output vector is always below max and above min.
Declaration
public static Vector2 ClampLength(Vector2 vector, float min, float max)
Parameters
Vector2
vector
Input Vector. |
System.Single
min
Min Length |
System.Single
max
Max Length |
Returns
Vector2
|
ClampLength(Vector2, Single, Single, out Vector2)
Makes sure that Length of the output vector is always below max and above min.
Declaration
public static void ClampLength(Vector2 vector, float min, float max, out Vector2 result)
Parameters
Vector2
vector
Input Vector. |
System.Single
min
Min Length |
System.Single
max
Max Length |
Vector2
result
The result value. |
Cross(Vector2, Vector2)
Calculates the cross product of two vectors.
Declaration
public static float Cross(Vector2 left, Vector2 right)
Parameters
Vector2
left
First source vector. |
Vector2
right
Second source vector. |
Returns
System.Single
The cross product of the two vectors. |
Cross(ref Vector2, ref Vector2)
Calculates the cross product of two vectors.
Declaration
public static float Cross(ref Vector2 left, ref Vector2 right)
Parameters
Vector2
left
First source vector. |
Vector2
right
Second source vector. |
Returns
System.Single
The cross product of the two vectors. |
Cross(ref Vector2, ref Vector2, out Single)
Calculates the cross product of two vectors.
Declaration
public static void Cross(ref Vector2 left, ref Vector2 right, out float result)
Parameters
Vector2
left
First source vector. |
Vector2
right
Second source vector. |
System.Single
result
When the method completes, contains the cross product of the two vectors. |
Distance(Vector2, Vector2)
Calculates the distance between two vectors.
Declaration
public static float Distance(Vector2 value1, Vector2 value2)
Parameters
Vector2
value1
The first vector. |
Vector2
value2
The second vector. |
Returns
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)
Calculates the distance between two vectors.
Declaration
public static float Distance(ref Vector2 value1, ref Vector2 value2)
Parameters
Vector2
value1
The first vector. |
Vector2
value2
The second vector. |
Returns
System.Single
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.
Distance(ref Vector2, ref Vector2, out Single)
Calculates the distance between two vectors.
Declaration
public static void Distance(ref Vector2 value1, ref Vector2 value2, out float result)
Parameters
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.
Declaration
public static float DistanceSquared(Vector2 value1, Vector2 value2)
Parameters
Vector2
value1
The first vector. |
Vector2
value2
The second vector. |
Returns
System.Single
The squared distance between the two vectors. |
DistanceSquared(ref Vector2, ref Vector2)
Calculates the squared distance between two vectors.
Declaration
public static float DistanceSquared(ref Vector2 value1, ref Vector2 value2)
Parameters
Vector2
value1
The first vector. |
Vector2
value2
The second vector |
Returns
System.Single
The squared distance between the two vectors. |
DistanceSquared(ref Vector2, ref Vector2, out Single)
Calculates the squared distance between two vectors.
Declaration
public static void DistanceSquared(ref Vector2 value1, ref Vector2 value2, out float result)
Parameters
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. |
Divide(Vector2, Single)
Scales a vector by the given value.
Declaration
public static Vector2 Divide(Vector2 value, float scale)
Parameters
Vector2
value
The vector to scale. |
System.Single
scale
The amount by which to scale the vector. |
Returns
Vector2
The scaled vector. |
Divide(ref Vector2, Single, out Vector2)
Scales a vector by the given value.
Declaration
public static void Divide(ref Vector2 value, float scale, out Vector2 result)
Parameters
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. |
Divide(Single, Vector2)
Scales a vector by the given value.
Declaration
public static Vector2 Divide(float scale, Vector2 value)
Parameters
System.Single
scale
The amount by which to scale the vector. |
Vector2
value
The vector to scale. |
Returns
Vector2
The scaled vector. |
Divide(Single, ref Vector2, out Vector2)
Scales a vector by the given value.
Declaration
public static void Divide(float scale, ref Vector2 value, out Vector2 result)
Parameters
System.Single
scale
The amount by which to scale the vector. |
Vector2
value
The vector to scale. |
Vector2
result
When the method completes, contains the scaled vector. |
Dot(Vector2, Vector2)
Calculates the dot product of two vectors.
Declaration
public static float Dot(Vector2 left, Vector2 right)
Parameters
Vector2
left
First source vector. |
Vector2
right
Second source vector. |
Returns
System.Single
The dot product of the two vectors. |
Dot(ref Vector2, ref Vector2)
Calculates the dot product of two vectors.
Declaration
public static float Dot(ref Vector2 left, ref Vector2 right)
Parameters
Vector2
left
First source vector. |
Vector2
right
Second source vector. |
Returns
System.Single
The dot product of the two vectors. |
Dot(ref Vector2, ref Vector2, out Single)
Calculates the dot product of two vectors.
Declaration
public static void Dot(ref Vector2 left, ref Vector2 right, out float result)
Parameters
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.
Declaration
public bool Equals(Vector2 other)
Parameters
Vector2
other
The Vector2 to compare with this instance. |
Returns
System.Boolean
|
Equals(ref Vector2)
Determines whether the specified Vector2 is equal to this instance.
Declaration
public bool Equals(ref Vector2 other)
Parameters
Vector2
other
The Vector2 to compare with this instance. |
Returns
System.Boolean
|
Equals(ref Vector2, ref Vector2)
Determines whether the specified Vector2 are equal.
Declaration
public static bool Equals(ref Vector2 a, ref Vector2 b)
Parameters
Vector2
a
|
Vector2
b
|
Returns
System.Boolean
|
Equals(Object)
Determines whether the specified System.Object is equal to this instance.
Declaration
public override bool Equals(object value)
Parameters
System.Object
value
The System.Object to compare with this instance. |
Returns
System.Boolean
|
GetHashCode()
Returns a hash code for this instance.
Declaration
public override int GetHashCode()
Returns
System.Int32
|
Hermite(Vector2, Vector2, Vector2, Vector2, Single)
Performs a Hermite spline interpolation.
Declaration
public static Vector2 Hermite(Vector2 value1, Vector2 tangent1, Vector2 value2, Vector2 tangent2, float amount)
Parameters
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
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.
Declaration
public static void Hermite(ref Vector2 value1, ref Vector2 tangent1, ref Vector2 value2, ref Vector2 tangent2, float amount, out Vector2 result)
Parameters
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. |
Lerp(Vector2, Vector2, Vector2)
Performs a linear interpolation between two vectors.
Declaration
public static Vector2 Lerp(Vector2 start, Vector2 end, Vector2 amount)
Parameters
Vector2
start
Start vector. |
Vector2
end
End vector. |
Vector2
amount
Value between 0 and 1 indicating the weight of |
Returns
Vector2
The linear interpolation of the two vectors. |
Remarks
Passing amount
a value of 0 will cause start
to be returned; a value of 1 will cause end
to be returned.
Lerp(Vector2, Vector2, Single)
Performs a linear interpolation between two vectors.
Declaration
public static Vector2 Lerp(Vector2 start, Vector2 end, float amount)
Parameters
Vector2
start
Start vector. |
Vector2
end
End vector. |
System.Single
amount
Value between 0 and 1 indicating the weight of |
Returns
Vector2
The linear interpolation of the two vectors. |
Remarks
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, ref Vector2, out Vector2)
Performs a linear interpolation between two vectors.
Declaration
public static void Lerp(ref Vector2 start, ref Vector2 end, ref Vector2 amount, out Vector2 result)
Parameters
Vector2
start
Start vector. |
Vector2
end
End vector. |
Vector2
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
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.
Declaration
public static void Lerp(ref Vector2 start, ref Vector2 end, float amount, out Vector2 result)
Parameters
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
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.
Declaration
public static Vector2 Max(Vector2 left, Vector2 right)
Parameters
Vector2
left
The first source vector. |
Vector2
right
The second source vector. |
Returns
Vector2
A vector containing the largest components of the source vectors. |
Max(ref Vector2, ref Vector2, out Vector2)
Returns a vector containing the largest components of the specified vectors.
Declaration
public static void Max(ref Vector2 left, ref Vector2 right, out Vector2 result)
Parameters
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.
Declaration
public static Vector2 Min(Vector2 left, Vector2 right)
Parameters
Vector2
left
The first source vector. |
Vector2
right
The second source vector. |
Returns
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.
Declaration
public static void Min(ref Vector2 left, ref Vector2 right, out Vector2 result)
Parameters
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. |
Mod(Vector2)
Breaks the components of the vector into an integral and a fractional part. Returns vector made of fractional parts.
Declaration
public static Vector2 Mod(Vector2 v)
Parameters
Vector2
v
The value. |
Returns
Vector2
The result. |
Multiply(Vector2, Vector2)
Multiplies a vector with another by performing component-wise multiplication.
Declaration
public static Vector2 Multiply(Vector2 left, Vector2 right)
Parameters
Vector2
left
The first vector to multiply. |
Vector2
right
The second vector to multiply. |
Returns
Vector2
The multiplied vector. |
Multiply(Vector2, Single)
Scales a vector by the given value.
Declaration
public static Vector2 Multiply(Vector2 value, float scale)
Parameters
Vector2
value
The vector to scale. |
System.Single
scale
The amount by which to scale the vector. |
Returns
Vector2
The scaled vector. |
Multiply(ref Vector2, ref Vector2, out Vector2)
Multiplies a vector with another by performing component-wise multiplication.
Declaration
public static void Multiply(ref Vector2 left, ref Vector2 right, out Vector2 result)
Parameters
Vector2
left
The first vector to multiply. |
Vector2
right
The second vector to multiply. |
Vector2
result
When the method completes, contains the multiplied vector. |
Multiply(ref Vector2, Single, out Vector2)
Scales a vector by the given value.
Declaration
public static void Multiply(ref Vector2 value, float scale, out Vector2 result)
Parameters
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. |
NearEqual(Vector2, Vector2, Single)
Tests whether one vector is near another vector.
Declaration
public static bool NearEqual(Vector2 left, Vector2 right, float epsilon = 1E-06F)
Parameters
Vector2
left
The left vector. |
Vector2
right
The right vector. |
System.Single
epsilon
The epsilon. |
Returns
System.Boolean
|
NearEqual(ref Vector2, ref Vector2, Single)
Tests whether one vector is near another vector.
Declaration
public static bool NearEqual(ref Vector2 left, ref Vector2 right, float epsilon = 1E-06F)
Parameters
Vector2
left
The left vector. |
Vector2
right
The right vector. |
System.Single
epsilon
The epsilon. |
Returns
System.Boolean
|
Negate(Vector2)
Reverses the direction of a given vector.
Declaration
public static Vector2 Negate(Vector2 value)
Parameters
Vector2
value
The vector to negate. |
Returns
Vector2
A vector facing in the opposite direction. |
Negate(ref Vector2, out Vector2)
Reverses the direction of a given vector.
Declaration
public static void Negate(ref Vector2 value, out Vector2 result)
Parameters
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.
Declaration
public void Normalize()
Normalize(Vector2)
Converts the vector into a unit vector.
Declaration
public static Vector2 Normalize(Vector2 value)
Parameters
Vector2
value
The vector to normalize. |
Returns
Vector2
The normalized vector. |
Normalize(ref Vector2, out Vector2)
Converts the vector into a unit vector.
Declaration
public static void Normalize(ref Vector2 value, out Vector2 result)
Parameters
Vector2
value
The vector to normalize. |
Vector2
result
When the method completes, contains the normalized vector. |
Perpendicular(Vector2)
Calculates the 2D vector perpendicular to the given 2D vector. The result is always rotated 90-degrees in a counter-clockwise direction for a 2D coordinate system where the positive Y axis goes up.
Declaration
public static Vector2 Perpendicular(Vector2 inDirection)
Parameters
Vector2
inDirection
The input direction. |
Returns
Vector2
The result. |
Perpendicular(ref Vector2, out Vector2)
Calculates the 2D vector perpendicular to the given 2D vector. The result is always rotated 90-degrees in a counter-clockwise direction for a 2D coordinate system where the positive Y axis goes up.
Declaration
public static void Perpendicular(ref Vector2 inDirection, out Vector2 result)
Parameters
Vector2
inDirection
The in direction. |
Vector2
result
When the method completes, contains the result of the calculation. |
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
Vector2
vector
The source vector. |
Vector2
normal
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 Vector2, ref Vector2, out Vector2)
Returns the reflection of a vector off a surface that has the specified normal.
Declaration
public static void Reflect(ref Vector2 vector, ref Vector2 normal, out Vector2 result)
Parameters
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.
Round(Vector2)
Returns the vector with components rounded to the nearest integer.
Declaration
public static Vector2 Round(Vector2 v)
Parameters
Vector2
v
The value. |
Returns
Vector2
The result. |
Saturate()
Saturates this instance in the range [0,1].
Declaration
public void Saturate()
SmoothDamp(Vector2, Vector2, ref Vector2, Single)
Performs a gradual change of a vector towards a specified target over time
Declaration
public static Vector2 SmoothDamp(Vector2 current, Vector2 target, ref Vector2 currentVelocity, float smoothTime)
Parameters
Vector2
current
Current vector. |
Vector2
target
Target vector. |
Vector2
currentVelocity
Used to store the current velocity. |
System.Single
smoothTime
Determines the approximate time it should take to reach the target vector. |
Returns
Vector2
|
SmoothDamp(Vector2, Vector2, ref Vector2, Single, Single)
Performs a gradual change of a vector towards a specified target over time
Declaration
public static Vector2 SmoothDamp(Vector2 current, Vector2 target, ref Vector2 currentVelocity, float smoothTime, float maxSpeed)
Parameters
Vector2
current
Current vector. |
Vector2
target
Target vector. |
Vector2
currentVelocity
Used to store the current velocity. |
System.Single
smoothTime
Determines the approximate time it should take to reach the target vector. |
System.Single
maxSpeed
Defines the upper limit on the speed of the Smooth Damp. |
Returns
Vector2
|
SmoothDamp(Vector2, Vector2, ref Vector2, Single, Single, Single)
Performs a gradual change of a vector towards a specified target over time
Declaration
public static Vector2 SmoothDamp(Vector2 current, Vector2 target, ref Vector2 currentVelocity, float smoothTime, float maxSpeed, float deltaTime)
Parameters
Vector2
current
Current vector. |
Vector2
target
Target vector. |
Vector2
currentVelocity
Used to store the current velocity. |
System.Single
smoothTime
Determines the approximate time it should take to reach the target vector. |
System.Single
maxSpeed
Defines the upper limit on the speed of the Smooth Damp. |
System.Single
deltaTime
Delta Time, represents the time elapsed since last frame. |
Returns
Vector2
|
SmoothStep(Vector2, Vector2, Single)
Performs a cubic interpolation between two vectors.
Declaration
public static Vector2 SmoothStep(Vector2 start, Vector2 end, float amount)
Parameters
Vector2
start
Start vector. |
Vector2
end
End vector. |
System.Single
amount
Value between 0 and 1 indicating the weight of |
Returns
Vector2
The cubic interpolation of the two vectors. |
SmoothStep(ref Vector2, ref Vector2, Single, out Vector2)
Performs a cubic interpolation between two vectors.
Declaration
public static void SmoothStep(ref Vector2 start, ref Vector2 end, float amount, out Vector2 result)
Parameters
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. |
SnapToGrid(Vector2, Vector2)
Snaps the input position into the grid.
Declaration
public static Vector2 SnapToGrid(Vector2 pos, Vector2 gridSize)
Parameters
Vector2
pos
The position to snap. |
Vector2
gridSize
The size of the grid. |
Returns
Vector2
The position snapped to the grid. |
Subtract(Vector2, Vector2)
Subtracts two vectors.
Declaration
public static Vector2 Subtract(Vector2 left, Vector2 right)
Parameters
Vector2
left
The first vector to subtract. |
Vector2
right
The second vector to subtract. |
Returns
Vector2
The difference of the two vectors. |
Subtract(Vector2, Single)
Performs a component-wise subtraction.
Declaration
public static Vector2 Subtract(Vector2 left, float right)
Parameters
Vector2
left
The input vector |
System.Single
right
The scalar value to be subtracted from elements |
Returns
Vector2
The vector with subtracted scalar for each element. |
Subtract(ref Vector2, ref Vector2, out Vector2)
Subtracts two vectors.
Declaration
public static void Subtract(ref Vector2 left, ref Vector2 right, out Vector2 result)
Parameters
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. |
Subtract(ref Vector2, ref Single, out Vector2)
Performs a component-wise subtraction.
Declaration
public static void Subtract(ref Vector2 left, ref float right, out Vector2 result)
Parameters
Vector2
left
The input vector |
System.Single
right
The scalar value to be subtracted from elements |
Vector2
result
The vector with subtracted scalar for each element. |
Subtract(Single, Vector2)
Performs a component-wise subtraction.
Declaration
public static Vector2 Subtract(float left, Vector2 right)
Parameters
System.Single
left
The scalar value to be subtracted from elements |
Vector2
right
The input vector |
Returns
Vector2
The vector with subtracted scalar for each element. |
Subtract(ref Single, ref Vector2, out Vector2)
Performs a component-wise subtraction.
Declaration
public static void Subtract(ref float left, ref Vector2 right, out Vector2 result)
Parameters
System.Single
left
The scalar value to be subtracted from elements |
Vector2
right
The input vector |
Vector2
result
The vector with subtracted scalar for each element. |
ToArray()
Creates an array containing the elements of the vector.
Declaration
public float[] ToArray()
Returns
System.Single[]
|
ToString()
Returns a System.String that represents this instance.
Declaration
public override string ToString()
Returns
System.String
A System.String that represents this instance. |
ToString(IFormatProvider)
Returns a System.String that represents this instance.
Declaration
public string ToString(IFormatProvider formatProvider)
Parameters
System.IFormatProvider
formatProvider
The format provider. |
Returns
System.String
A System.String that represents this instance. |
ToString(String)
Returns a System.String that represents this instance.
Declaration
public string ToString(string format)
Parameters
System.String
format
The format. |
Returns
System.String
A System.String that represents this instance. |
ToString(String, IFormatProvider)
Returns a System.String that represents this instance.
Declaration
public string ToString(string format, IFormatProvider formatProvider)
Parameters
System.String
format
The format. |
System.IFormatProvider
formatProvider
The format provider. |
Returns
System.String
A System.String that represents this instance. |
Transform(Vector2, Matrix)
Transforms a 2D vector by the given Matrix.
Declaration
public static Vector4 Transform(Vector2 vector, Matrix transform)
Parameters
Vector2
vector
The source vector. |
Matrix
transform
The transformation Matrix. |
Returns
Vector4
The transformed Vector4. |
Transform(Vector2, Quaternion)
Transforms a 2D vector by the given Quaternion rotation.
Declaration
public static Vector2 Transform(Vector2 vector, Quaternion rotation)
Parameters
Vector2
vector
The vector to rotate. |
Quaternion
rotation
The Quaternion rotation to apply. |
Returns
Vector2
The transformed Vector4. |
Transform(ref Vector2, ref Matrix, out Vector4)
Transforms a 2D vector by the given Matrix.
Declaration
public static void Transform(ref Vector2 vector, ref Matrix transform, out Vector4 result)
Parameters
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.
Declaration
public static void Transform(ref Vector2 vector, ref Quaternion rotation, out Vector2 result)
Parameters
Vector2
vector
The vector to rotate. |
Quaternion
rotation
The Quaternion rotation to apply. |
Vector2
result
When the method completes, contains the transformed Vector4. |
TransformCoordinate(Vector2, Matrix)
Performs a coordinate transformation using the given Matrix.
Declaration
public static Vector2 TransformCoordinate(Vector2 coordinate, Matrix transform)
Parameters
Vector2
coordinate
The coordinate vector to transform. |
Matrix
transform
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 Vector2, ref Matrix, out Vector2)
Performs a coordinate transformation using the given Matrix.
Declaration
public static void TransformCoordinate(ref Vector2 coordinate, ref Matrix transform, out Vector2 result)
Parameters
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 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.
TransformNormal(Vector2, Matrix)
Performs a normal transformation using the given Matrix.
Declaration
public static Vector2 TransformNormal(Vector2 normal, Matrix transform)
Parameters
Vector2
normal
The normal vector to transform. |
Matrix
transform
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 Vector2, ref Matrix, out Vector2)
Performs a normal transformation using the given Matrix.
Declaration
public static void TransformNormal(ref Vector2 normal, ref Matrix transform, out Vector2 result)
Parameters
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 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.
TriangleArea(ref Vector2, ref Vector2, ref Vector2)
Calculates the area of the triangle.
Declaration
public static float TriangleArea(ref Vector2 v0, ref Vector2 v1, ref Vector2 v2)
Parameters
Vector2
v0
The first triangle vertex. |
Vector2
v1
The second triangle vertex. |
Vector2
v2
The third triangle vertex. |
Returns
System.Single
The triangle area. |
Operators
Addition(Float2, Vector2)
Adds a vector to another by performing component-wise addition.
Declaration
public static Float2 operator +(Float2 left, Vector2 right)
Parameters
Float2
left
The first vector to add. |
Vector2
right
The second vector to add. |
Returns
Float2
The sum of the two vectors. |
Addition(Vector2, Float2)
Adds a vector to another by performing component-wise addition.
Declaration
public static Vector2 operator +(Vector2 left, Float2 right)
Parameters
Vector2
left
The first vector to add. |
Float2
right
The second vector to add. |
Returns
Vector2
The sum of the two vectors. |
Addition(Vector2, Vector2)
Adds two vectors.
Declaration
public static Vector2 operator +(Vector2 left, Vector2 right)
Parameters
Vector2
left
The first vector to add. |
Vector2
right
The second vector to add. |
Returns
Vector2
The sum of the two vectors. |
Addition(Vector2, Single)
Performs a component-wise addition.
Declaration
public static Vector2 operator +(Vector2 value, float scalar)
Parameters
Vector2
value
The input vector. |
System.Single
scalar
The scalar value to be added on elements |
Returns
Vector2
The vector with added scalar for each element. |
Addition(Single, Vector2)
Performs a component-wise addition.
Declaration
public static Vector2 operator +(float scalar, Vector2 value)
Parameters
System.Single
scalar
The scalar value to be added on elements |
Vector2
value
The input vector. |
Returns
Vector2
The vector with added scalar for each element. |
Division(Vector2, Vector2)
Scales a vector by the given value.
Declaration
public static Vector2 operator /(Vector2 value, Vector2 scale)
Parameters
Vector2
value
The vector to scale. |
Vector2
scale
The amount by which to scale the vector. |
Returns
Vector2
The scaled vector. |
Division(Vector2, Single)
Scales a vector by the given value.
Declaration
public static Vector2 operator /(Vector2 value, float scale)
Parameters
Vector2
value
The vector to scale. |
System.Single
scale
The amount by which to scale the vector. |
Returns
Vector2
The scaled vector. |
Division(Single, Vector2)
Scales a vector by the given value.
Declaration
public static Vector2 operator /(float scale, Vector2 value)
Parameters
System.Single
scale
The amount by which to scale the vector. |
Vector2
value
The vector to scale. |
Returns
Vector2
The scaled vector. |
Equality(Vector2, Vector2)
Tests for equality between two objects.
Declaration
public static bool operator ==(Vector2 left, Vector2 right)
Parameters
Vector2
left
The first value to compare. |
Vector2
right
The second value to compare. |
Returns
System.Boolean
|
Explicit(Vector2 to Vector3)
Declaration
public static explicit operator Vector3(Vector2 value)
Parameters
Vector2
value
The value. |
Returns
Vector3
The result of the conversion. |
Explicit(Vector2 to Vector4)
Declaration
public static explicit operator Vector4(Vector2 value)
Parameters
Vector2
value
The value. |
Returns
Vector4
The result of the conversion. |
Implicit(Vector2 to Double2)
Declaration
public static implicit operator Double2(Vector2 value)
Parameters
Vector2
value
The value. |
Returns
Double2
The result of the conversion. |
Implicit(Vector2 to Float2)
Declaration
public static implicit operator Float2(Vector2 value)
Parameters
Vector2
value
The value. |
Returns
Float2
The result of the conversion. |
Inequality(Vector2, Vector2)
Tests for inequality between two objects.
Declaration
public static bool operator !=(Vector2 left, Vector2 right)
Parameters
Vector2
left
The first value to compare. |
Vector2
right
The second value to compare. |
Returns
System.Boolean
|
Modulus(Vector2, Vector2)
Remainder of value divided by scale.
Declaration
public static Vector2 operator %(Vector2 value, Vector2 scale)
Parameters
Vector2
value
The vector to scale. |
Vector2
scale
The amount by which to scale the vector. |
Returns
Vector2
The remained vector. |
Modulus(Vector2, Single)
Remainder of value divided by scale.
Declaration
public static Vector2 operator %(Vector2 value, float scale)
Parameters
Vector2
value
The vector to scale. |
System.Single
scale
The amount by which to scale the vector. |
Returns
Vector2
The remained vector. |
Modulus(Single, Vector2)
Remainder of value divided by scale.
Declaration
public static Vector2 operator %(float value, Vector2 scale)
Parameters
System.Single
value
The amount by which to scale the vector. |
Vector2
scale
The vector to scale. |
Returns
Vector2
The remained vector. |
Multiply(Float2, Vector2)
Multiplies a vector with another by performing component-wise multiplication.
Declaration
public static Float2 operator *(Float2 left, Vector2 right)
Parameters
Float2
left
The first vector to multiply. |
Vector2
right
The second vector to multiply. |
Returns
Float2
The multiplication of the two vectors. |
Multiply(Vector2, Float2)
Multiplies a vector with another by performing component-wise multiplication.
Declaration
public static Vector2 operator *(Vector2 left, Float2 right)
Parameters
Vector2
left
The first vector to multiply. |
Float2
right
The second vector to multiply. |
Returns
Vector2
The multiplication of the two vectors. |
Multiply(Vector2, Vector2)
Multiplies a vector with another by performing component-wise multiplication equivalent to Multiply(ref Vector2, ref Vector2, out Vector2).
Declaration
public static Vector2 operator *(Vector2 left, Vector2 right)
Parameters
Vector2
left
The first vector to multiply. |
Vector2
right
The second vector to multiply. |
Returns
Vector2
The multiplication of the two vectors. |
Multiply(Vector2, Single)
Scales a vector by the given value.
Declaration
public static Vector2 operator *(Vector2 value, float scale)
Parameters
Vector2
value
The vector to scale. |
System.Single
scale
The amount by which to scale the vector. |
Returns
Vector2
The scaled vector. |
Multiply(Single, Vector2)
Scales a vector by the given value.
Declaration
public static Vector2 operator *(float scale, Vector2 value)
Parameters
System.Single
scale
The amount by which to scale the vector. |
Vector2
value
The vector to scale. |
Returns
Vector2
The scaled vector. |
Subtraction(Float2, Vector2)
Subtracts a vector from another by performing component-wise subtraction.
Declaration
public static Float2 operator -(Float2 left, Vector2 right)
Parameters
Float2
left
The first vector to add. |
Vector2
right
The second vector to add. |
Returns
Float2
The sum of the two vectors. |
Subtraction(Vector2, Float2)
Subtracts a vector from another by performing component-wise subtraction.
Declaration
public static Vector2 operator -(Vector2 left, Float2 right)
Parameters
Vector2
left
The first vector to add. |
Float2
right
The second vector to add. |
Returns
Vector2
The sum of the two vectors. |
Subtraction(Vector2, Vector2)
Subtracts two vectors.
Declaration
public static Vector2 operator -(Vector2 left, Vector2 right)
Parameters
Vector2
left
The first vector to subtract. |
Vector2
right
The second vector to subtract. |
Returns
Vector2
The difference of the two vectors. |
Subtraction(Vector2, Single)
Performs a component-wise subtraction.
Declaration
public static Vector2 operator -(Vector2 value, float scalar)
Parameters
Vector2
value
The input vector. |
System.Single
scalar
The scalar value to be subtracted from elements |
Returns
Vector2
The vector with subtracted scalar from each element. |
Subtraction(Single, Vector2)
Performs a component-wise subtraction.
Declaration
public static Vector2 operator -(float scalar, Vector2 value)
Parameters
System.Single
scalar
The scalar value to be subtracted from elements |
Vector2
value
The input vector. |
Returns
Vector2
The vector with subtracted scalar from each element. |
UnaryNegation(Vector2)
Reverses the direction of a given vector.
Declaration
public static Vector2 operator -(Vector2 value)
Parameters
Vector2
value
The vector to negate. |
Returns
Vector2
A vector facing in the opposite direction. |
UnaryPlus(Vector2)
Assert a vector (return it unchanged).
Declaration
public static Vector2 operator +(Vector2 value)
Parameters
Vector2
value
The vector to assert (unchanged). |
Returns
Vector2
The asserted (unchanged) vector. |