Show / Hide Table of Contents

Struct Vector2

Represents a 2D vector using two single-precision floating-point numbers.

Implements
IEquatable<Vector2>
IFormattable
Inherited Members
object.Equals(object, object)
object.GetType()
object.ReferenceEquals(object, object)
Namespace: OpenTK.Mathematics
Assembly: OpenTK.Mathematics.dll
Syntax
[Serializable]
public struct Vector2 : IEquatable<Vector2>, IFormattable
Remarks

The Vector2 structure is suitable for interoperation with unmanaged code requiring two consecutive floats.

Constructors

Vector2(float)

Initializes a new instance of the Vector2 struct.

Declaration
public Vector2(float value)
Parameters
Type Name Description
float value

The value that will initialize this instance.

Vector2(float, float)

Initializes a new instance of the Vector2 struct.

Declaration
public Vector2(float x, float y)
Parameters
Type Name Description
float x

The x component of the Vector2.

float y

The y component of the Vector2.

Fields

NegativeInfinity

Defines an instance with all components set to negative infinity.

Declaration
public static readonly Vector2 NegativeInfinity
Field Value
Type Description
Vector2

One

Defines an instance with all components set to 1.

Declaration
public static readonly Vector2 One
Field Value
Type Description
Vector2

PositiveInfinity

Defines an instance with all components set to positive infinity.

Declaration
public static readonly Vector2 PositiveInfinity
Field Value
Type Description
Vector2

SizeInBytes

Defines the size of the Vector2 struct in bytes.

Declaration
public static readonly int SizeInBytes
Field Value
Type Description
int

UnitX

Defines a unit-length Vector2 that points towards the X-axis.

Declaration
public static readonly Vector2 UnitX
Field Value
Type Description
Vector2

UnitY

Defines a unit-length Vector2 that points towards the Y-axis.

Declaration
public static readonly Vector2 UnitY
Field Value
Type Description
Vector2

X

The X component of the Vector2.

Declaration
public float X
Field Value
Type Description
float

Y

The Y component of the Vector2.

Declaration
public float Y
Field Value
Type Description
float

Zero

Defines an instance with all components set to 0.

Declaration
public static readonly Vector2 Zero
Field Value
Type Description
Vector2

Properties

this[int]

Gets or sets the value at the index of the Vector.

Declaration
public float this[int index] { readonly get; set; }
Parameters
Type Name Description
int index

The index of the component from the Vector.

Property Value
Type Description
float
Exceptions
Type Condition
IndexOutOfRangeException

Thrown if the index is less than 0 or greater than 1.

Length

Gets the length (magnitude) of the vector.

Declaration
public readonly float Length { get; }
Property Value
Type Description
float
See Also
LengthSquared

LengthFast

Gets an approximation of the vector length (magnitude).

Declaration
public readonly float LengthFast { get; }
Property Value
Type Description
float
Remarks

This property uses an approximation of the square root function to calculate vector magnitude.

See Also
LengthSquared

LengthSquared

Gets the square of the vector length (magnitude).

Declaration
public readonly float LengthSquared { get; }
Property Value
Type Description
float
Remarks

This property avoids the costly square root operation required by the Length property. This makes it more suitable for comparisons.

See Also
LengthFast

PerpendicularLeft

Gets the perpendicular vector on the left side of this vector.

Declaration
public readonly Vector2 PerpendicularLeft { get; }
Property Value
Type Description
Vector2

PerpendicularRight

Gets the perpendicular vector on the right side of this vector.

Declaration
public readonly Vector2 PerpendicularRight { get; }
Property Value
Type Description
Vector2

ReciprocalLengthFast

Gets an approximation of 1 over the length (magnitude) of the vector.

Declaration
public readonly float ReciprocalLengthFast { get; }
Property Value
Type Description
float

Yx

Gets or sets an OpenTK.Vector2 with the Y and X components of this instance.

Declaration
public Vector2 Yx { readonly get; set; }
Property Value
Type Description
Vector2

Methods

Abs()

Returns a new vector that is the component-wise absolute value of the vector.

