Show / Hide Table of Contents

Struct Quaternion

Represents a Quaternion.

Implements
IEquatable<Quaternion>
Inherited Members
Object.Equals(Object, Object)
Object.ReferenceEquals(Object, Object)
Object.GetType()
Namespace: OpenTK
Assembly: OpenTK.dll
Syntax
[Serializable]
public struct Quaternion : IEquatable<Quaternion>

Constructors

Quaternion(Vector3)

Construct a new Quaternion from given Euler angles. The rotations will get applied in following order:

  1. Around X, 2. Around Y, 3. Around Z
Declaration
public Quaternion(Vector3 eulerAngles)
Parameters
Type Name Description
Vector3 eulerAngles

The counterclockwise euler angles as a Vector3

Quaternion(Vector3, Single)

Construct a new Quaternion from vector and w components

Declaration
public Quaternion(Vector3 v, float w)
Parameters
Type Name Description
Vector3 v

The vector part

Single w

The w part

Quaternion(Single, Single, Single)

Construct a new Quaternion from given Euler angles in radians. The rotations will get applied in following order:

  1. around X axis, 2. around Y axis, 3. around Z axis
Declaration
public Quaternion(float rotationX, float rotationY, float rotationZ)
Parameters
Type Name Description
Single rotationX

Counterclockwise rotation around X axis in radian

Single rotationY

Counterclockwise rotation around Y axis in radian

Single rotationZ

Counterclockwise rotation around Z axis in radian

Quaternion(Single, Single, Single, Single)

Construct a new Quaternion

Declaration
public Quaternion(float x, float y, float z, float w)
Parameters
Type Name Description
Single x

The x component

Single y

The y component

Single z

The z component

Single w

The w component

Fields

Identity

Defines the identity quaternion.

Declaration
public static readonly Quaternion Identity
Field Value
Type Description
Quaternion

W

The W component of this instance.

Declaration
public float W
Field Value
Type Description
Single

Xyz

The X, Y and Z components of this instance.

Declaration
public Vector3 Xyz
Field Value
Type Description
Vector3

Properties

Length

Gets the length (magnitude) of the quaternion.

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

LengthSquared

Gets the square of the quaternion length (magnitude).

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

X

Gets or sets the X component of this instance.

Declaration
public float X { get; set; }
Property Value
Type Description
Single

Y

Gets or sets the Y component of this instance.

Declaration
public float Y { get; set; }
Property Value
Type Description
Single

Z

Gets or sets the Z component of this instance.

Declaration
public float Z { get; set; }
Property Value
Type Description
Single

Methods

Add(Quaternion, Quaternion)

Add two quaternions

Declaration
public static Quaternion Add(Quaternion left, Quaternion right)
Parameters
Type Name Description
Quaternion left

The first operand

Quaternion right

The second operand

Returns
Type Description
Quaternion

The result of the addition

Add(ref Quaternion, ref Quaternion, out Quaternion)

Add two quaternions

Declaration
public static void Add(ref Quaternion left, ref Quaternion right, out Quaternion result)
Parameters
Type Name Description
Quaternion left

The first operand

Quaternion right

The second operand

Quaternion result

The result of the addition

Conjugate()

Inverts the Vector3 component of this Quaternion.

Declaration
public void Conjugate()

Conjugate(Quaternion)

Get the conjugate of the given quaternion

Declaration
public static Quaternion Conjugate(Quaternion q)
Parameters
Type Name Description
Quaternion q

The quaternion

Returns
Type Description
Quaternion

The conjugate of the given quaternion

Conjugate(ref Quaternion, out Quaternion)

Get the conjugate of the given quaternion

Declaration
public static void Conjugate(ref Quaternion q, out Quaternion result)
Parameters
Type Name Description
Quaternion q

The quaternion

Quaternion result

The conjugate of the given quaternion

Equals(Quaternion)

Compares this Quaternion instance to another Quaternion for equality.

Declaration
public bool Equals(Quaternion other)
Parameters
Type Name Description
Quaternion other

The other Quaternion to be used in the comparison.

Returns
Type Description
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
Object other

The other object to be used in the comparison.

Returns
Type Description
Boolean

True if both objects are Quaternions of equal value. Otherwise it returns false.

Overrides
ValueType.Equals(Object)

FromAxisAngle(Vector3, Single)

Build a quaternion from the given axis and angle in radians

Declaration
public static Quaternion FromAxisAngle(Vector3 axis, float angle)
Parameters
Type Name Description
Vector3 axis

The axis to rotate about

