Struct Quaternion
An efficient mathematical representation for three dimensional rotations.
[DataContract]
public struct Quaternion : IEquatable<Quaternion>
- Implements
- Inherited Members
Constructors
Quaternion(Vector3, float)
Constructs a quaternion with X, Y, Z from Vector3 and rotation component from a scalar.
public Quaternion(Vector3 value, float w)
Parameters
Quaternion(Vector4)
Constructs a quaternion from Vector4.
public Quaternion(Vector4 value)
Parameters
value
Vector4The x, y, z coordinates in 3d-space and the rotation component.
Quaternion(float, float, float, float)
Constructs a quaternion with X, Y, Z and W from four values.
public Quaternion(float x, float y, float z, float w)
Parameters
x
floatThe x coordinate in 3d-space.
y
floatThe y coordinate in 3d-space.
z
floatThe z coordinate in 3d-space.
w
floatThe rotation component.
Fields
W
The rotation component of this Quaternion.
[DataMember]
public float W
Field Value
X
The x coordinate of this Quaternion.
[DataMember]
public float X
Field Value
Y
The y coordinate of this Quaternion.
[DataMember]
public float Y
Field Value
Z
The z coordinate of this Quaternion.
[DataMember]
public float Z
Field Value
Properties
Identity
Returns a quaternion representing no rotation.
public static Quaternion Identity { get; }
Property Value
Methods
Add(Quaternion, Quaternion)
Creates a new Quaternion that contains the sum of two quaternions.
public static Quaternion Add(Quaternion quaternion1, Quaternion quaternion2)
Parameters
quaternion1
QuaternionSource Quaternion.
quaternion2
QuaternionSource Quaternion.
Returns
- Quaternion
The result of the quaternion addition.
Add(ref Quaternion, ref Quaternion, out Quaternion)
Creates a new Quaternion that contains the sum of two quaternions.
public static void Add(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result)
Parameters
quaternion1
QuaternionSource Quaternion.
quaternion2
QuaternionSource Quaternion.
result
QuaternionThe result of the quaternion addition as an output parameter.
Concatenate(Quaternion, Quaternion)
Creates a new Quaternion that contains concatenation between two quaternion.
public static Quaternion Concatenate(Quaternion value1, Quaternion value2)
Parameters
value1
QuaternionThe first Quaternion to concatenate.
value2
QuaternionThe second Quaternion to concatenate.
Returns
- Quaternion
The result of rotation of
value1
followed byvalue2
rotation.
Concatenate(ref Quaternion, ref Quaternion, out Quaternion)
Creates a new Quaternion that contains concatenation between two quaternion.
public static void Concatenate(ref Quaternion value1, ref Quaternion value2, out Quaternion result)
Parameters
value1
QuaternionThe first Quaternion to concatenate.
value2
QuaternionThe second Quaternion to concatenate.
result
QuaternionThe result of rotation of
value1
followed byvalue2
rotation as an output parameter.
Conjugate()
Transforms this quaternion into its conjugated version.
public void Conjugate()
Conjugate(Quaternion)
Creates a new Quaternion that contains conjugated version of the specified quaternion.
public static Quaternion Conjugate(Quaternion value)
Parameters
value
QuaternionThe quaternion which values will be used to create the conjugated version.
Returns
- Quaternion
The conjugate version of the specified quaternion.
Conjugate(ref Quaternion, out Quaternion)
Creates a new Quaternion that contains conjugated version of the specified quaternion.
public static void Conjugate(ref Quaternion value, out Quaternion result)
Parameters
value
QuaternionThe quaternion which values will be used to create the conjugated version.
result
QuaternionThe conjugated version of the specified quaternion as an output parameter.
CreateFromAxisAngle(Vector3, float)
Creates a new Quaternion from the specified axis and angle.
public static Quaternion CreateFromAxisAngle(Vector3 axis, float angle)
Parameters
Returns
- Quaternion
The new quaternion builded from axis and angle.
CreateFromAxisAngle(ref Vector3, float, out Quaternion)
Creates a new Quaternion from the specified axis and angle.
public static void CreateFromAxisAngle(ref Vector3 axis, float angle, out Quaternion result)
Parameters
axis
Vector3The axis of rotation.
angle
floatThe angle in radians.
result
QuaternionThe new quaternion builded from axis and angle as an output parameter.
CreateFromRotationMatrix(Matrix)
Creates a new Quaternion from the specified Matrix.
public static Quaternion CreateFromRotationMatrix(Matrix matrix)
Parameters
matrix
MatrixThe rotation matrix.
Returns
- Quaternion
A quaternion composed from the rotation part of the matrix.
CreateFromRotationMatrix(ref Matrix, out Quaternion)
Creates a new Quaternion from the specified Matrix.
public static void CreateFromRotationMatrix(ref Matrix matrix, out Quaternion result)
Parameters
matrix
MatrixThe rotation matrix.
result
QuaternionA quaternion composed from the rotation part of the matrix as an output parameter.
CreateFromYawPitchRoll(float, float, float)
Creates a new Quaternion from the specified yaw, pitch and roll angles.
public static Quaternion CreateFromYawPitchRoll(float yaw, float pitch, float roll)
Parameters
yaw
floatYaw around the y axis in radians.
pitch
floatPitch around the x axis in radians.
roll
floatRoll around the z axis in radians.
Returns
- Quaternion
A new quaternion from the concatenated yaw, pitch, and roll angles.
CreateFromYawPitchRoll(float, float, float, out Quaternion)
Creates a new Quaternion from the specified yaw, pitch and roll angles.
public static void CreateFromYawPitchRoll(float yaw, float pitch, float roll, out Quaternion result)
Parameters
yaw
floatYaw around the y axis in radians.
pitch
floatPitch around the x axis in radians.
roll
floatRoll around the z axis in radians.
result
QuaternionA new quaternion from the concatenated yaw, pitch, and roll angles as an output parameter.
Deconstruct(out float, out float, out float, out float)
public void Deconstruct(out float x, out float y, out float z, out float w)
Parameters
Divide(Quaternion, Quaternion)
Divides a Quaternion by the other Quaternion.
public static Quaternion Divide(Quaternion quaternion1, Quaternion quaternion2)
Parameters
quaternion1
QuaternionSource Quaternion.
quaternion2
QuaternionDivisor Quaternion.
Returns
- Quaternion
The result of dividing the quaternions.
Divide(ref Quaternion, ref Quaternion, out Quaternion)
Divides a Quaternion by the other Quaternion.
public static void Divide(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result)
Parameters
quaternion1
QuaternionSource Quaternion.
quaternion2
QuaternionDivisor Quaternion.
result
QuaternionThe result of dividing the quaternions as an output parameter.
Dot(Quaternion, Quaternion)
Returns a dot product of two quaternions.
public static float Dot(Quaternion quaternion1, Quaternion quaternion2)
Parameters
quaternion1
QuaternionThe first quaternion.
quaternion2
QuaternionThe second quaternion.
Returns
- float
The dot product of two quaternions.
Dot(ref Quaternion, ref Quaternion, out float)
Returns a dot product of two quaternions.
public static void Dot(ref Quaternion quaternion1, ref Quaternion quaternion2, out float result)
Parameters
quaternion1
QuaternionThe first quaternion.
quaternion2
QuaternionThe second quaternion.
result
floatThe dot product of two quaternions as an output parameter.
Equals(Quaternion)
Compares whether current instance is equal to specified Quaternion.
public bool Equals(Quaternion other)
Parameters
other
QuaternionThe Quaternion to compare.
Returns
- bool
true
if the instances are equal;false
otherwise.
Equals(object)
Compares whether current instance is equal to specified object.
public override bool Equals(object obj)
Parameters
Returns
- bool
true
if the instances are equal;false
otherwise.
GetHashCode()
Gets the hash code of this Quaternion.
public override int GetHashCode()
Returns
- int
Hash code of this Quaternion.
Inverse(Quaternion)
Returns the inverse quaternion which represents the opposite rotation.
public static Quaternion Inverse(Quaternion quaternion)
Parameters
quaternion
QuaternionSource Quaternion.
Returns
- Quaternion
The inverse quaternion.
Inverse(ref Quaternion, out Quaternion)
Returns the inverse quaternion which represents the opposite rotation.
public static void Inverse(ref Quaternion quaternion, out Quaternion result)
Parameters
quaternion
QuaternionSource Quaternion.
result
QuaternionThe inverse quaternion as an output parameter.
Length()
Returns the magnitude of the quaternion components.
public float Length()
Returns
- float
The magnitude of the quaternion components.
LengthSquared()
Returns the squared magnitude of the quaternion components.
public float LengthSquared()
Returns
- float
The squared magnitude of the quaternion components.
Lerp(Quaternion, Quaternion, float)
Performs a linear blend between two quaternions.
public static Quaternion Lerp(Quaternion quaternion1, Quaternion quaternion2, float amount)
Parameters
quaternion1
QuaternionSource Quaternion.
quaternion2
QuaternionSource Quaternion.
amount
floatThe blend amount where 0 returns
quaternion1
and 1quaternion2
.
Returns
- Quaternion
The result of linear blending between two quaternions.
Lerp(ref Quaternion, ref Quaternion, float, out Quaternion)
Performs a linear blend between two quaternions.
public static void Lerp(ref Quaternion quaternion1, ref Quaternion quaternion2, float amount, out Quaternion result)
Parameters
quaternion1
QuaternionSource Quaternion.
quaternion2
QuaternionSource Quaternion.
amount
floatThe blend amount where 0 returns
quaternion1
and 1quaternion2
.result
QuaternionThe result of linear blending between two quaternions as an output parameter.
Multiply(Quaternion, Quaternion)
Creates a new Quaternion that contains a multiplication of two quaternions.
public static Quaternion Multiply(Quaternion quaternion1, Quaternion quaternion2)
Parameters
quaternion1
QuaternionSource Quaternion.
quaternion2
QuaternionSource Quaternion.
Returns
- Quaternion
The result of the quaternion multiplication.
Multiply(Quaternion, float)
Creates a new Quaternion that contains a multiplication of Quaternion and a scalar.
public static Quaternion Multiply(Quaternion quaternion1, float scaleFactor)
Parameters
quaternion1
QuaternionSource Quaternion.
scaleFactor
floatScalar value.
Returns
- Quaternion
The result of the quaternion multiplication with a scalar.
Multiply(ref Quaternion, ref Quaternion, out Quaternion)
Creates a new Quaternion that contains a multiplication of two quaternions.
public static void Multiply(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result)
Parameters
quaternion1
QuaternionSource Quaternion.
quaternion2
QuaternionSource Quaternion.
result
QuaternionThe result of the quaternion multiplication as an output parameter.
Multiply(ref Quaternion, float, out Quaternion)
Creates a new Quaternion that contains a multiplication of Quaternion and a scalar.
public static void Multiply(ref Quaternion quaternion1, float scaleFactor, out Quaternion result)
Parameters
quaternion1
QuaternionSource Quaternion.
scaleFactor
floatScalar value.
result
QuaternionThe result of the quaternion multiplication with a scalar as an output parameter.
Negate(Quaternion)
Flips the sign of the all the quaternion components.
public static Quaternion Negate(Quaternion quaternion)
Parameters
quaternion
QuaternionSource Quaternion.
Returns
- Quaternion
The result of the quaternion negation.
Negate(ref Quaternion, out Quaternion)
Flips the sign of the all the quaternion components.
public static void Negate(ref Quaternion quaternion, out Quaternion result)
Parameters
quaternion
QuaternionSource Quaternion.
result
QuaternionThe result of the quaternion negation as an output parameter.
Normalize()
Scales the quaternion magnitude to unit length.
public void Normalize()
Normalize(Quaternion)
Scales the quaternion magnitude to unit length.
public static Quaternion Normalize(Quaternion quaternion)
Parameters
quaternion
QuaternionSource Quaternion.
Returns
- Quaternion
The unit length quaternion.
Normalize(ref Quaternion, out Quaternion)
Scales the quaternion magnitude to unit length.
public static void Normalize(ref Quaternion quaternion, out Quaternion result)
Parameters
quaternion
QuaternionSource Quaternion.
result
QuaternionThe unit length quaternion an output parameter.
Slerp(Quaternion, Quaternion, float)
Performs a spherical linear blend between two quaternions.
public static Quaternion Slerp(Quaternion quaternion1, Quaternion quaternion2, float amount)
Parameters
quaternion1
QuaternionSource Quaternion.
quaternion2
QuaternionSource Quaternion.
amount
floatThe blend amount where 0 returns
quaternion1
and 1quaternion2
.
Returns
- Quaternion
The result of spherical linear blending between two quaternions.
Slerp(ref Quaternion, ref Quaternion, float, out Quaternion)
Performs a spherical linear blend between two quaternions.
public static void Slerp(ref Quaternion quaternion1, ref Quaternion quaternion2, float amount, out Quaternion result)
Parameters
quaternion1
QuaternionSource Quaternion.
quaternion2
QuaternionSource Quaternion.
amount
floatThe blend amount where 0 returns
quaternion1
and 1quaternion2
.result
QuaternionThe result of spherical linear blending between two quaternions as an output parameter.
Subtract(Quaternion, Quaternion)
Creates a new Quaternion that contains subtraction of one Quaternion from another.
public static Quaternion Subtract(Quaternion quaternion1, Quaternion quaternion2)
Parameters
quaternion1
QuaternionSource Quaternion.
quaternion2
QuaternionSource Quaternion.
Returns
- Quaternion
The result of the quaternion subtraction.
Subtract(ref Quaternion, ref Quaternion, out Quaternion)
Creates a new Quaternion that contains subtraction of one Quaternion from another.
public static void Subtract(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result)
Parameters
quaternion1
QuaternionSource Quaternion.
quaternion2
QuaternionSource Quaternion.
result
QuaternionThe result of the quaternion subtraction as an output parameter.
ToNumerics()
Returns a Quaternion.
public Quaternion ToNumerics()
Returns
ToString()
public override string ToString()
Returns
- string
A string representation of this Quaternion.
ToVector4()
Gets a Vector4 representation for this object.
public Vector4 ToVector4()
Returns
Operators
operator +(Quaternion, Quaternion)
Adds two quaternions.
public static Quaternion operator +(Quaternion quaternion1, Quaternion quaternion2)
Parameters
quaternion1
QuaternionSource Quaternion on the left of the add sign.
quaternion2
QuaternionSource Quaternion on the right of the add sign.
Returns
- Quaternion
Sum of the vectors.
operator /(Quaternion, Quaternion)
Divides a Quaternion by the other Quaternion.
public static Quaternion operator /(Quaternion quaternion1, Quaternion quaternion2)
Parameters
quaternion1
QuaternionSource Quaternion on the left of the div sign.
quaternion2
QuaternionDivisor Quaternion on the right of the div sign.
Returns
- Quaternion
The result of dividing the quaternions.
operator ==(Quaternion, Quaternion)
Compares whether two Quaternion instances are equal.
public static bool operator ==(Quaternion quaternion1, Quaternion quaternion2)
Parameters
quaternion1
QuaternionQuaternion instance on the left of the equal sign.
quaternion2
QuaternionQuaternion instance on the right of the equal sign.
Returns
- bool
true
if the instances are equal;false
otherwise.
implicit operator Quaternion(Quaternion)
Converts a Quaternion to a Quaternion.
public static implicit operator Quaternion(Quaternion value)
Parameters
value
QuaternionThe converted value.
Returns
operator !=(Quaternion, Quaternion)
Compares whether two Quaternion instances are not equal.
public static bool operator !=(Quaternion quaternion1, Quaternion quaternion2)
Parameters
quaternion1
QuaternionQuaternion instance on the left of the not equal sign.
quaternion2
QuaternionQuaternion instance on the right of the not equal sign.
Returns
- bool
true
if the instances are not equal;false
otherwise.
operator *(Quaternion, Quaternion)
Multiplies two quaternions.
public static Quaternion operator *(Quaternion quaternion1, Quaternion quaternion2)
Parameters
quaternion1
QuaternionSource Quaternion on the left of the mul sign.
quaternion2
QuaternionSource Quaternion on the right of the mul sign.
Returns
- Quaternion
Result of the quaternions multiplication.
operator *(Quaternion, float)
Multiplies the components of quaternion by a scalar.
public static Quaternion operator *(Quaternion quaternion1, float scaleFactor)
Parameters
quaternion1
QuaternionSource Vector3 on the left of the mul sign.
scaleFactor
floatScalar value on the right of the mul sign.
Returns
- Quaternion
Result of the quaternion multiplication with a scalar.
operator -(Quaternion, Quaternion)
Subtracts a Quaternion from a Quaternion.
public static Quaternion operator -(Quaternion quaternion1, Quaternion quaternion2)
Parameters
quaternion1
QuaternionSource Vector3 on the left of the sub sign.
quaternion2
QuaternionSource Vector3 on the right of the sub sign.
Returns
- Quaternion
Result of the quaternion subtraction.
operator -(Quaternion)
Flips the sign of the all the quaternion components.
public static Quaternion operator -(Quaternion quaternion)
Parameters
quaternion
QuaternionSource Quaternion on the right of the sub sign.
Returns
- Quaternion
The result of the quaternion negation.