Struct Quaternion
A structure encapsulating a four-dimensional vector (x,y,z,w), which is used to efficiently rotate an object about the (x,y,z) vector by the angle theta, where w = cos(theta/2).
Inherited Members
Namespace: System.Numerics
Assembly: System.Numerics.dll
Syntax
public struct Quaternion
Constructors
| Improve this Doc View SourceQuaternion(Double, Double, Double, Double)
Constructs a Quaternion from the given components.
Declaration
public Quaternion(double x, double y, double z, double w)
Parameters
Type | Name | Description |
---|---|---|
Double | x | The X component of the Quaternion. |
Double | y | The Y component of the Quaternion. |
Double | z | The Z component of the Quaternion. |
Double | w | The W component of the Quaternion. |
Quaternion(Vector3, Double)
Constructs a Quaternion from the given vector and rotation parts.
Declaration
public Quaternion(Vector3 vectorPart, double scalarPart)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vectorPart | The vector part of the Quaternion. |
Double | scalarPart | The rotation part of the Quaternion. |
Fields
| Improve this Doc View SourceW
Specifies the rotation component of the Quaternion.
Declaration
public double W
Field Value
Type | Description |
---|---|
Double |
X
Specifies the X-value of the vector component of the Quaternion.
Declaration
public double X
Field Value
Type | Description |
---|---|
Double |
Y
Specifies the Y-value of the vector component of the Quaternion.
Declaration
public double Y
Field Value
Type | Description |
---|---|
Double |
Z
Specifies the Z-value of the vector component of the Quaternion.
Declaration
public double Z
Field Value
Type | Description |
---|---|
Double |
Properties
| Improve this Doc View SourceIdentity
Returns a Quaternion representing no rotation.
Declaration
public static readonly Quaternion Identity { get; }
Property Value
Type | Description |
---|---|
Quaternion |
IsIdentity
Returns whether the Quaternion is the identity Quaternion.
Declaration
public readonly bool IsIdentity { get; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
| Improve this Doc View SourceAdd(Quaternion, Quaternion)
Adds two Quaternions element-by-element.
Declaration
public static Quaternion Add(Quaternion value1, Quaternion value2)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | value1 | The first source Quaternion. |
Quaternion | value2 | The second source Quaternion. |
Returns
Type | Description |
---|---|
Quaternion | The result of adding the Quaternions. |
Concatenate(Quaternion, Quaternion)
Concatenates two Quaternions; the result represents the value1 rotation followed by the value2 rotation.
Declaration
public static Quaternion Concatenate(Quaternion value1, Quaternion value2)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | value1 | The first Quaternion rotation in the series. |
Quaternion | value2 | The second Quaternion rotation in the series. |
Returns
Type | Description |
---|---|
Quaternion | A new Quaternion representing the concatenation of the value1 rotation followed by the value2 rotation. |
Conjugate(Quaternion)
Creates the conjugate of a specified Quaternion.
Declaration
public static Quaternion Conjugate(Quaternion value)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | value | The Quaternion of which to return the conjugate. |
Returns
Type | Description |
---|---|
Quaternion | A new Quaternion that is the conjugate of the specified one. |
CreateFromAxisAngle(Vector3, Double)
Creates a Quaternion from a vector and an angle to rotate about the vector.
Declaration
public static Quaternion CreateFromAxisAngle(Vector3 axis, double angle)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | axis | The vector to rotate around. |
Double | angle | The angle, in radians, to rotate around the vector. |
Returns
Type | Description |
---|---|
Quaternion | The created Quaternion. |
CreateFromYawPitchRoll(Double, Double, Double)
Creates a new Quaternion from the given yaw, pitch, and roll, in radians.
Declaration
public static Quaternion CreateFromYawPitchRoll(double yaw, double pitch, double roll)
Parameters
Type | Name | Description |
---|---|---|
Double | yaw | The yaw angle, in radians, around the Y-axis. |
Double | pitch | The pitch angle, in radians, around the X-axis. |
Double | roll | The roll angle, in radians, around the Z-axis. |
Returns
Type | Description |
---|---|
Quaternion |
Divide(Quaternion, Quaternion)
Divides a Quaternion by another Quaternion.
Declaration
public static Quaternion Divide(Quaternion value1, Quaternion value2)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | value1 | The source Quaternion. |
Quaternion | value2 | The divisor. |
Returns
Type | Description |
---|---|
Quaternion | The result of the division. |
Dot(Quaternion, Quaternion)
Calculates the dot product of two Quaternions.
Declaration
public static double Dot(Quaternion quaternion1, Quaternion quaternion2)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | quaternion1 | The first source Quaternion. |
Quaternion | quaternion2 | The second source Quaternion. |
Returns
Type | Description |
---|---|
Double | The dot product of the Quaternions. |
Equals(Quaternion)
Returns a boolean indicating whether the given Quaternion is equal to this Quaternion instance.
Declaration
public bool Equals(Quaternion other)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | other | The Quaternion to compare this instance to. |
Returns
Type | Description |
---|---|
Boolean | True if the other Quaternion is equal to this instance; False otherwise. |
Equals(Object)
Returns a boolean indicating whether the given Object is equal to this Quaternion instance.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj | The Object to compare against. |
Returns
Type | Description |
---|---|
Boolean | True if the Object is equal to this Quaternion; False otherwise. |
Overrides
| Improve this Doc View SourceGetHashCode()
Returns the hash code for this instance.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | The hash code. |
Overrides
| Improve this Doc View SourceInverse(Quaternion)
Returns the inverse of a Quaternion.
Declaration
public static Quaternion Inverse(Quaternion value)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | value | The source Quaternion. |
Returns
Type | Description |
---|---|
Quaternion | The inverted Quaternion. |
Length()
Calculates the length of the Quaternion.
Declaration
public double Length()
Returns
Type | Description |
---|---|
Double | The computed length of the Quaternion. |
LengthSquared()
Calculates the length squared of the Quaternion. This operation is cheaper than Length().
Declaration
public double LengthSquared()
Returns
Type | Description |
---|---|
Double | The length squared of the Quaternion. |
Lerp(Quaternion, Quaternion, Double)
Linearly interpolates between two quaternions.
Declaration
public static Quaternion Lerp(Quaternion quaternion1, Quaternion quaternion2, double amount)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | quaternion1 | The first source Quaternion. |
Quaternion | quaternion2 | The second source Quaternion. |
Double | amount | The relative weight of the second source Quaternion in the interpolation. |
Returns
Type | Description |
---|---|
Quaternion | The interpolated Quaternion. |
Multiply(Quaternion, Double)
Multiplies a Quaternion by a scalar value.
Declaration
public static Quaternion Multiply(Quaternion value1, double value2)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | value1 | The source Quaternion. |
Double | value2 | The scalar value. |
Returns
Type | Description |
---|---|
Quaternion | The result of the multiplication. |
Multiply(Quaternion, Quaternion)
Multiplies two Quaternions together.
Declaration
public static Quaternion Multiply(Quaternion value1, Quaternion value2)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | value1 | The Quaternion on the left side of the multiplication. |
Quaternion | value2 | The Quaternion on the right side of the multiplication. |
Returns
Type | Description |
---|---|
Quaternion | The result of the multiplication. |
Negate(Quaternion)
Flips the sign of each component of the quaternion.
Declaration
public static Quaternion Negate(Quaternion value)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | value | The source Quaternion. |
Returns
Type | Description |
---|---|
Quaternion | The negated Quaternion. |
Normalize(Quaternion)
Divides each component of the Quaternion by the length of the Quaternion.
Declaration
public static Quaternion Normalize(Quaternion value)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | value | The source Quaternion. |
Returns
Type | Description |
---|---|
Quaternion | The normalized Quaternion. |
Slerp(Quaternion, Quaternion, Double)
Interpolates between two quaternions, using spherical linear interpolation.
Declaration
public static Quaternion Slerp(Quaternion quaternion1, Quaternion quaternion2, double amount)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | quaternion1 | The first source Quaternion. |
Quaternion | quaternion2 | The second source Quaternion. |
Double | amount | The relative weight of the second source Quaternion in the interpolation. |
Returns
Type | Description |
---|---|
Quaternion | The interpolated Quaternion. |
Subtract(Quaternion, Quaternion)
Subtracts one Quaternion from another.
Declaration
public static Quaternion Subtract(Quaternion value1, Quaternion value2)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | value1 | The first source Quaternion. |
Quaternion | value2 | The second Quaternion, to be subtracted from the first. |
Returns
Type | Description |
---|---|
Quaternion | The result of the subtraction. |
ToString()
Returns a String representing this Quaternion instance.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | The string representation. |
Overrides
Operators
| Improve this Doc View SourceAddition(Quaternion, Quaternion)
Adds two Quaternions element-by-element.
Declaration
public static Quaternion operator +(Quaternion value1, Quaternion value2)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | value1 | The first source Quaternion. |
Quaternion | value2 | The second source Quaternion. |
Returns
Type | Description |
---|---|
Quaternion | The result of adding the Quaternions. |
Division(Quaternion, Quaternion)
Divides a Quaternion by another Quaternion.
Declaration
public static Quaternion operator /(Quaternion value1, Quaternion value2)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | value1 | The source Quaternion. |
Quaternion | value2 | The divisor. |
Returns
Type | Description |
---|---|
Quaternion | The result of the division. |
Equality(Quaternion, Quaternion)
Returns a boolean indicating whether the two given Quaternions are equal.
Declaration
public static bool operator ==(Quaternion value1, Quaternion value2)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | value1 | The first Quaternion to compare. |
Quaternion | value2 | The second Quaternion to compare. |
Returns
Type | Description |
---|---|
Boolean | True if the Quaternions are equal; False otherwise. |
Inequality(Quaternion, Quaternion)
Returns a boolean indicating whether the two given Quaternions are not equal.
Declaration
public static bool operator !=(Quaternion value1, Quaternion value2)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | value1 | The first Quaternion to compare. |
Quaternion | value2 | The second Quaternion to compare. |
Returns
Type | Description |
---|---|
Boolean | True if the Quaternions are not equal; False if they are equal. |
Multiply(Quaternion, Double)
Multiplies a Quaternion by a scalar value.
Declaration
public static Quaternion operator *(Quaternion value1, double value2)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | value1 | The source Quaternion. |
Double | value2 | The scalar value. |
Returns
Type | Description |
---|---|
Quaternion | The result of the multiplication. |
Multiply(Quaternion, Quaternion)
Multiplies two Quaternions together.
Declaration
public static Quaternion operator *(Quaternion value1, Quaternion value2)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | value1 | The Quaternion on the left side of the multiplication. |
Quaternion | value2 | The Quaternion on the right side of the multiplication. |
Returns
Type | Description |
---|---|
Quaternion | The result of the multiplication. |
Subtraction(Quaternion, Quaternion)
Subtracts one Quaternion from another.
Declaration
public static Quaternion operator -(Quaternion value1, Quaternion value2)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | value1 | The first source Quaternion. |
Quaternion | value2 | The second Quaternion, to be subtracted from the first. |
Returns
Type | Description |
---|---|
Quaternion | The result of the subtraction. |
UnaryNegation(Quaternion)
Flips the sign of each component of the quaternion.
Declaration
public static Quaternion operator -(Quaternion value)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | value | The source Quaternion. |
Returns
Type | Description |
---|---|
Quaternion | The negated Quaternion. |