Single angle

The rotation angle in radians

Returns
Type Description
Quaternion

The equivalent quaternion

FromEulerAngles(Vector3)

Builds a Quaternion from the given euler angles in radians. The rotations will get applied in following order:

  1. X axis, 2. Y axis, 3. Z axis
Declaration
public static Quaternion FromEulerAngles(Vector3 eulerAngles)
Parameters
Type Name Description
Vector3 eulerAngles

The counterclockwise euler angles as a vector

Returns
Type Description
Quaternion

The equivalent Quaternion

FromEulerAngles(ref Vector3, out Quaternion)

Builds a Quaternion from the given euler angles in radians. The rotations will get applied in following order:

  1. Around X, 2. Around Y, 3. Around Z
Declaration
public static void FromEulerAngles(ref Vector3 eulerAngles, out Quaternion result)
Parameters
Type Name Description
Vector3 eulerAngles

The counterclockwise euler angles a vector

Quaternion result

The equivalent Quaternion

FromEulerAngles(Single, Single, Single)

Builds a Quaternion from the given euler angles in radians The rotations will get applied in following order:

  1. pitch (X axis), 2. yaw (Y axis), 3. roll (Z axis)
Declaration
public static Quaternion FromEulerAngles(float pitch, float yaw, float roll)
Parameters
Type Name Description
Single pitch

The pitch (attitude), counterclockwise rotation around X axis

Single yaw

The yaw (heading), counterclockwise rotation around Y axis

Single roll

The roll (bank), counterclockwise rotation around Z axis

Returns
Type Description
Quaternion

FromMatrix(Matrix3)

Builds a quaternion from the given rotation matrix

Declaration
public static Quaternion FromMatrix(Matrix3 matrix)
Parameters
Type Name Description
Matrix3 matrix

A rotation matrix

Returns
Type Description
Quaternion

The equivalent quaternion

FromMatrix(ref Matrix3, out Quaternion)

Builds a quaternion from the given rotation matrix

Declaration
public static void FromMatrix(ref Matrix3 matrix, out Quaternion result)
Parameters
Type Name Description
Matrix3 matrix

A rotation matrix

Quaternion result

The equivalent quaternion

GetHashCode()

Provides the hash code for this object.

Declaration
public override int GetHashCode()
Returns
Type Description
Int32

A hash code formed from the bitwise XOR of this objects members.

Overrides
ValueType.GetHashCode()

Invert()

Inverts this Quaternion.

Declaration
public void Invert()

Invert(Quaternion)

Get the inverse of the given quaternion

Declaration
public static Quaternion Invert(Quaternion q)
Parameters
Type Name Description
Quaternion q

The quaternion to invert

Returns
Type Description
Quaternion

The inverse of the given quaternion

Invert(ref Quaternion, out Quaternion)

Get the inverse of the given quaternion

Declaration
public static void Invert(ref Quaternion q, out Quaternion result)
Parameters
Type Name Description
Quaternion q

The quaternion to invert

Quaternion result

The inverse of the given quaternion

Inverted()

Returns the inverse of this Quaternion.

Declaration
public Quaternion Inverted()
Returns
Type Description
Quaternion

Multiply(Quaternion, Quaternion)

Multiplies two instances.

Declaration
public static Quaternion Multiply(Quaternion left, Quaternion right)
Parameters
Type Name Description
Quaternion left

The first instance.

Quaternion right

The second instance.

Returns
Type Description
Quaternion

A new instance containing the result of the calculation.

Multiply(Quaternion, Single)

Multiplies an instance by a scalar.

Declaration
public static Quaternion Multiply(Quaternion quaternion, float scale)
Parameters
Type Name Description
Quaternion quaternion

The instance.

Single scale

The scalar.

Returns
Type Description
Quaternion

A new instance containing the result of the calculation.

Multiply(ref Quaternion, ref Quaternion, out Quaternion)

Multiplies two instances.

Declaration
public static void Multiply(ref Quaternion left, ref Quaternion right, out Quaternion result)
Parameters
Type Name Description
Quaternion left

The first instance.

Quaternion right

The second instance.

Quaternion result

A new instance containing the result of the calculation.

Multiply(ref Quaternion, Single, out Quaternion)

Multiplies an instance by a scalar.

Declaration
public static void Multiply(ref Quaternion quaternion, float scale, out Quaternion result)
Parameters
Type Name Description
Quaternion quaternion

The instance.

Single scale

The scalar.

Quaternion result

A new instance containing the result of the calculation.