Declaration
public readonly Vector2 Abs()
Returns
Type Description
Vector2

The component-wise absolute value vector.

Abs(Vector2)

Take the component-wise absolute value of a vector.

Declaration
public static Vector2 Abs(Vector2 vec)
Parameters
Type Name Description
Vector2 vec

The vector to apply component-wise absolute value to.

Returns
Type Description
Vector2

The component-wise absolute value vector.

Abs(in Vector2, out Vector2)

Take the component-wise absolute value of a vector.

Declaration
public static void Abs(in Vector2 vec, out Vector2 result)
Parameters
Type Name Description
Vector2 vec

The vector to apply component-wise absolute value to.

Vector2 result

The component-wise absolute value vector.

Add(Vector2, Vector2)

Adds two vectors.

Declaration
[Pure]
public static Vector2 Add(Vector2 a, Vector2 b)
Parameters
Type Name Description
Vector2 a

Left operand.

Vector2 b

Right operand.

Returns
Type Description
Vector2

Result of operation.

Add(in Vector2, in Vector2, out Vector2)

Adds two vectors.

Declaration
public static void Add(in Vector2 a, in Vector2 b, out Vector2 result)
Parameters
Type Name Description
Vector2 a

Left operand.

Vector2 b

Right operand.

Vector2 result

Result of operation.

BaryCentric(Vector2, Vector2, Vector2, float, float)

Interpolate 3 Vectors using Barycentric coordinates.

Declaration
[Pure]
public static Vector2 BaryCentric(Vector2 a, Vector2 b, Vector2 c, float u, float v)
Parameters
Type Name Description
Vector2 a

First input Vector.

Vector2 b

Second input Vector.

Vector2 c

Third input Vector.

float u

First Barycentric Coordinate.

float v

Second Barycentric Coordinate.

Returns
Type Description
Vector2

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(in Vector2, in Vector2, in Vector2, float, float, out Vector2)

Interpolate 3 Vectors using Barycentric coordinates.

Declaration
public static void BaryCentric(in Vector2 a, in Vector2 b, in Vector2 c, float u, float v, out Vector2 result)
Parameters
Type Name Description
Vector2 a

First input Vector.

Vector2 b

Second input Vector.

Vector2 c

Third input Vector.

float u

First Barycentric Coordinate.

float v

Second Barycentric Coordinate.

Vector2 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(Vector2, Vector2, Vector2)

Clamp a vector to the given minimum and maximum vectors.

Declaration
[Pure]
public static Vector2 Clamp(Vector2 vec, Vector2 min, Vector2 max)
Parameters
Type Name Description
Vector2 vec

Input vector.

Vector2 min

Minimum vector.

Vector2 max

Maximum vector.

Returns
Type Description
Vector2

The clamped vector.

Clamp(in Vector2, in Vector2, in Vector2, out Vector2)

Clamp a vector to the given minimum and maximum vectors.

Declaration
public static void Clamp(in Vector2 vec, in Vector2 min, in Vector2 max, out Vector2 result)
Parameters
Type Name Description
Vector2 vec

Input vector.

Vector2 min

Minimum vector.

Vector2 max

Maximum vector.

Vector2 result

The clamped vector.

ComponentMax(Vector2, Vector2)

Returns a vector created from the largest of the corresponding components of the given vectors.

Declaration
[Pure]
public static Vector2 ComponentMax(Vector2 a, Vector2 b)
Parameters
Type Name Description
Vector2 a

First operand.

Vector2 b

Second operand.

Returns
Type Description
Vector2

The component-wise maximum.

ComponentMax(in Vector2, in Vector2, out Vector2)

Returns a vector created from the largest of the corresponding components of the given vectors.

Declaration
public static void ComponentMax(in Vector2 a, in Vector2 b, out Vector2 result)
Parameters
Type Name Description
Vector2 a

First operand.

Vector2 b

Second operand.

Vector2 result

The component-wise maximum.

ComponentMin(Vector2, Vector2)

Returns a vector created from the smallest of the corresponding components of the given vectors.

