Struct Vector2d
Represents a 2D vector using two double-precision floating-point numbers.
Implements
Inherited Members
Namespace: OpenTK
Assembly: OpenTK.dll
Syntax
[Serializable]
public struct Vector2d : IEquatable<Vector2d>
Constructors
Vector2d(Double)
Constructs a new instance.
Declaration
public Vector2d(double value)
Parameters
Type | Name | Description |
---|---|---|
Double | value | The value that will initialize this instance. |
Vector2d(Double, Double)
Constructs left vector with the given coordinates.
Declaration
public Vector2d(double x, double y)
Parameters
Type | Name | Description |
---|---|---|
Double | x | The X coordinate. |
Double | y | The Y coordinate. |
Fields
One
Defines an instance with all components set to 1.
Declaration
public static readonly Vector2d One
Field Value
Type | Description |
---|---|
Vector2d |
SizeInBytes
Defines the size of the Vector2d struct in bytes.
Declaration
public static readonly int SizeInBytes
Field Value
Type | Description |
---|---|
Int32 |
UnitX
Defines a unit-length Vector2d that points towards the X-axis.
Declaration
public static readonly Vector2d UnitX
Field Value
Type | Description |
---|---|
Vector2d |
UnitY
Defines a unit-length Vector2d that points towards the Y-axis.
Declaration
public static readonly Vector2d UnitY
Field Value
Type | Description |
---|---|
Vector2d |
X
The X coordinate of this instance.
Declaration
public double X
Field Value
Type | Description |
---|---|
Double |
Y
The Y coordinate of this instance.
Declaration
public double Y
Field Value
Type | Description |
---|---|
Double |
Zero
Defines a zero-length Vector2d.
Declaration
public static readonly Vector2d Zero
Field Value
Type | Description |
---|---|
Vector2d |
Properties
Item[Int32]
Gets or sets the value at the index of the Vector.
Declaration
public double this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | index |
Property Value
Type | Description |
---|---|
Double |
Length
Gets the length (magnitude) of the vector.
Declaration
public readonly double Length { get; }
Property Value
Type | Description |
---|---|
Double |
See Also
LengthSquared
Gets the square of the vector length (magnitude).
Declaration
public readonly double LengthSquared { get; }
Property Value
Type | Description |
---|---|
Double |
Remarks
This property avoids the costly square root operation required by the Length property. This makes it more suitable for comparisons.
PerpendicularLeft
Gets the perpendicular vector on the left side of this vector.
Declaration
public readonly Vector2d PerpendicularLeft { get; }
Property Value
Type | Description |
---|---|
Vector2d |
PerpendicularRight
Gets the perpendicular vector on the right side of this vector.
Declaration
public readonly Vector2d PerpendicularRight { get; }
Property Value
Type | Description |
---|---|
Vector2d |
Yx
Gets or sets an OpenTK.Vector2d with the Y and X components of this instance.
Declaration
public Vector2d Yx { get; set; }
Property Value
Type | Description |
---|---|
Vector2d |
Methods
Add(Vector2d, Vector2d)
Adds two vectors.
Declaration
public static Vector2d Add(Vector2d a, Vector2d b)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | a | Left operand. |
Vector2d | b | Right operand. |
Returns
Type | Description |
---|---|
Vector2d | Result of operation. |
Add(ref Vector2d, ref Vector2d, out Vector2d)
Adds two vectors.
Declaration
public static void Add(ref Vector2d a, ref Vector2d b, out Vector2d result)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | a | Left operand. |
Vector2d | b | Right operand. |
Vector2d | result | Result of operation. |
BaryCentric(Vector2d, Vector2d, Vector2d, Double, Double)
Interpolate 3 Vectors using Barycentric coordinates
Declaration
public static Vector2d BaryCentric(Vector2d a, Vector2d b, Vector2d c, double u, double v)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | a | First input Vector |
Vector2d | b | Second input Vector |
Vector2d | c | Third input Vector |
Double | u | First Barycentric Coordinate |
Double | v | Second Barycentric Coordinate |
Returns
Type | Description |
---|---|
Vector2d | 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 |
BaryCentric(ref Vector2d, ref Vector2d, ref Vector2d, Double, Double, out Vector2d)
Interpolate 3 Vectors using Barycentric coordinates
Declaration
public static void BaryCentric(ref Vector2d a, ref Vector2d b, ref Vector2d c, double u, double v, out Vector2d result)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | a | First input Vector. |
Vector2d | b | Second input Vector. |
Vector2d | c | Third input Vector. |
Double | u | First Barycentric Coordinate. |
Double | v | Second Barycentric Coordinate. |
Vector2d | 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 |
Clamp(Vector2d, Vector2d, Vector2d)
Clamp a vector to the given minimum and maximum vectors
Declaration
public static Vector2d Clamp(Vector2d vec, Vector2d min, Vector2d max)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vec | Input vector |
Vector2d | min | Minimum vector |
Vector2d | max | Maximum vector |
Returns
Type | Description |
---|---|
Vector2d | The clamped vector |
Clamp(ref Vector2d, ref Vector2d, ref Vector2d, out Vector2d)
Clamp a vector to the given minimum and maximum vectors
Declaration
public static void Clamp(ref Vector2d vec, ref Vector2d min, ref Vector2d max, out Vector2d result)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vec | Input vector |
Vector2d | min | Minimum vector |
Vector2d | max | Maximum vector |
Vector2d | result | The clamped vector |
ComponentMax(Vector2d, Vector2d)
Returns a vector created from the largest of the corresponding components of the given vectors.
Declaration
public static Vector2d ComponentMax(Vector2d a, Vector2d b)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | a | First operand |
Vector2d | b | Second operand |
Returns
Type | Description |
---|---|
Vector2d | The component-wise maximum |
ComponentMax(ref Vector2d, ref Vector2d, out Vector2d)
Returns a vector created from the largest of the corresponding components of the given vectors.
Declaration
public static void ComponentMax(ref Vector2d a, ref Vector2d b, out Vector2d result)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | a | First operand |
Vector2d | b | Second operand |
Vector2d | result | The component-wise maximum |
ComponentMin(Vector2d, Vector2d)
Returns a vector created from the smallest of the corresponding components of the given vectors.
Declaration
public static Vector2d ComponentMin(Vector2d a, Vector2d b)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | a | First operand |
Vector2d | b | Second operand |
Returns
Type | Description |
---|---|
Vector2d | The component-wise minimum |
ComponentMin(ref Vector2d, ref Vector2d, out Vector2d)
Returns a vector created from the smallest of the corresponding components of the given vectors.
Declaration
public static void ComponentMin(ref Vector2d a, ref Vector2d b, out Vector2d result)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | a | First operand |
Vector2d | b | Second operand |
Vector2d | result | The component-wise minimum |
Distance(Vector2d, Vector2d)
Compute the euclidean distance between two vectors.
Declaration
public static double Distance(Vector2d vec1, Vector2d vec2)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vec1 | The first vector |
Vector2d | vec2 | The second vector |
Returns
Type | Description |
---|---|
Double | The distance |
Distance(ref Vector2d, ref Vector2d, out Double)
Compute the euclidean distance between two vectors.
Declaration
public static void Distance(ref Vector2d vec1, ref Vector2d vec2, out double result)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vec1 | The first vector |
Vector2d | vec2 | The second vector |
Double | result | The distance |
DistanceSquared(Vector2d, Vector2d)
Compute the squared euclidean distance between two vectors.
Declaration
public static double DistanceSquared(Vector2d vec1, Vector2d vec2)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vec1 | The first vector |
Vector2d | vec2 | The second vector |
Returns
Type | Description |
---|---|
Double | The squared distance |
DistanceSquared(ref Vector2d, ref Vector2d, out Double)
Compute the squared euclidean distance between two vectors.
Declaration
public static void DistanceSquared(ref Vector2d vec1, ref Vector2d vec2, out double result)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vec1 | The first vector |
Vector2d | vec2 | The second vector |
Double | result | The squared distance |
Divide(Vector2d, Vector2d)
Divides a vector by the components of a vector (scale).
Declaration
public static Vector2d Divide(Vector2d vector, Vector2d scale)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vector | Left operand. |
Vector2d | scale | Right operand. |
Returns
Type | Description |
---|---|
Vector2d | Result of the operation. |
Divide(Vector2d, Double)
Divides a vector by a scalar.
Declaration
public static Vector2d Divide(Vector2d vector, double scale)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vector | Left operand. |
Double | scale | Right operand. |
Returns
Type | Description |
---|---|
Vector2d | Result of the operation. |
Divide(ref Vector2d, ref Vector2d, out Vector2d)
Divide a vector by the components of a vector (scale).
Declaration
public static void Divide(ref Vector2d vector, ref Vector2d scale, out Vector2d result)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vector | Left operand. |
Vector2d | scale | Right operand. |
Vector2d | result | Result of the operation. |
Divide(ref Vector2d, Double, out Vector2d)
Divides a vector by a scalar.
Declaration
public static void Divide(ref Vector2d vector, double scale, out Vector2d result)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vector | Left operand. |
Double | scale | Right operand. |
Vector2d | result | Result of the operation. |
Dot(Vector2d, Vector2d)
Calculate the dot (scalar) product of two vectors
Declaration
public static double Dot(Vector2d left, Vector2d right)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | left | First operand |
Vector2d | right | Second operand |
Returns
Type | Description |
---|---|
Double | The dot product of the two inputs |
Dot(ref Vector2d, ref Vector2d, out Double)
Calculate the dot (scalar) product of two vectors
Declaration
public static void Dot(ref Vector2d left, ref Vector2d right, out double result)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | left | First operand |
Vector2d | right | Second operand |
Double | result | The dot product of the two inputs |
Equals(Vector2d)
Indicates whether the current vector is equal to another vector.
Declaration
public bool Equals(Vector2d other)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | other | A vector to compare with this vector. |
Returns
Type | Description |
---|---|
Boolean | true if the current vector is equal to the vector parameter; otherwise, false. |
Equals(Object)
Indicates whether this instance and a specified object are equal.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj | The object to compare to. |
Returns
Type | Description |
---|---|
Boolean | True if the instances are equal; false otherwise. |
Overrides
GetHashCode()
Returns the hashcode for this instance.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | A System.Int32 containing the unique hashcode for this instance. |
Overrides
Lerp(Vector2d, Vector2d, Double)
Returns a new Vector that is the linear blend of the 2 given Vectors
Declaration
public static Vector2d Lerp(Vector2d a, Vector2d b, double blend)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | a | First input vector |
Vector2d | b | Second input vector |
Double | blend | The blend factor. a when blend=0, b when blend=1. |
Returns
Type | Description |
---|---|
Vector2d | a when blend=0, b when blend=1, and a linear combination otherwise |
Lerp(ref Vector2d, ref Vector2d, Double, out Vector2d)
Returns a new Vector that is the linear blend of the 2 given Vectors
Declaration
public static void Lerp(ref Vector2d a, ref Vector2d b, double blend, out Vector2d result)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | a | First input vector |
Vector2d | b | Second input vector |
Double | blend | The blend factor. a when blend=0, b when blend=1. |
Vector2d | result | a when blend=0, b when blend=1, and a linear combination otherwise |
MagnitudeMax(Vector2d, Vector2d)
Returns the Vector2d with the minimum magnitude. If the magnitudes are equal, the first vector is selected.
Declaration
public static Vector2d MagnitudeMax(Vector2d left, Vector2d right)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | left | Left operand |
Vector2d | right | Right operand |
Returns
Type | Description |
---|---|
Vector2d | The minimum Vector2d |
MagnitudeMax(ref Vector2d, ref Vector2d, out Vector2d)
Returns the Vector2d with the maximum magnitude. If the magnitudes are equal, the first vector is selected.
Declaration
public static void MagnitudeMax(ref Vector2d left, ref Vector2d right, out Vector2d result)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | left | Left operand |
Vector2d | right | Right operand |
Vector2d | result | The magnitude-wise maximum |
MagnitudeMin(Vector2d, Vector2d)
Returns the Vector2d with the minimum magnitude. If the magnitudes are equal, the second vector is selected.
Declaration
public static Vector2d MagnitudeMin(Vector2d left, Vector2d right)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | left | Left operand |
Vector2d | right | Right operand |
Returns
Type | Description |
---|---|
Vector2d | The minimum Vector2d |
MagnitudeMin(ref Vector2d, ref Vector2d, out Vector2d)
Returns the Vector2d with the minimum magnitude. If the magnitudes are equal, the second vector is selected.
Declaration
public static void MagnitudeMin(ref Vector2d left, ref Vector2d right, out Vector2d result)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | left | Left operand |
Vector2d | right | Right operand |
Vector2d | result | The magnitude-wise minimum |
Max(Vector2d, Vector2d)
Calculate the component-wise maximum of two vectors
Declaration
[Obsolete("Use ComponentMax() instead.")]
public static Vector2d Max(Vector2d a, Vector2d b)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | a | First operand |
Vector2d | b | Second operand |
Returns
Type | Description |
---|---|
Vector2d | The component-wise maximum |
Max(ref Vector2d, ref Vector2d, out Vector2d)
Calculate the component-wise maximum of two vectors
Declaration
[Obsolete("Use ComponentMax() instead.")]
public static void Max(ref Vector2d a, ref Vector2d b, out Vector2d result)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | a | First operand |
Vector2d | b | Second operand |
Vector2d | result | The component-wise maximum |
Min(Vector2d, Vector2d)
Calculate the component-wise minimum of two vectors
Declaration
[Obsolete("Use ComponentMin() instead.")]
public static Vector2d Min(Vector2d a, Vector2d b)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | a | First operand |
Vector2d | b | Second operand |
Returns
Type | Description |
---|---|
Vector2d | The component-wise minimum |
Min(ref Vector2d, ref Vector2d, out Vector2d)
Calculate the component-wise minimum of two vectors
Declaration
[Obsolete("Use ComponentMin() instead.")]
public static void Min(ref Vector2d a, ref Vector2d b, out Vector2d result)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | a | First operand |
Vector2d | b | Second operand |
Vector2d | result | The component-wise minimum |
Multiply(Vector2d, Vector2d)
Multiplies a vector by the components a vector (scale).
Declaration
public static Vector2d Multiply(Vector2d vector, Vector2d scale)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vector | Left operand. |
Vector2d | scale | Right operand. |
Returns
Type | Description |
---|---|
Vector2d | Result of the operation. |
Multiply(Vector2d, Double)
Multiplies a vector by a scalar.
Declaration
public static Vector2d Multiply(Vector2d vector, double scale)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vector | Left operand. |
Double | scale | Right operand. |
Returns
Type | Description |
---|---|
Vector2d | Result of the operation. |
Multiply(ref Vector2d, ref Vector2d, out Vector2d)
Multiplies a vector by the components of a vector (scale).
Declaration
public static void Multiply(ref Vector2d vector, ref Vector2d scale, out Vector2d result)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vector | Left operand. |
Vector2d | scale | Right operand. |
Vector2d | result | Result of the operation. |
Multiply(ref Vector2d, Double, out Vector2d)
Multiplies a vector by a scalar.
Declaration
public static void Multiply(ref Vector2d vector, double scale, out Vector2d result)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vector | Left operand. |
Double | scale | Right operand. |
Vector2d | result | Result of the operation. |
Normalize()
Scales the Vector2 to unit length.
Declaration
public void Normalize()
Normalize(Vector2d)
Scale a vector to unit length
Declaration
public static Vector2d Normalize(Vector2d vec)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vec | The input vector |
Returns
Type | Description |
---|---|
Vector2d | The normalized vector |
Normalize(ref Vector2d, out Vector2d)
Scale a vector to unit length
Declaration
public static void Normalize(ref Vector2d vec, out Vector2d result)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vec | The input vector |
Vector2d | result | The normalized vector |
Normalized()
Returns a copy of the Vector2d scaled to unit length.
Declaration
public Vector2d Normalized()
Returns
Type | Description |
---|---|
Vector2d |
NormalizeFast(Vector2d)
Scale a vector to approximately unit length
Declaration
public static Vector2d NormalizeFast(Vector2d vec)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vec | The input vector |
Returns
Type | Description |
---|---|
Vector2d | The normalized vector |
NormalizeFast(ref Vector2d, out Vector2d)
Scale a vector to approximately unit length
Declaration
public static void NormalizeFast(ref Vector2d vec, out Vector2d result)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vec | The input vector |
Vector2d | result | The normalized vector |
Subtract(Vector2d, Vector2d)
Subtract one Vector from another
Declaration
public static Vector2d Subtract(Vector2d a, Vector2d b)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | a | First operand |
Vector2d | b | Second operand |
Returns
Type | Description |
---|---|
Vector2d | Result of subtraction |
Subtract(ref Vector2d, ref Vector2d, out Vector2d)
Subtract one Vector from another
Declaration
public static void Subtract(ref Vector2d a, ref Vector2d b, out Vector2d result)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | a | First operand |
Vector2d | b | Second operand |
Vector2d | result | Result of subtraction |
ToString()
Returns a System.String that represents the current instance.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String |
Overrides
Transform(Vector2d, Quaterniond)
Transforms a vector by a quaternion rotation.
Declaration
public static Vector2d Transform(Vector2d vec, Quaterniond quat)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vec | The vector to transform. |
Quaterniond | quat | The quaternion to rotate the vector by. |
Returns
Type | Description |
---|---|
Vector2d | The result of the operation. |
Transform(ref Vector2d, ref Quaterniond, out Vector2d)
Transforms a vector by a quaternion rotation.
Declaration
public static void Transform(ref Vector2d vec, ref Quaterniond quat, out Vector2d result)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vec | The vector to transform. |
Quaterniond | quat | The quaternion to rotate the vector by. |
Vector2d | result | The result of the operation. |
Operators
Addition(Vector2d, Vector2d)
Adds two instances.
Declaration
public static Vector2d operator +(Vector2d left, Vector2d right)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | left | The left instance. |
Vector2d | right | The right instance. |
Returns
Type | Description |
---|---|
Vector2d | The result of the operation. |
Division(Vector2d, Double)
Divides an instance by a scalar.
Declaration
public static Vector2d operator /(Vector2d vec, double f)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vec | The instance. |
Double | f | The scalar. |
Returns
Type | Description |
---|---|
Vector2d | The result of the operation. |
Equality(Vector2d, Vector2d)
Compares two instances for equality.
Declaration
public static bool operator ==(Vector2d left, Vector2d right)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | left | The left instance. |
Vector2d | right | The right instance. |
Returns
Type | Description |
---|---|
Boolean | True, if both instances are equal; false otherwise. |
Explicit(Vector2 to Vector2d)
Converts OpenTK.Vector2 to OpenTK.Vector2d.
Declaration
public static explicit operator Vector2d(Vector2 v2)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | v2 | The Vector2 to convert. |
Returns
Type | Description |
---|---|
Vector2d | The resulting Vector2d. |
Explicit(Vector2d to Vector2)
Converts OpenTK.Vector2d to OpenTK.Vector2.
Declaration
public static explicit operator Vector2(Vector2d v2d)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | v2d | The Vector2d to convert. |
Returns
Type | Description |
---|---|
Vector2 | The resulting Vector2. |
Inequality(Vector2d, Vector2d)
Compares two instances for ienquality.
Declaration
public static bool operator !=(Vector2d left, Vector2d right)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | left | The left instance. |
Vector2d | right | The right instance. |
Returns
Type | Description |
---|---|
Boolean | True, if the instances are not equal; false otherwise. |
Multiply(Vector2d, Vector2d)
Component-wise multiplication between the specified instance by a scale vector.
Declaration
public static Vector2d operator *(Vector2d vec, Vector2d scale)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vec | Right operand. |
Vector2d | scale | Left operand. |
Returns
Type | Description |
---|---|
Vector2d | Result of multiplication. |
Multiply(Vector2d, Double)
Multiplies an instance by a scalar.
Declaration
public static Vector2d operator *(Vector2d vec, double f)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vec | The instance. |
Double | f | The scalar. |
Returns
Type | Description |
---|---|
Vector2d | The result of the operation. |
Multiply(Double, Vector2d)
Multiply an instance by a scalar.
Declaration
public static Vector2d operator *(double f, Vector2d vec)
Parameters
Type | Name | Description |
---|---|---|
Double | f | The scalar. |
Vector2d | vec | The instance. |
Returns
Type | Description |
---|---|
Vector2d | The result of the operation. |
Subtraction(Vector2d, Vector2d)
Subtracts two instances.
Declaration
public static Vector2d operator -(Vector2d left, Vector2d right)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | left | The left instance. |
Vector2d | right | The right instance. |
Returns
Type | Description |
---|---|
Vector2d | The result of the operation. |
UnaryNegation(Vector2d)
Negates an instance.
Declaration
public static Vector2d operator -(Vector2d vec)
Parameters
Type | Name | Description |
---|---|---|
Vector2d | vec | The instance. |
Returns
Type | Description |
---|---|
Vector2d | The result of the operation. |