Normalize()

Scales the Quaternion to unit length.

Declaration
public void Normalize()

Normalize(Quaternion)

Scale the given quaternion to unit length

Declaration
public static Quaternion Normalize(Quaternion q)
Parameters
Type Name Description
Quaternion q

The quaternion to normalize

Returns
Type Description
Quaternion

The normalized quaternion

Normalize(ref Quaternion, out Quaternion)

Scale the given quaternion to unit length

Declaration
public static void Normalize(ref Quaternion q, out Quaternion result)
Parameters
Type Name Description
Quaternion q

The quaternion to normalize

Quaternion result

The normalized quaternion

Normalized()

Returns a copy of the Quaternion scaled to unit length.

Declaration
public Quaternion Normalized()
Returns
Type Description
Quaternion

Slerp(Quaternion, Quaternion, Single)

Do Spherical linear interpolation between two quaternions

Declaration
public static Quaternion Slerp(Quaternion q1, Quaternion q2, float blend)
Parameters
Type Name Description
Quaternion q1

The first quaternion

Quaternion q2

The second quaternion

Single blend

The blend factor

Returns
Type Description
Quaternion

A smooth blend between the given quaternions

Sub(Quaternion, Quaternion)

Subtracts two instances.

Declaration
public static Quaternion Sub(Quaternion left, Quaternion right)
Parameters
Type Name Description
Quaternion left

The left instance.

Quaternion right

The right instance.

Returns
Type Description
Quaternion

The result of the operation.

Sub(ref Quaternion, ref Quaternion, out Quaternion)

Subtracts two instances.

Declaration
public static void Sub(ref Quaternion left, ref Quaternion right, out Quaternion result)
Parameters
Type Name Description
Quaternion left

The left instance.

Quaternion right

The right instance.

Quaternion result

The result of the operation.

ToAxisAngle()

Convert this instance to an axis-angle representation.

Declaration
public Vector4 ToAxisAngle()
Returns
Type Description
Vector4

A Vector4 that is the axis-angle representation of this quaternion.

ToAxisAngle(out Vector3, out Single)

Convert the current quaternion to axis angle representation

Declaration
public void ToAxisAngle(out Vector3 axis, out float angle)
Parameters
Type Name Description
Vector3 axis

The resultant axis

Single angle

The resultant angle

ToString()

Returns a System.String that represents the current Quaternion.

Declaration
public override string ToString()
Returns
Type Description
String
Overrides
ValueType.ToString()

Operators

Addition(Quaternion, Quaternion)

Adds two instances.

Declaration
public static Quaternion operator +(Quaternion left, Quaternion right)
Parameters
Type Name Description
Quaternion left

The first instance.

Quaternion right

The second instance.

Returns
Type Description
Quaternion

The result of the calculation.

Equality(Quaternion, Quaternion)

Compares two instances for equality.

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

The first instance.

Quaternion right

The second instance.

Returns
Type Description
Boolean

True, if left equals right; false otherwise.

Inequality(Quaternion, Quaternion)

Compares two instances for inequality.

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

The first instance.

Quaternion right

The second instance.

Returns
Type Description
Boolean

True, if left does not equal right; false otherwise.

Multiply(Quaternion, Quaternion)

Multiplies two instances.

Declaration
public static Quaternion operator *(Quaternion left, Quaternion right)
Parameters
Type Name Description
Quaternion left

The first instance.

Quaternion right

The second instance.

Returns
Type Description
Quaternion

The result of the calculation.

Multiply(Quaternion, Single)

Multiplies an instance by a scalar.

Declaration
public static Quaternion operator *(Quaternion quaternion, float scale)
Parameters
Type Name Description
Quaternion quaternion

The instance.

Single scale

The scalar.

Returns
Type Description
Quaternion

A new instance containing the result of the calculation.

Multiply(Single, Quaternion)

Multiplies an instance by a scalar.

Declaration
public static Quaternion operator *(float scale, Quaternion quaternion)
Parameters
Type Name Description
Single scale

The scalar.

Quaternion quaternion

The instance.

Returns
Type Description
Quaternion

A new instance containing the result of the calculation.

Subtraction(Quaternion, Quaternion)

Subtracts two instances.

Declaration
public static Quaternion operator -(Quaternion left, Quaternion right)
Parameters
Type Name Description
Quaternion left

The first instance.

Quaternion right

The second instance.

Returns
Type Description
Quaternion

The result of the calculation.

Implements

System.IEquatable<T>
In This Article
Back to top Generated by DocFX