Declaration
[Pure]
public static Vector2 ComponentMin(Vector2 a, Vector2 b)
Parameters
Type Name Description
Vector2 a

First operand.

Vector2 b

Second operand.

Returns
Type Description
Vector2

The component-wise minimum.

ComponentMin(in Vector2, in Vector2, out Vector2)

Returns a vector created from the smallest of the corresponding components of the given vectors.

Declaration
public static void ComponentMin(in Vector2 a, in Vector2 b, out Vector2 result)
Parameters
Type Name Description
Vector2 a

First operand.

Vector2 b

Second operand.

Vector2 result

The component-wise minimum.

Deconstruct(out float, out float)

Deconstructs the vector into it's individual components.

Declaration
[Pure]
public readonly void Deconstruct(out float x, out float y)
Parameters
Type Name Description
float x

The X component of the vector.

float y

The Y component of the vector.

Distance(Vector2, Vector2)

Compute the euclidean distance between two vectors.

Declaration
[Pure]
public static float Distance(Vector2 vec1, Vector2 vec2)
Parameters
Type Name Description
Vector2 vec1

The first vector.

Vector2 vec2

The second vector.

Returns
Type Description
float

The distance.

Distance(in Vector2, in Vector2, out float)

Compute the euclidean distance between two vectors.

Declaration
public static void Distance(in Vector2 vec1, in Vector2 vec2, out float result)
Parameters
Type Name Description
Vector2 vec1

The first vector.

Vector2 vec2

The second vector.

float result

The distance.

DistanceSquared(Vector2, Vector2)

Compute the squared euclidean distance between two vectors.

Declaration
[Pure]
public static float DistanceSquared(Vector2 vec1, Vector2 vec2)
Parameters
Type Name Description
Vector2 vec1

The first vector.

Vector2 vec2

The second vector.

Returns
Type Description
float

The squared distance.

DistanceSquared(in Vector2, in Vector2, out float)

Compute the squared euclidean distance between two vectors.

Declaration
public static void DistanceSquared(in Vector2 vec1, in Vector2 vec2, out float result)
Parameters
Type Name Description
Vector2 vec1

The first vector.

Vector2 vec2

The second vector.

float result

The squared distance.

Divide(Vector2, Vector2)

Divides a vector by the components of a vector (scale).

Declaration
[Pure]
public static Vector2 Divide(Vector2 vector, Vector2 scale)
Parameters
Type Name Description
Vector2 vector

Left operand.

Vector2 scale

Right operand.

Returns
Type Description
Vector2

Result of the operation.

Divide(Vector2, float)

Divides a vector by a scalar.

Declaration
[Pure]
public static Vector2 Divide(Vector2 vector, float scale)
Parameters
Type Name Description
Vector2 vector

Left operand.

float scale

Right operand.

Returns
Type Description
Vector2

Result of the operation.

Divide(in Vector2, in Vector2, out Vector2)

Divide a vector by the components of a vector (scale).

Declaration
public static void Divide(in Vector2 vector, in Vector2 scale, out Vector2 result)
Parameters
Type Name Description
Vector2 vector

Left operand.

Vector2 scale

Right operand.

Vector2 result

Result of the operation.

Divide(in Vector2, float, out Vector2)

Divides a vector by a scalar.

Declaration
public static void Divide(in Vector2 vector, float scale, out Vector2 result)
Parameters
Type Name Description
Vector2 vector

Left operand.

float scale

Right operand.

Vector2 result

Result of the operation.

Dot(Vector2, Vector2)

Calculate the dot (scalar) product of two vectors.

Declaration
[Pure]
public static float Dot(Vector2 left, Vector2 right)
Parameters
Type Name Description
Vector2 left

First operand.

Vector2 right

Second operand.

Returns
Type Description
float

The dot product of the two inputs.

Dot(in Vector2, in Vector2, out float)

Calculate the dot (scalar) product of two vectors.

Declaration
public static void Dot(in Vector2 left, in Vector2 right, out float result)
Parameters
Type Name Description
Vector2 left

