Vector2
Represents a 2D vector using two double-precision floating-point numbers.
Implements: IEquatable<Vector2>
Constructors
public Vector2(double x, double y)
vector2 = Vector2(x, y)
Constructs left vector with the given coordinates.
- x
- The X coordinate.
- y
- The Y coordinate.
Properties
public double Length { get; }
value = vector2.Length
Gets the length (magnitude) of the vector.
public double LengthSquared { get; }
value = vector2.LengthSquared
Gets the square of the vector length (magnitude).
public Vector2 PerpendicularLeft { get; }
value = vector2.PerpendicularLeft
Gets the perpendicular vector on the left side of this vector.
public Vector2 PerpendicularRight { get; }
value = vector2.PerpendicularRight
Gets the perpendicular vector on the right side of this vector.
Methods
public static void Add(Vector2 a, Vector2 b, Vector2 result)
Vector2.Add(a, b, result)
Adds two vectors.
- a
- Left operand.
- b
- Right operand.
- result
- Result of operation.
public static Vector2 Add(Vector2 a, Vector2 b)
result = Vector2.Add(a, b)
Adds two vectors.
- a
- Left operand.
- b
- Right operand.
Returns: Result of operation.
public static void BaryCentric(Vector2 a, Vector2 b, Vector2 c, double u, double v, Vector2 result)
Vector2.BaryCentric(a, b, c, u, v, result)
Interpolate 3 Vectors using Barycentric coordinates
- a
- First input Vector.
- b
- Second input Vector.
- c
- Third input Vector.
- u
- First Barycentric Coordinate.
- v
- Second Barycentric Coordinate.
- result
- Output Vector. a when u=v=0, b when u=1,v=0, c when u=0,v=1, and a linear combination of a,b,c otherwise
public static Vector2 BaryCentric(Vector2 a, Vector2 b, Vector2 c, double u, double v)
result = Vector2.BaryCentric(a, b, c, u, v)
Interpolate 3 Vectors using Barycentric coordinates
- a
- First input Vector
- b
- Second input Vector
- c
- Third input Vector
- u
- First Barycentric Coordinate
- v
- Second Barycentric Coordinate
Returns: a when u=v=0, b when u=1,v=0, c when u=0,v=1, and a linear combination of a,b,c otherwise
public static void Clamp(Vector2 vec, Vector2 min, Vector2 max, Vector2 result)
Vector2.Clamp(vec, min, max, result)
Clamp a vector to the given minimum and maximum vectors
- vec
- Input vector
- min
- Minimum vector
- max
- Maximum vector
- result
- The clamped vector
public static Vector2 Clamp(Vector2 vec, Vector2 min, Vector2 max)
result = Vector2.Clamp(vec, min, max)
Clamp a vector to the given minimum and maximum vectors
- vec
- Input vector
- min
- Minimum vector
- max
- Maximum vector
Returns: The clamped vector
public static void ComponentMax(Vector2 a, Vector2 b, Vector2 result)
Vector2.ComponentMax(a, b, result)
Calculate the component-wise maximum of two vectors
- a
- First operand
- b
- Second operand
- result
- The component-wise maximum
public static Vector2 ComponentMax(Vector2 a, Vector2 b)
result = Vector2.ComponentMax(a, b)
Calculate the component-wise maximum of two vectors
- a
- First operand
- b
- Second operand
Returns: The component-wise maximum
public static void ComponentMin(Vector2 a, Vector2 b, Vector2 result)
Vector2.ComponentMin(a, b, result)
Calculate the component-wise minimum of two vectors
- a
- First operand
- b
- Second operand
- result
- The component-wise minimum
public static Vector2 ComponentMin(Vector2 a, Vector2 b)
result = Vector2.ComponentMin(a, b)
Calculate the component-wise minimum of two vectors
- a
- First operand
- b
- Second operand
Returns: The component-wise minimum
public static double Cross(Vector2 left, Vector2 right)
result = Vector2.Cross(left, right)
Calculate the cross product of two vectors
- left
- First operand
- right
- Second operand
Returns: The cross product of the two inputs
public static Vector2 Divide(Vector2 vector, Vector2 scale)
result = Vector2.Divide(vector, scale)
Divides a vector by the components of a vector (scale).
- vector
- Left operand.
- scale
- Right operand.
Returns: Result of the operation.
public static void Divide(Vector2 vector, Vector2 scale, Vector2 result)
Vector2.Divide(vector, scale, result)
Divide a vector by the components of a vector (scale).
- vector
- Left operand.
- scale
- Right operand.
- result
- Result of the operation.
public static Vector2 Divide(Vector2 vector, double scale)
result = Vector2.Divide(vector, scale)
Divides a vector by a scalar.
- vector
- Left operand.
- scale
- Right operand.
Returns: Result of the operation.
public static void Divide(Vector2 vector, double scale, Vector2 result)
Vector2.Divide(vector, scale, result)
Divides a vector by a scalar.
- vector
- Left operand.
- scale
- Right operand.
- result
- Result of the operation.
public static double Dot(Vector2 left, Vector2 right)
result = Vector2.Dot(left, right)
Calculate the dot (scalar) product of two vectors
- left
- First operand
- right
- Second operand
Returns: The dot product of the two inputs
public static void Dot(Vector2 left, Vector2 right, double result)
Vector2.Dot(left, right, result)
Calculate the dot (scalar) product of two vectors
- left
- First operand
- right
- Second operand
- result
- The dot product of the two inputs
public override bool Equals(object obj)
result = vector2.Equals(obj)
Indicates whether this instance and a specified object are equal.
- obj
- The object to compare to.
Returns: True if the instances are equal; false otherwise.
public bool Equals(Vector2 other)
result = vector2.Equals(other)
Indicates whether the current vector is equal to another vector.
- other
- A vector to compare with this vector.
Returns: true if the current vector is equal to the vector parameter; otherwise, false.
public bool Equals(Vector2 other, double errorRange)
result = vector2.Equals(other, errorRange)
Indicates whether the current vector is equal to another vector.
- other
- A vector to compare with this vector.
- errorRange
Returns: true if the current vector is equal to the vector parameter; otherwise, false.
public override int GetHashCode()
result = vector2.GetHashCode()
Returns the hashcode for this instance.
Returns: A System.Int32 containing the unique hashcode for this instance.
public Vector2 GetNormal()
result = vector2.GetNormal()
Returns a normalized Vector of this.
public static Vector2 Lerp(Vector2 a, Vector2 b, double blend)
result = Vector2.Lerp(a, b, blend)
Returns a new Vector that is the linear blend of the 2 given Vectors
- a
- First input vector
- b
- Second input vector
- blend
- The blend factor. a when blend=0, b when blend=1.
Returns: a when blend=0, b when blend=1, and a linear combination otherwise
public static void Lerp(Vector2 a, Vector2 b, double blend, Vector2 result)
Vector2.Lerp(a, b, blend, result)
Returns a new Vector that is the linear blend of the 2 given Vectors
- a
- First input vector
- b
- Second input vector
- blend
- The blend factor. a when blend=0, b when blend=1.
- result
- a when blend=0, b when blend=1, and a linear combination otherwise
public static Vector2 Max(Vector2 a, Vector2 b)
result = Vector2.Max(a, b)
Calculate the component-wise maximum of two vectors
- a
- First operand
- b
- Second operand
Returns: The component-wise maximum
public static void Max(Vector2 a, Vector2 b, Vector2 result)
Vector2.Max(a, b, result)
Calculate the component-wise maximum of two vectors
- a
- First operand
- b
- Second operand
- result
- The component-wise maximum
public static Vector2 Min(Vector2 a, Vector2 b)
result = Vector2.Min(a, b)
Calculate the component-wise minimum of two vectors
- a
- First operand
- b
- Second operand
Returns: The component-wise minimum
public static void Min(Vector2 a, Vector2 b, Vector2 result)
Vector2.Min(a, b, result)
Calculate the component-wise minimum of two vectors
- a
- First operand
- b
- Second operand
- result
- The component-wise minimum
public static void Multiply(Vector2 vector, double scale, Vector2 result)
Vector2.Multiply(vector, scale, result)
Multiplies a vector by a scalar.
- vector
- Left operand.
- scale
- Right operand.
- result
- Result of the operation.
public static Vector2 Multiply(Vector2 vector, Vector2 scale)
result = Vector2.Multiply(vector, scale)
Multiplies a vector by the components a vector (scale).
- vector
- Left operand.
- scale
- Right operand.
Returns: Result of the operation.
public static void Multiply(Vector2 vector, Vector2 scale, Vector2 result)
Vector2.Multiply(vector, scale, result)
Multiplies a vector by the components of a vector (scale).
- vector
- Left operand.
- scale
- Right operand.
- result
- Result of the operation.
public static Vector2 Multiply(Vector2 vector, double scale)
result = Vector2.Multiply(vector, scale)
Multiplies a vector by a scalar.
- vector
- Left operand.
- scale
- Right operand.
Returns: Result of the operation.
public static Vector2 Normalize(Vector2 vec)
result = Vector2.Normalize(vec)
Scale a vector to unit length
- vec
- The input vector
Returns: The normalized vector
public static void Normalize(Vector2 vec, Vector2 result)
Vector2.Normalize(vec, result)
Scale a vector to unit length
- vec
- The input vector
- result
- The normalized vector
public static Vector2 NormalizeFast(Vector2 vec)
result = Vector2.NormalizeFast(vec)
Scale a vector to approximately unit length
- vec
- The input vector
Returns: The normalized vector
public static void NormalizeFast(Vector2 vec, Vector2 result)
Vector2.NormalizeFast(vec, result)
Scale a vector to approximately unit length
- vec
- The input vector
- result
- The normalized vector
public static Vector2 op_Addition(Vector2 left, Vector2 right)
result = Vector2.op_Addition(left, right)
Adds two instances.
- left
- The left instance.
- right
- The right instance.
Returns: The result of the operation.
public static Vector2 op_Division(double f, Vector2 vec)
result = Vector2.op_Division(f, vec)
Divides a scaler by an instance components wise.
- vec
- The scalar.
- f
- The instance.
Returns: The result of the operation.
public static Vector2 op_Division(Vector2 vec, double f)
result = Vector2.op_Division(vec, f)
Divides an instance by a scalar.
- vec
- The instance.
- f
- The scalar.
Returns: The result of the operation.
public static bool op_Equality(Vector2 left, Vector2 right)
result = Vector2.op_Equality(left, right)
Compares two instances for equality.
- left
- The left instance.
- right
- The right instance.
Returns: True, if both instances are equal; false otherwise.
public static bool op_Inequality(Vector2 left, Vector2 right)
result = Vector2.op_Inequality(left, right)
Compares two instances for ienquality.
- left
- The left instance.
- right
- The right instance.
Returns: True, if the instances are not equal; false otherwise.
public static Vector2 op_Multiply(double f, Vector2 vec)
result = Vector2.op_Multiply(f, vec)
Multiply an instance by a scalar.
- f
- The scalar.
- vec
- The instance.
Returns: The result of the operation.
public static Vector2 op_Multiply(Vector2 vec, double f)
result = Vector2.op_Multiply(vec, f)
Multiplies an instance by a scalar.
- vec
- The instance.
- f
- The scalar.
Returns: The result of the operation.
public static Vector2 op_Subtraction(Vector2 left, Vector2 right)
result = Vector2.op_Subtraction(left, right)
Subtracts two instances.
- left
- The left instance.
- right
- The right instance.
Returns: The result of the operation.
public static Vector2 op_UnaryNegation(Vector2 vec)
result = Vector2.op_UnaryNegation(vec)
Negates an instance.
- vec
- The instance.
Returns: The result of the operation.
public static void Subtract(Vector2 a, Vector2 b, Vector2 result)
Vector2.Subtract(a, b, result)
Subtract one Vector from another
- a
- First operand
- b
- Second operand
- result
- Result of subtraction
public static Vector2 Subtract(Vector2 a, Vector2 b)
result = Vector2.Subtract(a, b)
Subtract one Vector from another
- a
- First operand
- b
- Second operand
Returns: Result of subtraction
public override string ToString()
result = vector2.ToString()
Returns a System.String that represents the current instance.
public static void Transform(Vector2 vec, Quaternion quat, Vector2 result)
Vector2.Transform(vec, quat, result)
Transforms a vector by a quaternion rotation.
- vec
- The vector to transform.
- quat
- The quaternion to rotate the vector by.
- result
- The result of the operation.
public static Vector2 Transform(Vector2 vec, Quaternion quat)
result = Vector2.Transform(vec, quat)
Transforms a vector by a quaternion rotation.
- vec
- The vector to transform.
- quat
- The quaternion to rotate the vector by.
Returns: The result of the operation.
Fields
public static readonly Vector2 One
value = Vector2.One
Defines an instance with all components set to 1.
public static readonly int SizeInBytes
value = Vector2.SizeInBytes
Defines the size of the Vector2d struct in bytes.
public static Vector2 UnitX
value = Vector2.UnitX
Defines a unit-length Vector2d that points towards the X-axis.
public static Vector2 UnitY
value = Vector2.UnitY
Defines a unit-length Vector2d that points towards the Y-axis.