Struct QuaternionF
Represents a Quaternion (single precision).
Implements
Inherited Members
Namespace: Fusee.Math.Core
Assembly: Fusee.Math.Core.dll
Syntax
public struct QuaternionF : IEquatable<QuaternionF>Constructors
QuaternionF(float3, Single)
Construct a new Quaternion from vector and w components
Declaration
public QuaternionF(float3 v, float w)Parameters
| Type | Name | Description | 
|---|---|---|
| float3 | v | The vector part | 
| System.Single | w | The w part | 
QuaternionF(Single, Single, Single, Single)
Construct a new Quaternion
Declaration
public QuaternionF(float xx, float yy, float zz, float w)Parameters
| Type | Name | Description | 
|---|---|---|
| System.Single | xx | The xx component | 
| System.Single | yy | The yy component | 
| System.Single | zz | The zz component | 
| System.Single | w | The w component | 
Fields
Identity
Defines the identity quaternion.
Declaration
public static readonly QuaternionF IdentityField Value
| Type | Description | 
|---|---|
| QuaternionF | 
Properties
Item[Int32]
Sets/Gets value from given idx
Declaration
public float this[int idx] { get; set; }Parameters
| Type | Name | Description | 
|---|---|---|
| System.Int32 | idx | 
Property Value
| Type | Description | 
|---|---|
| System.Single | 
Length
Gets the length (magnitude) of the quaternion.
Declaration
public readonly float Length { get; }Property Value
| Type | Description | 
|---|---|
| System.Single | 
See Also
LengthSquared
Gets the square of the quaternion length (magnitude).
Declaration
public readonly float LengthSquared { get; }Property Value
| Type | Description | 
|---|---|
| System.Single | 
w
Gets and sets the w component of this instance.
Declaration
public float w { get; set; }Property Value
| Type | Description | 
|---|---|
| System.Single | 
x
Gets and sets the x component of this instance.
Declaration
public float x { get; set; }Property Value
| Type | Description | 
|---|---|
| System.Single | 
xyz
Gets and sets an Fusee.Math.float3 with the x, y and z components of this instance.
Declaration
public float3 xyz { get; set; }Property Value
| Type | Description | 
|---|---|
| float3 | 
y
Gets and sets the y component of this instance.
Declaration
public float y { get; set; }Property Value
| Type | Description | 
|---|---|
| System.Single | 
z
Gets and sets the z component of this instance.
Declaration
public float z { get; set; }Property Value
| Type | Description | 
|---|---|
| System.Single | 
Methods
Add(QuaternionF, QuaternionF)
Add two quaternions
Declaration
public static QuaternionF Add(QuaternionF left, QuaternionF right)Parameters
| Type | Name | Description | 
|---|---|---|
| QuaternionF | left | The first operand | 
| QuaternionF | right | The second operand | 
Returns
| Type | Description | 
|---|---|
| QuaternionF | The result of the addition | 
Conjugate()
Convert this quaternion to its conjugate.
Declaration
public QuaternionF Conjugate()Returns
| Type | Description | 
|---|---|
| QuaternionF | 
Conjugate(QuaternionF)
Get the conjugate of the given quaternion
Declaration
public static QuaternionF Conjugate(QuaternionF q)Parameters
| Type | Name | Description | 
|---|---|---|
| QuaternionF | q | The quaternion | 
Returns
| Type | Description | 
|---|---|
| QuaternionF | The conjugate of the given quaternion | 
CopySign(Single, Single)
a with the algebraic sign of b.
Declaration
public static float CopySign(float a, float b)Parameters
| Type | Name | Description | 
|---|---|---|
| System.Single | a | Absolut value | 
| System.Single | b | A positiv/negativ number or zero. | 
Returns
| Type | Description | 
|---|---|
| System.Single | Returns a with the algebraic sign of b. | 
Remarks
Takes a as an absolute value and multiplies it with: +1 for any positiv number for b, -1 for any negative number for b or 0 for 0 for b.
Equals(QuaternionF)
Compares this Quaternion instance to another Quaternion for equality.
Declaration
public bool Equals(QuaternionF other)Parameters
| Type | Name | Description | 
|---|---|---|
| QuaternionF | other | The other Quaternion to be used in the comparison. | 
Returns
| Type | Description | 
|---|---|
| System.Boolean | True if both instances are equal; false otherwise. | 
Equals(Object)
Compares this object instance to another object for equality.
Declaration
public override bool Equals(object other)Parameters
| Type | Name | Description | 
|---|---|---|
| System.Object | other | The other object to be used in the comparison. | 
Returns
| Type | Description | 
|---|---|
| System.Boolean | True if both objects are Quaternions of equal value. Otherwise it returns false. | 
Overrides
FromAxisAngle(float3, Single)
Build a quaternion from the given axis and angle
Declaration
public static QuaternionF FromAxisAngle(float3 axis, float angle)Parameters
| Type | Name | Description | 
|---|---|---|
| float3 | axis | The axis to rotate about | 
| System.Single | angle | The rotation angle in radians | 
Returns
| Type | Description | 
|---|---|
| QuaternionF | A normalized quaternion rotation. | 
FromEuler(float3, Boolean)
Convert Euler angle to Quaternion rotation.
Declaration
public static QuaternionF FromEuler(float3 e, bool inDegrees = false)Parameters
| Type | Name | Description | 
|---|---|---|
| float3 | e | Euler angle to convert. | 
| System.Boolean | inDegrees | Whether the angles are in degrees or radians. | 
Returns
| Type | Description | 
|---|---|
| QuaternionF | A Quaternion representing the euler angle passed to this method. | 
Remarks
The euler angle is assumed to be in common aviation order where the y axis is up. Thus x is pitch/attitude, y is yaw/heading, and z is roll/bank. In practice x is never out of [-PI/2, PI/2] while y and z may well be in the range of [-PI, PI].
See also the euclideanspace website.
FromEuler(Single, Single, Single, Boolean)
Convert Euler angle to Quaternion rotation.
Declaration
public static QuaternionF FromEuler(float x, float y, float z, bool inDegrees = false)Parameters
| Type | Name | Description | 
|---|---|---|
| System.Single | x | Angle around x. | 
| System.Single | y | Angle around x. | 
| System.Single | z | Angle around x. | 
| System.Boolean | inDegrees | Whether the angles are in degrees or radians. | 
Returns
| Type | Description | 
|---|---|
| QuaternionF | A Quaternion representing the euler angle passed to this method. | 
Remarks
The euler angle is assumed to be in common aviation order where the y axis is up. Thus x is pitch/attitude, y is yaw/heading, and z is roll/bank. In practice x is never out of [-PI/2, PI/2] while y and z may well be in the range of [-PI, PI].
See also the euclideanspace website.
FromRotationMatrix(float4x4)
Build a quaternion from a rotation matrix
Declaration
public static QuaternionF FromRotationMatrix(float4x4 mtx)Parameters
| Type | Name | Description | 
|---|---|---|
| float4x4 | mtx | 
Returns
| Type | Description | 
|---|---|
| QuaternionF | 
FromToRotation(float3, float3)
Build a quaternion with the shortest rotation from to.
Declaration
public static QuaternionF FromToRotation(float3 from, float3 to)Parameters
| Type | Name | Description | 
|---|---|---|
| float3 | from | |
| float3 | to | 
Returns
| Type | Description | 
|---|---|
| QuaternionF | A normalized quaternion rotation. | 
GetHashCode()
Provides the hash code for this object.
Declaration
public override int GetHashCode()Returns
| Type | Description | 
|---|---|
| System.Int32 | A hash code formed from the bitwise XOR of this objects members. | 
Overrides
Invert()
Convert this quaternion to its inverse.
Declaration
public QuaternionF Invert()Returns
| Type | Description | 
|---|---|
| QuaternionF | 
Invert(QuaternionF)
Get the inverse of the given quaternion
Declaration
public static QuaternionF Invert(QuaternionF q)Parameters
| Type | Name | Description | 
|---|---|---|
| QuaternionF | q | The quaternion to invert | 
Returns
| Type | Description | 
|---|---|
| QuaternionF | The inverse of the given quaternion | 
LookRotation(float3, float3)
Takes a lookAt and upDirection vector and returns a quaternion rotation.
Declaration
public static QuaternionF LookRotation(float3 lookAt, float3 upDirection)Parameters
| Type | Name | Description | 
|---|---|---|
| float3 | lookAt | The look at. | 
| float3 | upDirection | Up direction. | 
Returns
| Type | Description | 
|---|---|
| QuaternionF | A Quaternion. | 
Multiply(QuaternionF, QuaternionF)
Multiplies two instances.
Declaration
public static QuaternionF Multiply(QuaternionF left, QuaternionF right)Parameters
| Type | Name | Description | 
|---|---|---|
| QuaternionF | left | The first instance. | 
| QuaternionF | right | The second instance. | 
Returns
| Type | Description | 
|---|---|
| QuaternionF | A new instance containing the result of the calculation. | 
Multiply(QuaternionF, Single)
Multiplies an instance by a scalar.
Declaration
public static QuaternionF Multiply(QuaternionF quaternion, float scale)Parameters
| Type | Name | Description | 
|---|---|---|
| QuaternionF | quaternion | The instance. | 
| System.Single | scale | The scalar. | 
Returns
| Type | Description | 
|---|---|
| QuaternionF | A new instance containing the result of the calculation. | 
Normalize()
Scales the Quaternion to unit length.
Declaration
public QuaternionF Normalize()Returns
| Type | Description | 
|---|---|
| QuaternionF | 
Normalize(QuaternionF)
Scale the given quaternion to unit length
Declaration
public static QuaternionF Normalize(QuaternionF q)Parameters
| Type | Name | Description | 
|---|---|---|
| QuaternionF | q | The quaternion to normalize | 
Returns
| Type | Description | 
|---|---|
| QuaternionF | The normalized quaternion | 
Slerp(QuaternionF, QuaternionF, Single)
Do Spherical linear interpolation between two quaternions
Declaration
public static QuaternionF Slerp(QuaternionF q1, QuaternionF q2, float blend)Parameters
| Type | Name | Description | 
|---|---|---|
| QuaternionF | q1 | The first quaternion | 
| QuaternionF | q2 | The second quaternion | 
| System.Single | blend | The blend factor | 
Returns
| Type | Description | 
|---|---|
| QuaternionF | A smooth blend between the given quaternions | 
Sub(QuaternionF, QuaternionF)
Subtracts two instances.
Declaration
public static QuaternionF Sub(QuaternionF left, QuaternionF right)Parameters
| Type | Name | Description | 
|---|---|---|
| QuaternionF | left | The left instance. | 
| QuaternionF | right | The right instance. | 
Returns
| Type | Description | 
|---|---|
| QuaternionF | The result of the operation. | 
ToAxisAngle()
Convert this instance to an axis-angle representation.
Declaration
public float4 ToAxisAngle()Returns
| Type | Description | 
|---|---|
| float4 | A float4 that is the axis-angle representation of this quaternion. | 
ToAxisAngle(QuaternionF)
Angle axis representation of the given quaternion.
Declaration
public static float4 ToAxisAngle(QuaternionF quat)Parameters
| Type | Name | Description | 
|---|---|---|
| QuaternionF | quat | The quaternion to transform. | 
Returns
| Type | Description | 
|---|---|
| float4 | 
ToEuler(QuaternionF, Boolean)
Convert Quaternion rotation to Euler Angles.
Declaration
public static float3 ToEuler(QuaternionF q, bool inDegrees = false)Parameters
| Type | Name | Description | 
|---|---|---|
| QuaternionF | q | Quaternion rotation to convert. | 
| System.Boolean | inDegrees | Whether the angles shall be in degrees or radians. | 
Returns
| Type | Description | 
|---|---|
| float3 | 
Remarks
The euler angle is assumed to be in common aviation order where the y axis is up. Thus x is pitch/attitude, y is yaw/heading, and z is roll/bank. In practice x is never out of [-PI/2, PI/2] while y and z may well be in the range of [-PI, PI].
See also the euclidean space website.
ToRotationMatrix()
Converts the quaternion into a rotation matrix.
Declaration
public float4x4 ToRotationMatrix()Returns
| Type | Description | 
|---|---|
| float4x4 | 
ToRotationMatrix(QuaternionF)
Convert Quaternion to rotation matrix
Declaration
public static float4x4 ToRotationMatrix(QuaternionF q)Parameters
| Type | Name | Description | 
|---|---|---|
| QuaternionF | q | Quaternion to convert. | 
Returns
| Type | Description | 
|---|---|
| float4x4 | A matrix of type float4x4 from the passed Quaternion. | 
ToRotationMatrixFast()
Converts the quaternion into a rotation matrix.
Declaration
public float4x4 ToRotationMatrixFast()Returns
| Type | Description | 
|---|---|
| float4x4 | 
ToRotationMatrixFast(QuaternionF)
Constructs a rotation matrix from a given quaternion This uses some geometric algebra magic https://en.wikipedia.org/wiki/Geometric_algebra From: https://sourceforge.net/p/mjbworld/discussion/122133/thread/c59339da/#62ce
Declaration
public static float4x4 ToRotationMatrixFast(QuaternionF quat)Parameters
| Type | Name | Description | 
|---|---|---|
| QuaternionF | quat | Input quaternion | 
Returns
| Type | Description | 
|---|---|
| float4x4 | 
ToString()
Returns a System.String that represents the current Quaternion.
Declaration
public override string ToString()Returns
| Type | Description | 
|---|---|
| System.String | A string. | 
Overrides
ToString(IFormatProvider)
Returns a System.String that represents the current Quaternion.
Declaration
public string ToString(IFormatProvider provider)Parameters
| Type | Name | Description | 
|---|---|---|
| System.IFormatProvider | provider | Provides information about a specific culture. | 
Returns
| Type | Description | 
|---|---|
| System.String | A System.String that represents this instance. | 
Transform(float4, QuaternionF)
Transforms a vector by a quaternion rotation.
Declaration
public static float4 Transform(float4 vec, QuaternionF quat)Parameters
| Type | Name | Description | 
|---|---|---|
| float4 | vec | The vector to transform. | 
| QuaternionF | quat | The quaternion to rotate the vector by. | 
Returns
| Type | Description | 
|---|---|
| float4 | The result of the operation. | 
Operators
Addition(QuaternionF, QuaternionF)
Adds two instances.
Declaration
public static QuaternionF operator +(QuaternionF left, QuaternionF right)Parameters
| Type | Name | Description | 
|---|---|---|
| QuaternionF | left | The first instance. | 
| QuaternionF | right | The second instance. | 
Returns
| Type | Description | 
|---|---|
| QuaternionF | The result of the calculation. | 
Equality(QuaternionF, QuaternionF)
Compares two instances for equality.
Declaration
public static bool operator ==(QuaternionF left, QuaternionF right)Parameters
| Type | Name | Description | 
|---|---|---|
| QuaternionF | left | The first instance. | 
| QuaternionF | right | The second instance. | 
Returns
| Type | Description | 
|---|---|
| System.Boolean | True, if left equals right; false otherwise. | 
Inequality(QuaternionF, QuaternionF)
Compares two instances for inequality.
Declaration
public static bool operator !=(QuaternionF left, QuaternionF right)Parameters
| Type | Name | Description | 
|---|---|---|
| QuaternionF | left | The first instance. | 
| QuaternionF | right | The second instance. | 
Returns
| Type | Description | 
|---|---|
| System.Boolean | True, if left does not equal right; false otherwise. | 
Multiply(QuaternionF, QuaternionF)
Multiplies two instances.
Declaration
public static QuaternionF operator *(QuaternionF left, QuaternionF right)Parameters
| Type | Name | Description | 
|---|---|---|
| QuaternionF | left | The first instance. | 
| QuaternionF | right | The second instance. | 
Returns
| Type | Description | 
|---|---|
| QuaternionF | The result of the calculation. | 
Multiply(QuaternionF, Single)
Multiplies an instance by a scalar.
Declaration
public static QuaternionF operator *(QuaternionF quaternion, float scale)Parameters
| Type | Name | Description | 
|---|---|---|
| QuaternionF | quaternion | The instance. | 
| System.Single | scale | The scalar. | 
Returns
| Type | Description | 
|---|---|
| QuaternionF | A new instance containing the result of the calculation. | 
Multiply(Single, QuaternionF)
Multiplies an instance by a scalar.
Declaration
public static QuaternionF operator *(float scale, QuaternionF quaternion)Parameters
| Type | Name | Description | 
|---|---|---|
| System.Single | scale | The scalar. | 
| QuaternionF | quaternion | The instance. | 
Returns
| Type | Description | 
|---|---|
| QuaternionF | A new instance containing the result of the calculation. | 
Subtraction(QuaternionF, QuaternionF)
Subtracts two instances.
Declaration
public static QuaternionF operator -(QuaternionF left, QuaternionF right)Parameters
| Type | Name | Description | 
|---|---|---|
| QuaternionF | left | The first instance. | 
| QuaternionF | right | The second instance. | 
Returns
| Type | Description | 
|---|---|
| QuaternionF | The result of the calculation. |