First operand.

Vector2 right

Second operand.

float result

The dot product of the two inputs.

Elerp(Vector2, Vector2, float)

Returns a new vector that is the exponential interpolation of the two vectors. Equivalent to a * pow(b/a, t).

Declaration
public static Vector2 Elerp(Vector2 a, Vector2 b, float t)
Parameters
Type Name Description
Vector2 a

The starting value. Must be non-negative.

Vector2 b

The end value. Must be non-negative.

float t

The blend factor.

Returns
Type Description
Vector2

The exponential interpolation between a and b.

See Also
Elerp(float, float, float)

Elerp(in Vector2, in Vector2, float, out Vector2)

Returns a new vector that is the exponential interpolation of the two vectors. Equivalent to a * pow(b/a, t).

Declaration
public static void Elerp(in Vector2 a, in Vector2 b, float t, out Vector2 result)
Parameters
Type Name Description
Vector2 a

The starting value. Must be non-negative.

Vector2 b

The end value. Must be non-negative.

float t

The blend factor.

Vector2 result

The exponential interpolation between a and b.

See Also
Elerp(float, float, float)

Equals(Vector2)

Indicates whether the current object is equal to another object of the same type.

Declaration
public readonly bool Equals(Vector2 other)
Parameters
Type Name Description
Vector2 other

An object to compare with this object.

Returns
Type Description
bool

true if the current object is equal to the other 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 with the current instance.

Returns
Type Description
bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

Overrides
ValueType.Equals(object)

GetHashCode()

Returns the hash code for this instance.

Declaration
public override readonly int GetHashCode()
Returns
Type Description
int

A 32-bit signed integer that is the hash code for this instance.

Overrides
ValueType.GetHashCode()

Lerp(Vector2, Vector2, Vector2)

Returns a new vector that is the component-wise linear blend of the 2 given vectors.

Declaration
[Pure]
public static Vector2 Lerp(Vector2 a, Vector2 b, Vector2 blend)
Parameters
Type Name Description
Vector2 a

First input vector.

Vector2 b

Second input vector.

Vector2 blend

The blend factor.

Returns
Type Description
Vector2

a when blend=0, b when blend=1, and a component-wise linear combination otherwise.

Lerp(Vector2, Vector2, float)

Returns a new vector that is the linear blend of the 2 given vectors.

Declaration
[Pure]
public static Vector2 Lerp(Vector2 a, Vector2 b, float blend)
Parameters
Type Name Description
Vector2 a

First input vector.

Vector2 b

Second input vector.

float blend

The blend factor.

Returns
Type Description
Vector2

a when blend=0, b when blend=1, and a linear combination otherwise.

Lerp(in Vector2, in Vector2, Vector2, out Vector2)

Returns a new vector that is the component-wise linear blend of the 2 given vectors.

Declaration
public static void Lerp(in Vector2 a, in Vector2 b, Vector2 blend, out Vector2 result)
Parameters
Type Name Description
Vector2 a

First input vector.

Vector2 b

Second input vector.

Vector2 blend

The blend factor.

Vector2 result

a when blend=0, b when blend=1, and a component-wise linear combination otherwise.

Lerp(in Vector2, in Vector2, float, out Vector2)

Returns a new vector that is the linear blend of the 2 given vectors.

Declaration
public static void Lerp(in Vector2 a, in Vector2 b, float blend, out Vector2 result)
Parameters
Type Name Description
Vector2 a

First input vector.

Vector2 b

Second input vector.

float blend

The blend factor.

Vector2 result

a when blend=0, b when blend=1, and a linear combination otherwise.

MagnitudeMax(Vector2, Vector2)

Returns the Vector2 with the maximum magnitude. If the magnitudes are equal, the first vector is selected.

Declaration
[Pure]
public static Vector2 MagnitudeMax(Vector2 left, Vector2 right)
Parameters
Type Name Description
Vector2 left

Left operand.

Vector2 right

Right operand.

Returns
Type Description
Vector2

The maximum Vector2.

MagnitudeMax(in Vector2, in Vector2, out Vector2)

