Struct Vector3
Represents a 3D vector using three single-precision floating-point numbers.
Inherited Members
Namespace: OpenTK.Mathematics
Assembly: OpenTK.Mathematics.dll
Syntax
[Serializable]
public struct Vector3 : IEquatable<Vector3>, IFormattable
Remarks
The Vector3 structure is suitable for interoperation with unmanaged code requiring three consecutive floats.
Constructors
Vector3(Vector2, float)
Initializes a new instance of the Vector3 struct.
Declaration
public Vector3(Vector2 xy, float z = 0)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | xy | The x and y components of the Vector3. |
float | z | The z component of the Vector3. |
Vector3(float)
Initializes a new instance of the Vector3 struct.
Declaration
public Vector3(float value)
Parameters
Type | Name | Description |
---|---|---|
float | value | The value that will initialize this instance. |
Vector3(float, float, float)
Initializes a new instance of the Vector3 struct.
Declaration
public Vector3(float x, float y, float z)
Parameters
Type | Name | Description |
---|---|---|
float | x | The x component of the Vector3. |
float | y | The y component of the Vector3. |
float | z | The z component of the Vector3. |
Fields
NegativeInfinity
Defines an instance with all components set to negative infinity.
Declaration
public static readonly Vector3 NegativeInfinity
Field Value
Type | Description |
---|---|
Vector3 |
One
Defines an instance with all components set to 1.
Declaration
public static readonly Vector3 One
Field Value
Type | Description |
---|---|
Vector3 |
PositiveInfinity
Defines an instance with all components set to positive infinity.
Declaration
public static readonly Vector3 PositiveInfinity
Field Value
Type | Description |
---|---|
Vector3 |
SizeInBytes
Defines the size of the Vector3 struct in bytes.
Declaration
public static readonly int SizeInBytes
Field Value
Type | Description |
---|---|
int |
UnitX
Defines a unit-length Vector3 that points towards the X-axis.
Declaration
public static readonly Vector3 UnitX
Field Value
Type | Description |
---|---|
Vector3 |
UnitY
Defines a unit-length Vector3 that points towards the Y-axis.
Declaration
public static readonly Vector3 UnitY
Field Value
Type | Description |
---|---|
Vector3 |
UnitZ
Defines a unit-length Vector3 that points towards the Z-axis.
Declaration
public static readonly Vector3 UnitZ
Field Value
Type | Description |
---|---|
Vector3 |
X
The X component of the Vector3.
Declaration
public float X
Field Value
Type | Description |
---|---|
float |
Y
The Y component of the Vector3.
Declaration
public float Y
Field Value
Type | Description |
---|---|
float |
Z
The Z component of the Vector3.
Declaration
public float Z
Field Value
Type | Description |
---|---|
float |
Zero
Defines an instance with all components set to 0.
Declaration
public static readonly Vector3 Zero
Field Value
Type | Description |
---|---|
Vector3 |
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 2. |
Length
Gets the length (magnitude) of the vector.
Declaration
public readonly float Length { get; }
Property Value
Type | Description |
---|---|
float |
See Also
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
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
ReciprocalLengthFast
Gets an approximation of 1 over the length (magnitude) of the vector.
Declaration
public readonly float ReciprocalLengthFast { get; }
Property Value
Type | Description |
---|---|
float |
Xy
Gets or sets an OpenTK.Vector2 with the X and Y components of this instance.
Declaration
public Vector2 Xy { get; set; }
Property Value
Type | Description |
---|---|
Vector2 |
Xz
Gets or sets an OpenTK.Vector2 with the X and Z components of this instance.
Declaration
public Vector2 Xz { readonly get; set; }
Property Value
Type | Description |
---|---|
Vector2 |
Xzy
Gets or sets an OpenTK.Vector3 with the X, Z, and Y components of this instance.
Declaration
public Vector3 Xzy { readonly get; set; }
Property Value
Type | Description |
---|---|
Vector3 |
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 |
Yxz
Gets or sets an OpenTK.Vector3 with the Y, X, and Z components of this instance.
Declaration
public Vector3 Yxz { readonly get; set; }
Property Value
Type | Description |
---|---|
Vector3 |
Yz
Gets or sets an OpenTK.Vector2 with the Y and Z components of this instance.
Declaration
public Vector2 Yz { readonly get; set; }
Property Value
Type | Description |
---|---|
Vector2 |
Yzx
Gets or sets an OpenTK.Vector3 with the Y, Z, and X components of this instance.
Declaration
public Vector3 Yzx { readonly get; set; }
Property Value
Type | Description |
---|---|
Vector3 |
Zx
Gets or sets an OpenTK.Vector2 with the Z and X components of this instance.
Declaration
public Vector2 Zx { readonly get; set; }
Property Value
Type | Description |
---|---|
Vector2 |
Zxy
Gets or sets an OpenTK.Vector3 with the Z, X, and Y components of this instance.
Declaration
public Vector3 Zxy { readonly get; set; }
Property Value
Type | Description |
---|---|
Vector3 |
Zy
Gets or sets an OpenTK.Vector2 with the Z and Y components of this instance.
Declaration
public Vector2 Zy { readonly get; set; }
Property Value
Type | Description |
---|---|
Vector2 |
Zyx
Gets or sets an OpenTK.Vector3 with the Z, Y, and X components of this instance.
Declaration
public Vector3 Zyx { readonly get; set; }
Property Value
Type | Description |
---|---|
Vector3 |
Methods
Abs()
Returns a new vector that is the component-wise absolute value of the vector.
Declaration
public readonly Vector3 Abs()
Returns
Type | Description |
---|---|
Vector3 | The component-wise absolute value vector. |
Abs(Vector3)
Take the component-wise absolute value of a vector.
Declaration
public static Vector3 Abs(Vector3 vec)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | The vector to apply component-wise absolute value to. |
Returns
Type | Description |
---|---|
Vector3 | The component-wise absolute value vector. |
Abs(in Vector3, out Vector3)
Take the component-wise absolute value of a vector.
Declaration
public static void Abs(in Vector3 vec, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | The vector to apply component-wise absolute value to. |
Vector3 | result | The component-wise absolute value vector. |
Add(Vector3, Vector3)
Adds two vectors.
Declaration
[Pure]
public static Vector3 Add(Vector3 a, Vector3 b)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | a | Left operand. |
Vector3 | b | Right operand. |
Returns
Type | Description |
---|---|
Vector3 | Result of operation. |
Add(in Vector3, in Vector3, out Vector3)
Adds two vectors.
Declaration
public static void Add(in Vector3 a, in Vector3 b, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | a | Left operand. |
Vector3 | b | Right operand. |
Vector3 | result | Result of operation. |
BaryCentric(Vector3, Vector3, Vector3, float, float)
Interpolate 3 Vectors using Barycentric coordinates.
Declaration
[Pure]
public static Vector3 BaryCentric(Vector3 a, Vector3 b, Vector3 c, float u, float v)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | a | First input Vector. |
Vector3 | b | Second input Vector. |
Vector3 | c | Third input Vector. |
float | u | First Barycentric Coordinate. |
float | v | Second Barycentric Coordinate. |
Returns
Type | Description |
---|---|
Vector3 | 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 Vector3, in Vector3, in Vector3, float, float, out Vector3)
Interpolate 3 Vectors using Barycentric coordinates.
Declaration
[Pure]
public static void BaryCentric(in Vector3 a, in Vector3 b, in Vector3 c, float u, float v, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | a | First input Vector. |
Vector3 | b | Second input Vector. |
Vector3 | c | Third input Vector. |
float | u | First Barycentric Coordinate. |
float | v | Second Barycentric Coordinate. |
Vector3 | 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. |
CalculateAngle(Vector3, Vector3)
Calculates the angle (in radians) between two vectors.
Declaration
[Pure]
public static float CalculateAngle(Vector3 first, Vector3 second)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | first | The first vector. |
Vector3 | second | The second vector. |
Returns
Type | Description |
---|---|
float | Angle (in radians) between the vectors. |
Remarks
Note that the returned angle is never bigger than the constant Pi.
CalculateAngle(in Vector3, in Vector3, out float)
Calculates the angle (in radians) between two vectors.
Declaration
public static void CalculateAngle(in Vector3 first, in Vector3 second, out float result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | first | The first vector. |
Vector3 | second | The second vector. |
float | result | Angle (in radians) between the vectors. |
Remarks
Note that the returned angle is never bigger than the constant Pi.
Clamp(Vector3, Vector3, Vector3)
Clamp a vector to the given minimum and maximum vectors.
Declaration
[Pure]
public static Vector3 Clamp(Vector3 vec, Vector3 min, Vector3 max)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | Input vector. |
Vector3 | min | Minimum vector. |
Vector3 | max | Maximum vector. |
Returns
Type | Description |
---|---|
Vector3 | The clamped vector. |
Clamp(in Vector3, in Vector3, in Vector3, out Vector3)
Clamp a vector to the given minimum and maximum vectors.
Declaration
public static void Clamp(in Vector3 vec, in Vector3 min, in Vector3 max, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | Input vector. |
Vector3 | min | Minimum vector. |
Vector3 | max | Maximum vector. |
Vector3 | result | The clamped vector. |
ComponentMax(Vector3, Vector3)
Returns a vector created from the largest of the corresponding components of the given vectors.
Declaration
[Pure]
public static Vector3 ComponentMax(Vector3 a, Vector3 b)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | a | First operand. |
Vector3 | b | Second operand. |
Returns
Type | Description |
---|---|
Vector3 | The component-wise maximum. |
ComponentMax(in Vector3, in Vector3, out Vector3)
Returns a vector created from the largest of the corresponding components of the given vectors.
Declaration
public static void ComponentMax(in Vector3 a, in Vector3 b, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | a | First operand. |
Vector3 | b | Second operand. |
Vector3 | result | The component-wise maximum. |
ComponentMin(Vector3, Vector3)
Returns a vector created from the smallest of the corresponding components of the given vectors.
Declaration
[Pure]
public static Vector3 ComponentMin(Vector3 a, Vector3 b)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | a | First operand. |
Vector3 | b | Second operand. |
Returns
Type | Description |
---|---|
Vector3 | The component-wise minimum. |
ComponentMin(in Vector3, in Vector3, out Vector3)
Returns a vector created from the smallest of the corresponding components of the given vectors.
Declaration
public static void ComponentMin(in Vector3 a, in Vector3 b, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | a | First operand. |
Vector3 | b | Second operand. |
Vector3 | result | The component-wise minimum. |
Cross(Vector3, Vector3)
Caclulate the cross (vector) product of two vectors.
Declaration
[Pure]
public static Vector3 Cross(Vector3 left, Vector3 right)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | left | First operand. |
Vector3 | right | Second operand. |
Returns
Type | Description |
---|---|
Vector3 | The cross product of the two inputs. |
Cross(in Vector3, in Vector3, out Vector3)
Caclulate the cross (vector) product of two vectors.
Declaration
public static void Cross(in Vector3 left, in Vector3 right, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | left | First operand. |
Vector3 | right | Second operand. |
Vector3 | result | The cross product of the two inputs. |
Deconstruct(out float, out float, out float)
Deconstructs the vector into it's individual components.
Declaration
[Pure]
public readonly void Deconstruct(out float x, out float y, out float z)
Parameters
Type | Name | Description |
---|---|---|
float | x | The X component of the vector. |
float | y | The Y component of the vector. |
float | z | The Z component of the vector. |
Distance(Vector3, Vector3)
Compute the euclidean distance between two vectors.
Declaration
[Pure]
public static float Distance(Vector3 vec1, Vector3 vec2)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec1 | The first vector. |
Vector3 | vec2 | The second vector. |
Returns
Type | Description |
---|---|
float | The distance. |
Distance(in Vector3, in Vector3, out float)
Compute the euclidean distance between two vectors.
Declaration
public static void Distance(in Vector3 vec1, in Vector3 vec2, out float result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec1 | The first vector. |
Vector3 | vec2 | The second vector. |
float | result | The distance. |
DistanceSquared(Vector3, Vector3)
Compute the squared euclidean distance between two vectors.
Declaration
[Pure]
public static float DistanceSquared(Vector3 vec1, Vector3 vec2)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec1 | The first vector. |
Vector3 | vec2 | The second vector. |
Returns
Type | Description |
---|---|
float | The squared distance. |
DistanceSquared(in Vector3, in Vector3, out float)
Compute the squared euclidean distance between two vectors.
Declaration
public static void DistanceSquared(in Vector3 vec1, in Vector3 vec2, out float result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec1 | The first vector. |
Vector3 | vec2 | The second vector. |
float | result | The squared distance. |
Divide(Vector3, Vector3)
Divides a vector by the components of a vector (scale).
Declaration
[Pure]
public static Vector3 Divide(Vector3 vector, Vector3 scale)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vector | Left operand. |
Vector3 | scale | Right operand. |
Returns
Type | Description |
---|---|
Vector3 | Result of the operation. |
Divide(Vector3, float)
Divides a vector by a scalar.
Declaration
[Pure]
public static Vector3 Divide(Vector3 vector, float scale)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vector | Left operand. |
float | scale | Right operand. |
Returns
Type | Description |
---|---|
Vector3 | Result of the operation. |
Divide(in Vector3, in Vector3, out Vector3)
Divide a vector by the components of a vector (scale).
Declaration
public static void Divide(in Vector3 vector, in Vector3 scale, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vector | Left operand. |
Vector3 | scale | Right operand. |
Vector3 | result | Result of the operation. |
Divide(in Vector3, float, out Vector3)
Divides a vector by a scalar.
Declaration
public static void Divide(in Vector3 vector, float scale, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vector | Left operand. |
float | scale | Right operand. |
Vector3 | result | Result of the operation. |
Dot(Vector3, Vector3)
Calculate the dot (scalar) product of two vectors.
Declaration
[Pure]
public static float Dot(Vector3 left, Vector3 right)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | left | First operand. |
Vector3 | right | Second operand. |
Returns
Type | Description |
---|---|
float | The dot product of the two inputs. |
Dot(in Vector3, in Vector3, out float)
Calculate the dot (scalar) product of two vectors.
Declaration
public static void Dot(in Vector3 left, in Vector3 right, out float result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | left | First operand. |
Vector3 | right | Second operand. |
float | result | The dot product of the two inputs. |
Elerp(Vector3, Vector3, float)
Returns a new vector that is the exponential interpolation of the two vectors.
Equivalent to a * pow(b/a, t)
.
Declaration
public static Vector3 Elerp(Vector3 a, Vector3 b, float t)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | a | The starting value. Must be non-negative. |
Vector3 | b | The end value. Must be non-negative. |
float | t | The blend factor. |
Returns
Type | Description |
---|---|
Vector3 | The exponential interpolation between |
See Also
Elerp(in Vector3, in Vector3, float, out Vector3)
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 Vector3 a, in Vector3 b, float t, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | a | The starting value. Must be non-negative. |
Vector3 | b | The end value. Must be non-negative. |
float | t | The blend factor. |
Vector3 | result | The exponential interpolation between |
See Also
Equals(Vector3)
Indicates whether the current object is equal to another object of the same type.
Declaration
public readonly bool Equals(Vector3 other)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | other | An object to compare with this object. |
Returns
Type | Description |
---|---|
bool | true if the current object is equal to the |
Equals(object)
Indicates whether this instance and a specified object are equal.
Declaration
public override readonly bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The object to compare with the current instance. |
Returns
Type | Description |
---|---|
bool | true if |
Overrides
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
Lerp(Vector3, Vector3, Vector3)
Returns a new vector that is the component-wise linear blend of the 2 given vectors.
Declaration
[Pure]
public static Vector3 Lerp(Vector3 a, Vector3 b, Vector3 blend)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | a | First input vector. |
Vector3 | b | Second input vector. |
Vector3 | blend | The blend factor. |
Returns
Type | Description |
---|---|
Vector3 | a when blend=0, b when blend=1, and a component-wise linear combination otherwise. |
Lerp(Vector3, Vector3, float)
Returns a new vector that is the linear blend of the 2 given vectors.
Declaration
[Pure]
public static Vector3 Lerp(Vector3 a, Vector3 b, float blend)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | a | First input vector. |
Vector3 | b | Second input vector. |
float | blend | The blend factor. |
Returns
Type | Description |
---|---|
Vector3 | a when blend=0, b when blend=1, and a linear combination otherwise. |
Lerp(in Vector3, in Vector3, Vector3, out Vector3)
Returns a new vector that is the component-wise linear blend of the 2 given vectors.
Declaration
public static void Lerp(in Vector3 a, in Vector3 b, Vector3 blend, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | a | First input vector. |
Vector3 | b | Second input vector. |
Vector3 | blend | The blend factor. |
Vector3 | result | a when blend=0, b when blend=1, and a component-wise linear combination otherwise. |
Lerp(in Vector3, in Vector3, float, out Vector3)
Returns a new vector that is the linear blend of the 2 given vectors.
Declaration
public static void Lerp(in Vector3 a, in Vector3 b, float blend, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | a | First input vector. |
Vector3 | b | Second input vector. |
float | blend | The blend factor. |
Vector3 | result | a when blend=0, b when blend=1, and a linear combination otherwise. |
MagnitudeMax(Vector3, Vector3)
Returns the Vector3 with the maximum magnitude. If the magnitudes are equal, the first vector is selected.
Declaration
[Pure]
public static Vector3 MagnitudeMax(Vector3 left, Vector3 right)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | left | Left operand. |
Vector3 | right | Right operand. |
Returns
Type | Description |
---|---|
Vector3 | The maximum Vector3. |
MagnitudeMax(in Vector3, in Vector3, out Vector3)
Returns the Vector3 with the maximum magnitude. If the magnitudes are equal, the first vector is selected.
Declaration
public static void MagnitudeMax(in Vector3 left, in Vector3 right, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | left | Left operand. |
Vector3 | right | Right operand. |
Vector3 | result | The magnitude-wise maximum. |
MagnitudeMin(Vector3, Vector3)
Returns the Vector3 with the minimum magnitude. If the magnitudes are equal, the second vector is selected.
Declaration
[Pure]
public static Vector3 MagnitudeMin(Vector3 left, Vector3 right)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | left | Left operand. |
Vector3 | right | Right operand. |
Returns
Type | Description |
---|---|
Vector3 | The minimum Vector3. |
MagnitudeMin(in Vector3, in Vector3, out Vector3)
Returns the Vector3 with the minimum magnitude. If the magnitudes are equal, the second vector is selected.
Declaration
public static void MagnitudeMin(in Vector3 left, in Vector3 right, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | left | Left operand. |
Vector3 | right | Right operand. |
Vector3 | result | The magnitude-wise minimum. |
Multiply(Vector3, Vector3)
Multiplies a vector by the components a vector (scale).
Declaration
[Pure]
public static Vector3 Multiply(Vector3 vector, Vector3 scale)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vector | Left operand. |
Vector3 | scale | Right operand. |
Returns
Type | Description |
---|---|
Vector3 | Result of the operation. |
Multiply(Vector3, float)
Multiplies a vector by a scalar.
Declaration
[Pure]
public static Vector3 Multiply(Vector3 vector, float scale)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vector | Left operand. |
float | scale | Right operand. |
Returns
Type | Description |
---|---|
Vector3 | Result of the operation. |
Multiply(in Vector3, in Vector3, out Vector3)
Multiplies a vector by the components of a vector (scale).
Declaration
public static void Multiply(in Vector3 vector, in Vector3 scale, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vector | Left operand. |
Vector3 | scale | Right operand. |
Vector3 | result | Result of the operation. |
Multiply(in Vector3, float, out Vector3)
Multiplies a vector by a scalar.
Declaration
public static void Multiply(in Vector3 vector, float scale, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vector | Left operand. |
float | scale | Right operand. |
Vector3 | result | Result of the operation. |
Normalize()
Scales the Vector3 to unit length.
Declaration
public void Normalize()
Normalize(Vector3)
Scale a vector to unit length.
Declaration
[Pure]
public static Vector3 Normalize(Vector3 vec)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | The input vector. |
Returns
Type | Description |
---|---|
Vector3 | The normalized copy. |
Normalize(in Vector3, out Vector3)
Scale a vector to unit length.
Declaration
public static void Normalize(in Vector3 vec, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | The input vector. |
Vector3 | result | The normalized vector. |
NormalizeFast()
Scales the Vector3 to approximately unit length.
Declaration
public void NormalizeFast()
NormalizeFast(Vector3)
Scale a vector to approximately unit length.
Declaration
[Pure]
public static Vector3 NormalizeFast(Vector3 vec)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | The input vector. |
Returns
Type | Description |
---|---|
Vector3 | The normalized copy. |
NormalizeFast(in Vector3, out Vector3)
Scale a vector to approximately unit length.
Declaration
public static void NormalizeFast(in Vector3 vec, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | The input vector. |
Vector3 | result | The normalized vector. |
Normalized()
Returns a copy of the Vector3 scaled to unit length.
Declaration
public readonly Vector3 Normalized()
Returns
Type | Description |
---|---|
Vector3 | The normalized copy. |
Project(Vector3, float, float, float, float, float, float, Matrix4)
Projects a vector from object space into screen space.
Declaration
[Pure]
public static Vector3 Project(Vector3 vector, float x, float y, float width, float height, float minZ, float maxZ, Matrix4 worldViewProjection)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vector | The vector to project. |
float | x | The X coordinate of the viewport. |
float | y | The Y coordinate of the viewport. |
float | width | The width of the viewport. |
float | height | The height of the viewport. |
float | minZ | The minimum depth of the viewport. |
float | maxZ | The maximum depth of the viewport. |
Matrix4 | worldViewProjection | The world-view-projection matrix. |
Returns
Type | Description |
---|---|
Vector3 | The vector in screen space. |
Remarks
To project to normalized device coordinates (NDC) use the following parameters: Project(vector, -1, -1, 2, 2, -1, 1, worldViewProjection).
Slerp(Vector3, Vector3, 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 Vector3 Slerp(Vector3 a, Vector3 b, float t)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | a | Unit vector start point. |
Vector3 | b | Unit vector end point. |
float | t | The blend factor. |
Returns
Type | Description |
---|---|
Vector3 |
|
Slerp(in Vector3, in Vector3, float, out Vector3)
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 Vector3 a, in Vector3 b, float t, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | a | Unit vector start point. |
Vector3 | b | Unit vector end point. |
float | t | The blend factor. |
Vector3 | result | Is |
Subtract(Vector3, Vector3)
Subtract one Vector from another.
Declaration
[Pure]
public static Vector3 Subtract(Vector3 a, Vector3 b)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | a | First operand. |
Vector3 | b | Second operand. |
Returns
Type | Description |
---|---|
Vector3 | Result of subtraction. |
Subtract(in Vector3, in Vector3, out Vector3)
Subtract one Vector from another.
Declaration
public static void Subtract(in Vector3 a, in Vector3 b, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | a | First operand. |
Vector3 | b | Second operand. |
Vector3 | result | Result of subtraction. |
ToString()
Returns the fully qualified type name of this instance.
Declaration
public override readonly string ToString()
Returns
Type | Description |
---|---|
string | The fully qualified type name. |
Overrides
ToString(IFormatProvider)
Formats the value of the current instance using the specified format.
Declaration
public readonly string ToString(IFormatProvider formatProvider)
Parameters
Type | Name | Description |
---|---|---|
IFormatProvider | formatProvider | The provider to use to format the value. -or- A null reference ( |
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 readonly string ToString(string format)
Parameters
Type | Name | Description |
---|---|---|
string | format | The format to use. -or- A null reference ( |
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 ( |
IFormatProvider | formatProvider | The provider to use to format the value. -or- A null reference ( |
Returns
Type | Description |
---|---|
string | The value of the current instance in the specified format. |
Transform(Vector3, Quaternion)
Transforms a vector by a quaternion rotation.
Declaration
[Pure]
public static Vector3 Transform(Vector3 vec, Quaternion quat)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | The vector to transform. |
Quaternion | quat | The quaternion to rotate the vector by. |
Returns
Type | Description |
---|---|
Vector3 | The result of the operation. |
Transform(in Vector3, in Quaternion, out Vector3)
Transforms a vector by a quaternion rotation.
Declaration
public static void Transform(in Vector3 vec, in Quaternion quat, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | The vector to transform. |
Quaternion | quat | The quaternion to rotate the vector by. |
Vector3 | result | The result of the operation. |
TransformColumn(Matrix3, Vector3)
Transform a Vector by the given Matrix using right-handed notation.
Declaration
[Pure]
public static Vector3 TransformColumn(Matrix3 mat, Vector3 vec)
Parameters
Type | Name | Description |
---|---|---|
Matrix3 | mat | The desired transformation. |
Vector3 | vec | The vector to transform. |
Returns
Type | Description |
---|---|
Vector3 | The transformed vector. |
TransformColumn(in Matrix3, in Vector3, out Vector3)
Transform a Vector by the given Matrix using right-handed notation.
Declaration
public static void TransformColumn(in Matrix3 mat, in Vector3 vec, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Matrix3 | mat | The desired transformation. |
Vector3 | vec | The vector to transform. |
Vector3 | result | The transformed vector. |
TransformNormal(Vector3, Matrix4)
Transform a Normal by the given Matrix.
Declaration
[Pure]
public static Vector3 TransformNormal(Vector3 norm, Matrix4 mat)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | norm | The normal to transform. |
Matrix4 | mat | The desired transformation. |
Returns
Type | Description |
---|---|
Vector3 | The transformed normal. |
Remarks
This calculates the inverse of the given matrix, use TransformNormalInverse if you already have the inverse to avoid this extra calculation.
TransformNormal(in Vector3, in Matrix4, out Vector3)
Transform a Normal by the given Matrix.
Declaration
public static void TransformNormal(in Vector3 norm, in Matrix4 mat, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | norm | The normal to transform. |
Matrix4 | mat | The desired transformation. |
Vector3 | result | The transformed normal. |
Remarks
This calculates the inverse of the given matrix, use TransformNormalInverse if you already have the inverse to avoid this extra calculation.
TransformNormalInverse(Vector3, Matrix4)
Transform a Normal by the (transpose of the) given Matrix.
Declaration
[Pure]
public static Vector3 TransformNormalInverse(Vector3 norm, Matrix4 invMat)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | norm | The normal to transform. |
Matrix4 | invMat | The inverse of the desired transformation. |
Returns
Type | Description |
---|---|
Vector3 | The transformed normal. |
Remarks
This version doesn't calculate the inverse matrix. Use this version if you already have the inverse of the desired transform to hand.
TransformNormalInverse(in Vector3, in Matrix4, out Vector3)
Transform a Normal by the (transpose of the) given Matrix.
Declaration
public static void TransformNormalInverse(in Vector3 norm, in Matrix4 invMat, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | norm | The normal to transform. |
Matrix4 | invMat | The inverse of the desired transformation. |
Vector3 | result | The transformed normal. |
Remarks
This version doesn't calculate the inverse matrix. Use this version if you already have the inverse of the desired transform to hand.
TransformPerspective(Vector3, Matrix4)
Transform a Vector3 by the given Matrix, and project the resulting Vector4 back to a Vector3.
Declaration
[Pure]
public static Vector3 TransformPerspective(Vector3 vec, Matrix4 mat)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | The vector to transform. |
Matrix4 | mat | The desired transformation. |
Returns
Type | Description |
---|---|
Vector3 | The transformed vector. |
TransformPerspective(in Vector3, in Matrix4, out Vector3)
Transform a Vector3 by the given Matrix, and project the resulting Vector4 back to a Vector3.
Declaration
public static void TransformPerspective(in Vector3 vec, in Matrix4 mat, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | The vector to transform. |
Matrix4 | mat | The desired transformation. |
Vector3 | result | The transformed vector. |
TransformPosition(Vector3, Matrix4)
Transform a Position by the given Matrix.
Declaration
[Pure]
public static Vector3 TransformPosition(Vector3 pos, Matrix4 mat)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | pos | The position to transform. |
Matrix4 | mat | The desired transformation. |
Returns
Type | Description |
---|---|
Vector3 | The transformed position. |
TransformPosition(in Vector3, in Matrix4, out Vector3)
Transform a Position by the given Matrix.
Declaration
public static void TransformPosition(in Vector3 pos, in Matrix4 mat, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | pos | The position to transform. |
Matrix4 | mat | The desired transformation. |
Vector3 | result | The transformed position. |
TransformRow(Vector3, Matrix3)
Transform a Vector by the given Matrix.
Declaration
[Pure]
public static Vector3 TransformRow(Vector3 vec, Matrix3 mat)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | The vector to transform. |
Matrix3 | mat | The desired transformation. |
Returns
Type | Description |
---|---|
Vector3 | The transformed vector. |
TransformRow(in Vector3, in Matrix3, out Vector3)
Transform a Vector by the given Matrix.
Declaration
public static void TransformRow(in Vector3 vec, in Matrix3 mat, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | The vector to transform. |
Matrix3 | mat | The desired transformation. |
Vector3 | result | The transformed vector. |
TransformVector(Vector3, Matrix4)
Transform a direction vector by the given Matrix. Assumes the matrix has a bottom row of (0,0,0,1), that is the translation part is ignored.
Declaration
[Pure]
public static Vector3 TransformVector(Vector3 vec, Matrix4 mat)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | The vector to transform. |
Matrix4 | mat | The desired transformation. |
Returns
Type | Description |
---|---|
Vector3 | The transformed vector. |
TransformVector(in Vector3, in Matrix4, out Vector3)
Transform a direction vector by the given Matrix. Assumes the matrix has a bottom row of (0,0,0,1), that is the translation part is ignored.
Declaration
public static void TransformVector(in Vector3 vec, in Matrix4 mat, out Vector3 result)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | The vector to transform. |
Matrix4 | mat | The desired transformation. |
Vector3 | result | The transformed vector. |
Unproject(Vector3, float, float, float, float, float, float, Matrix4)
Projects a vector from screen space into object space.
Declaration
[Pure]
public static Vector3 Unproject(Vector3 vector, float x, float y, float width, float height, float minZ, float maxZ, Matrix4 inverseWorldViewProjection)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vector | The vector to project. |
float | x | The X coordinate of the viewport. |
float | y | The Y coordinate of the viewport. |
float | width | The width of the viewport. |
float | height | The height of the viewport. |
float | minZ | The minimum depth of the viewport. |
float | maxZ | The maximum depth of the viewport. |
Matrix4 | inverseWorldViewProjection | The inverse of the world-view-projection matrix. |
Returns
Type | Description |
---|---|
Vector3 | The vector in object space. |
Remarks
To project from normalized device coordinates (NDC) use the following parameters: Project(vector, -1, -1, 2, 2, -1, 1, inverseWorldViewProjection).
Operators
operator +(Vector3, Vector3)
Adds two instances.
Declaration
[Pure]
public static Vector3 operator +(Vector3 left, Vector3 right)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | left | The first instance. |
Vector3 | right | The second instance. |
Returns
Type | Description |
---|---|
Vector3 | The result of the calculation. |
operator /(Vector3, Vector3)
Component-wise division between the specified instance by a scale vector.
Declaration
[Pure]
public static Vector3 operator /(Vector3 vec, Vector3 scale)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | Left operand. |
Vector3 | scale | Right operand. |
Returns
Type | Description |
---|---|
Vector3 | Result of the division. |
operator /(Vector3, float)
Divides an instance by a scalar.
Declaration
[Pure]
public static Vector3 operator /(Vector3 vec, float scale)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | The instance. |
float | scale | The scalar. |
Returns
Type | Description |
---|---|
Vector3 | The result of the calculation. |
operator ==(Vector3, Vector3)
Compares two instances for equality.
Declaration
public static bool operator ==(Vector3 left, Vector3 right)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | left | The first instance. |
Vector3 | right | The second instance. |
Returns
Type | Description |
---|---|
bool | True, if left equals right; false otherwise. |
explicit operator Vector3h(Vector3)
Converts OpenTK.Vector3 to OpenTK.Vector3h.
Declaration
[Pure]
public static explicit operator Vector3h(Vector3 vec)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | The Vector3 to convert. |
Returns
Type | Description |
---|---|
Vector3h | The resulting Vector3h. |
explicit operator Vector3i(Vector3)
Converts OpenTK.Vector3 to OpenTK.Vector3i.
Declaration
[Pure]
public static explicit operator Vector3i(Vector3 vec)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | The Vector3 to convert. |
Returns
Type | Description |
---|---|
Vector3i | The resulting Vector3i. |
implicit operator Vector3d(Vector3)
Converts OpenTK.Vector3 to OpenTK.Vector3d.
Declaration
[Pure]
public static implicit operator Vector3d(Vector3 vec)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | The Vector3 to convert. |
Returns
Type | Description |
---|---|
Vector3d | The resulting Vector3d. |
implicit operator Vector3((float X, float Y, float Z))
Initializes a new instance of the Vector3 struct using a tuple containing the component values.
Declaration
[Pure]
public static implicit operator Vector3((float X, float Y, float Z) values)
Parameters
Type | Name | Description |
---|---|---|
(float X, float Y, float Z) | values | A tuple containing the component values. |
Returns
Type | Description |
---|---|
Vector3 | A new instance of the Vector3 struct with the given component values. |
operator !=(Vector3, Vector3)
Compares two instances for inequality.
Declaration
public static bool operator !=(Vector3 left, Vector3 right)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | left | The first instance. |
Vector3 | right | The second instance. |
Returns
Type | Description |
---|---|
bool | True, if left does not equal right; false otherwise. |
operator *(Matrix3, Vector3)
Transform a Vector by the given Matrix using right-handed notation.
Declaration
[Pure]
public static Vector3 operator *(Matrix3 mat, Vector3 vec)
Parameters
Type | Name | Description |
---|---|---|
Matrix3 | mat | The desired transformation. |
Vector3 | vec | The vector to transform. |
Returns
Type | Description |
---|---|
Vector3 | The transformed vector. |
operator *(Quaternion, Vector3)
Transforms a vector by a quaternion rotation.
Declaration
[Pure]
public static Vector3 operator *(Quaternion quat, Vector3 vec)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | quat | The quaternion to rotate the vector by. |
Vector3 | vec | The vector to transform. |
Returns
Type | Description |
---|---|
Vector3 | The multiplied vector. |
operator *(Vector3, Matrix3)
Transform a Vector by the given Matrix.
Declaration
[Pure]
public static Vector3 operator *(Vector3 vec, Matrix3 mat)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | The vector to transform. |
Matrix3 | mat | The desired transformation. |
Returns
Type | Description |
---|---|
Vector3 | The transformed vector. |
operator *(Vector3, Vector3)
Component-wise multiplication between the specified instance by a scale vector.
Declaration
[Pure]
public static Vector3 operator *(Vector3 vec, Vector3 scale)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | Right operand. |
Vector3 | scale | Left operand. |
Returns
Type | Description |
---|---|
Vector3 | Result of multiplication. |
operator *(Vector3, float)
Multiplies an instance by a scalar.
Declaration
[Pure]
public static Vector3 operator *(Vector3 vec, float scale)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | The instance. |
float | scale | The scalar. |
Returns
Type | Description |
---|---|
Vector3 | The result of the calculation. |
operator *(float, Vector3)
Multiplies an instance by a scalar.
Declaration
[Pure]
public static Vector3 operator *(float scale, Vector3 vec)
Parameters
Type | Name | Description |
---|---|---|
float | scale | The scalar. |
Vector3 | vec | The instance. |
Returns
Type | Description |
---|---|
Vector3 | The result of the calculation. |
operator -(Vector3, Vector3)
Subtracts two instances.
Declaration
[Pure]
public static Vector3 operator -(Vector3 left, Vector3 right)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | left | The first instance. |
Vector3 | right | The second instance. |
Returns
Type | Description |
---|---|
Vector3 | The result of the calculation. |
operator -(Vector3)
Negates an instance.
Declaration
[Pure]
public static Vector3 operator -(Vector3 vec)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vec | The instance. |
Returns
Type | Description |
---|---|
Vector3 | The result of the calculation. |