Returns the Vector2 with the maximum magnitude. If the magnitudes are equal, the first vector is selected.

Declaration
public static void MagnitudeMax(in Vector2 left, in Vector2 right, out Vector2 result)
Parameters
Type Name Description
Vector2 left

Left operand.

Vector2 right

Right operand.

Vector2 result

The magnitude-wise maximum.

MagnitudeMin(Vector2, Vector2)

Returns the Vector2 with the minimum magnitude. If the magnitudes are equal, the second vector is selected.

Declaration
[Pure]
public static Vector2 MagnitudeMin(Vector2 left, Vector2 right)
Parameters
Type Name Description
Vector2 left

Left operand.

Vector2 right

Right operand.

Returns
Type Description
Vector2

The minimum Vector2.

MagnitudeMin(in Vector2, in Vector2, out Vector2)

Returns the Vector2 with the minimum magnitude. If the magnitudes are equal, the second vector is selected.

Declaration
public static void MagnitudeMin(in Vector2 left, in Vector2 right, out Vector2 result)
Parameters
Type Name Description
Vector2 left

Left operand.

Vector2 right

Right operand.

Vector2 result

The magnitude-wise minimum.

Multiply(Vector2, Vector2)

Multiplies a vector by the components a vector (scale).

Declaration
[Pure]
public static Vector2 Multiply(Vector2 vector, Vector2 scale)
Parameters
Type Name Description
Vector2 vector

Left operand.

Vector2 scale

Right operand.

Returns
Type Description
Vector2

Result of the operation.

Multiply(Vector2, float)

Multiplies a vector by a scalar.

Declaration
[Pure]
public static Vector2 Multiply(Vector2 vector, float scale)
Parameters
Type Name Description
Vector2 vector

Left operand.

float scale

Right operand.

Returns
Type Description
Vector2

Result of the operation.

Multiply(in Vector2, in Vector2, out Vector2)

Multiplies a vector by the components of a vector (scale).

Declaration
public static void Multiply(in Vector2 vector, in Vector2 scale, out Vector2 result)
Parameters
Type Name Description
Vector2 vector

Left operand.

Vector2 scale

Right operand.

Vector2 result

Result of the operation.

Multiply(in Vector2, float, out Vector2)

Multiplies a vector by a scalar.

Declaration
public static void Multiply(in Vector2 vector, float scale, out Vector2 result)
Parameters
Type Name Description
Vector2 vector

Left operand.

float scale

Right operand.

Vector2 result

Result of the operation.

Normalize()

Scales the Vector2 to unit length.

Declaration
public void Normalize()

Normalize(Vector2)

Scale a vector to unit length.

Declaration
[Pure]
public static Vector2 Normalize(Vector2 vec)
Parameters
Type Name Description
Vector2 vec

The input vector.

Returns
Type Description
Vector2

The normalized copy.

Normalize(in Vector2, out Vector2)

Scale a vector to unit length.

Declaration
public static void Normalize(in Vector2 vec, out Vector2 result)
Parameters
Type Name Description
Vector2 vec

The input vector.

Vector2 result

The normalized vector.

NormalizeFast()

Scales the Vector2 to approximately unit length.

Declaration
public void NormalizeFast()

NormalizeFast(Vector2)

Scale a vector to approximately unit length.

Declaration
[Pure]
public static Vector2 NormalizeFast(Vector2 vec)
Parameters
Type Name Description
Vector2 vec

The input vector.

Returns
Type Description
Vector2

The normalized copy.

NormalizeFast(in Vector2, out Vector2)

Scale a vector to approximately unit length.

Declaration
public static void NormalizeFast(in Vector2 vec, out Vector2 result)
Parameters
Type Name Description
Vector2 vec

The input vector.

Vector2 result

The normalized vector.

Normalized()

Returns a copy of the Vector2 scaled to unit length.

Declaration
public readonly Vector2 Normalized()
Returns
Type Description
Vector2

The normalized copy.

PerpDot(Vector2, Vector2)

Calculate the perpendicular dot (scalar) product of two vectors.

Declaration
[Pure]
public static float PerpDot(Vector2 left, Vector2 right)
Parameters
Type Name Description
Vector2 left

First operand.

Vector2 right

Second operand.

Returns
Type Description
float

The perpendicular dot product of the two inputs.

PerpDot(in Vector2, in Vector2, out float)

Calculate the perpendicular dot (scalar) product of two vectors.

Declaration
public static void PerpDot(in Vector2 left, in Vector2 right, out float result)
Parameters
Type Name Description
Vector2 left

First operand.

Vector2 right

Second operand.

float result

The perpendicular dot product of the two inputs.

Slerp(Vector2, Vector2, float)

Returns a new vector that is the spherical interpolation of the two given vectors. a and b need to be normalized for this function to work properly.

Declaration
[Pure]
public static Vector2 Slerp(Vector2 a, Vector2 b, float t)
Parameters
Type Name Description
Vector2 a

Unit vector start point.

Vector2 b

Unit vector end point.

float t

The blend factor.

Returns
Type Description
Vector2

a when t=0, b when t=1, and a spherical interpolation between the vectors otherwise.

Slerp(in Vector2, in Vector2, float, out Vector2)

Returns a new vector that is the spherical interpolation of the two given vectors. a and b need to be normalized for this function to work properly.

Declaration
public static void Slerp(in Vector2 a, in Vector2 b, float t, out Vector2 result)
Parameters
Type Name Description
Vector2 a

Unit vector start point.

Vector2 b

Unit vector end point.

float t

The blend factor.

Vector2 result

Is a when t=0, b when t=1, and a spherical interpolation between the vectors otherwise.

Subtract(Vector2, Vector2)

Subtract one Vector from another.

Declaration
[Pure]
public static Vector2 Subtract(Vector2 a, Vector2 b)
Parameters
Type Name Description
Vector2 a

First operand.

Vector2 b

Second operand.

Returns
Type Description
Vector2

Result of subtraction.

Subtract(in Vector2, in Vector2, out Vector2)

Subtract one Vector from another.

Declaration
public static void Subtract(in Vector2 a, in Vector2 b, out Vector2 result)
Parameters
Type Name Description
Vector2 a

First operand.

Vector2 b

Second operand.

Vector2 result

Result of subtraction.

ToString()

Returns the fully qualified type name of this instance.

Declaration
public override string ToString()
Returns
Type Description
string

The fully qualified type name.

Overrides
ValueType.ToString()

ToString(IFormatProvider)

Formats the value of the current instance using the specified format.

Declaration
public string ToString(IFormatProvider formatProvider)
Parameters
Type Name Description
IFormatProvider formatProvider

The provider to use to format the value.

-or-

A null reference (Nothing in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.

Returns
Type Description
string

The value of the current instance in the specified format.

ToString(string)

Formats the value of the current instance using the specified format.

Declaration
public string ToString(string format)
Parameters
Type Name Description
string format

The format to use.

-or-

A null reference (Nothing in Visual Basic) to use the default format defined for the type of the IFormattable implementation.

Returns
Type Description
string

The value of the current instance in the specified format.

ToString(string, IFormatProvider)

Formats the value of the current instance using the specified format.

Declaration
public readonly string ToString(string format, IFormatProvider formatProvider)
Parameters
Type Name Description
string format

The format to use.

-or-

A null reference (Nothing in Visual Basic) to use the default format defined for the type of the IFormattable implementation.

IFormatProvider formatProvider

The provider to use to format the value.

-or-

A null reference (Nothing in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.

Returns
Type Description
string

The value of the current instance in the specified format.

Transform(Vector2, Quaternion)

Transforms a vector by a quaternion rotation.

Declaration
[Pure]
public static Vector2 Transform(Vector2 vec, Quaternion quat)
Parameters
Type Name Description
Vector2 vec

The vector to transform.

Quaternion quat

The quaternion to rotate the vector by.

Returns
Type Description
Vector2

The result of the operation.

Transform(in Vector2, in Quaternion, out Vector2)

Transforms a vector by a quaternion rotation.

Declaration
public static void Transform(in Vector2 vec, in Quaternion quat, out Vector2 result)
Parameters
Type Name Description
Vector2 vec

The vector to transform.

Quaternion quat

The quaternion to rotate the vector by.

Vector2 result

The result of the operation.

TransformColumn(Matrix2, Vector2)

Transform a Vector by the given Matrix using right-handed notation.

Declaration
[Pure]
public static Vector2 TransformColumn(Matrix2 mat, Vector2 vec)
Parameters
Type Name Description
Matrix2 mat

The desired transformation.

Vector2 vec

The vector to transform.

Returns
Type Description
Vector2

The transformed vector.

TransformColumn(in Matrix2, in Vector2, out Vector2)

Transform a Vector by the given Matrix using right-handed notation.

Declaration
public static void TransformColumn(in Matrix2 mat, in Vector2 vec, out Vector2 result)
Parameters
Type Name Description
Matrix2 mat

The desired transformation.

Vector2 vec

The vector to transform.

Vector2 result

The transformed vector.

TransformRow(Vector2, Matrix2)

Transform a Vector by the given Matrix.

Declaration
[Pure]
public static Vector2 TransformRow(Vector2 vec, Matrix2 mat)
Parameters
Type Name Description
Vector2 vec

The vector to transform.

Matrix2 mat

The desired transformation.

Returns
Type Description
Vector2

The transformed vector.

TransformRow(in Vector2, in Matrix2, out Vector2)

Transform a Vector by the given Matrix.

Declaration
public static void TransformRow(in Vector2 vec, in Matrix2 mat, out Vector2 result)
Parameters
Type Name Description
Vector2 vec

The vector to transform.

Matrix2 mat

The desired transformation.

Vector2 result

The transformed vector.

Operators

operator +(Vector2, Vector2)

Adds the specified instances.

Declaration
[Pure]
public static Vector2 operator +(Vector2 left, Vector2 right)
Parameters
Type Name Description
Vector2 left

Left operand.

Vector2 right

Right operand.

Returns
Type Description
Vector2

Result of addition.

operator /(Vector2, Vector2)

Component-wise division between the specified instance by a scale vector.

Declaration
[Pure]
public static Vector2 operator /(Vector2 vec, Vector2 scale)
Parameters
Type Name Description
Vector2 vec

Left operand.

Vector2 scale

Right operand.

Returns
Type Description
Vector2

Result of the division.

operator /(Vector2, float)

Divides the specified instance by a scalar.

Declaration
[Pure]
public static Vector2 operator /(Vector2 vec, float scale)
Parameters
Type Name Description
Vector2 vec

Left operand.

float scale

Right operand.

Returns
Type Description
Vector2

Result of the division.

operator ==(Vector2, Vector2)

Compares the specified instances for equality.

Declaration
public static bool operator ==(Vector2 left, Vector2 right)
Parameters
Type Name Description
Vector2 left

Left operand.

Vector2 right

Right operand.

Returns
Type Description
bool

True if both instances are equal; false otherwise.

explicit operator Vector2h(Vector2)

Converts OpenTK.Vector2 to OpenTK.Vector2h.

Declaration
[Pure]
public static explicit operator Vector2h(Vector2 vec)
Parameters
Type Name Description
Vector2 vec

The Vector2 to convert.

Returns
Type Description
Vector2h

The resulting Vector2h.

explicit operator Vector2i(Vector2)

Converts OpenTK.Vector2 to OpenTK.Vector2i.

Declaration
[Pure]
public static explicit operator Vector2i(Vector2 vec)
Parameters
Type Name Description
Vector2 vec

The Vector2 to convert.

Returns
Type Description
Vector2i

The resulting Vector2i.

explicit operator PointF(Vector2)

Converts Vector2 to PointF.

Declaration
[Pure]
public static explicit operator PointF(Vector2 vec)
Parameters
Type Name Description
Vector2 vec

The Vector2 to cast.

Returns
Type Description
PointF

The resulting PointF.

explicit operator SizeF(Vector2)

Converts Vector2 to SizeF.

Declaration
[Pure]
public static explicit operator SizeF(Vector2 vec)
Parameters
Type Name Description
Vector2 vec

The Vector2 to cast.

Returns
Type Description
SizeF

The resulting SizeF.

implicit operator Vector2d(Vector2)

Converts OpenTK.Vector2 to OpenTK.Vector2d.

Declaration
[Pure]
public static implicit operator Vector2d(Vector2 vec)
Parameters
Type Name Description
Vector2 vec

The Vector2 to convert.

Returns
Type Description
Vector2d

The resulting Vector2d.

implicit operator Vector2((float X, float Y))

Initializes a new instance of the Vector2 struct using a tuple containing the component values.

Declaration
[Pure]
public static implicit operator Vector2((float X, float Y) values)
Parameters
Type Name Description
(float X, float Y) values

A tuple containing the component values.

Returns
Type Description
Vector2

A new instance of the Vector2 struct with the given component values.

operator !=(Vector2, Vector2)

Compares the specified instances for inequality.

Declaration
public static bool operator !=(Vector2 left, Vector2 right)
Parameters
Type Name Description
Vector2 left

Left operand.

Vector2 right

Right operand.

Returns
Type Description
bool

True if both instances are not equal; false otherwise.

operator *(Matrix2, Vector2)

Transform a Vector by the given Matrix using right-handed notation.

Declaration
[Pure]
public static Vector2 operator *(Matrix2 mat, Vector2 vec)
Parameters
Type Name Description
Matrix2 mat

The desired transformation.

Vector2 vec

The vector to transform.

Returns
Type Description
Vector2

The transformed vector.

operator *(Quaternion, Vector2)

Transforms a vector by a quaternion rotation.

Declaration
[Pure]
public static Vector2 operator *(Quaternion quat, Vector2 vec)
Parameters
Type Name Description
Quaternion quat

The quaternion to rotate the vector by.

Vector2 vec

The vector to transform.

Returns
Type Description
Vector2

The multiplied vector.

operator *(Vector2, Matrix2)

Transform a Vector by the given Matrix.

Declaration
[Pure]
public static Vector2 operator *(Vector2 vec, Matrix2 mat)
Parameters
Type Name Description
Vector2 vec

The vector to transform.

Matrix2 mat

The desired transformation.

Returns
Type Description
Vector2

The transformed vector.

operator *(Vector2, Vector2)

Component-wise multiplication between the specified instance by a scale vector.

Declaration
[Pure]
public static Vector2 operator *(Vector2 vec, Vector2 scale)
Parameters
Type Name Description
Vector2 vec

Right operand.

Vector2 scale

Left operand.

Returns
Type Description
Vector2

Result of multiplication.

operator *(Vector2, float)

Multiplies the specified instance by a scalar.

Declaration
[Pure]
public static Vector2 operator *(Vector2 vec, float scale)
Parameters
Type Name Description
Vector2 vec

Left operand.

float scale

Right operand.

Returns
Type Description
Vector2

Result of multiplication.

operator *(float, Vector2)

Multiplies the specified instance by a scalar.

Declaration
[Pure]
public static Vector2 operator *(float scale, Vector2 vec)
Parameters
Type Name Description
float scale

Left operand.

Vector2 vec

Right operand.

Returns
Type Description
Vector2

Result of multiplication.

operator -(Vector2, Vector2)

Subtracts the specified instances.

Declaration
[Pure]
public static Vector2 operator -(Vector2 left, Vector2 right)
Parameters
Type Name Description
Vector2 left

Left operand.

Vector2 right

Right operand.

Returns
Type Description
Vector2

Result of subtraction.

operator -(Vector2)

Negates the specified instance.

Declaration
[Pure]
public static Vector2 operator -(Vector2 vec)
Parameters
Type Name Description
Vector2 vec

Operand.

Returns
Type Description
Vector2

Result of negation.

Implements

IEquatable<T>
IFormattable
In this article
Back to top Generated by DocFX