Table of Contents

Struct Quaternion

Namespace
Microsoft.Xna.Framework
Assembly
MonoGame.Framework.dll

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

value Vector3

The x, y, z coordinates in 3d-space.

w float

The rotation component.

Quaternion(Vector4)

Constructs a quaternion from Vector4.

public Quaternion(Vector4 value)

Parameters

value Vector4

The 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 float

The x coordinate in 3d-space.

y float

The y coordinate in 3d-space.

z float

The z coordinate in 3d-space.

w float

The rotation component.

Fields

W

The rotation component of this Quaternion.

[DataMember]
public float W

Field Value

float

X

The x coordinate of this Quaternion.

[DataMember]
public float X

Field Value

float

Y

The y coordinate of this Quaternion.

[DataMember]
public float Y

Field Value

float

Z

The z coordinate of this Quaternion.

[DataMember]
public float Z

Field Value

float

Properties

Identity

Returns a quaternion representing no rotation.

public static Quaternion Identity { get; }

Property Value

Quaternion

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 Quaternion

Source Quaternion.

quaternion2 Quaternion

Source 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 Quaternion

Source Quaternion.

quaternion2 Quaternion

Source Quaternion.

result Quaternion

The 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 Quaternion

The first Quaternion to concatenate.

value2 Quaternion

The second Quaternion to concatenate.

Returns

Quaternion

The result of rotation of value1 followed by value2 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 Quaternion

The first Quaternion to concatenate.

value2 Quaternion

The second Quaternion to concatenate.

result Quaternion

The result of rotation of value1 followed by value2 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 Quaternion

The 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 Quaternion

The quaternion which values will be used to create the conjugated version.

result Quaternion

The 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

axis Vector3

The axis of rotation.

angle float

The angle in radians.

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 Vector3

The axis of rotation.

angle float

The angle in radians.

result Quaternion

The 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 Matrix

The 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 Matrix

The rotation matrix.

result Quaternion

A 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 float

Yaw around the y axis in radians.

pitch float

Pitch around the x axis in radians.

roll float

Roll 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 float

Yaw around the y axis in radians.

pitch float

Pitch around the x axis in radians.

roll float

Roll around the z axis in radians.

result Quaternion

A new quaternion from the concatenated yaw, pitch, and roll angles as an output parameter.

Deconstruct(out float, out float, out float, out float)

Deconstruction method for Quaternion.

public void Deconstruct(out float x, out float y, out float z, out float w)

Parameters

x float

The x coordinate in 3d-space.

y float

The y coordinate in 3d-space.

z float

The z coordinate in 3d-space.

w float

The rotation component.

Divide(Quaternion, Quaternion)

Divides a Quaternion by the other Quaternion.

public static Quaternion Divide(Quaternion quaternion1, Quaternion quaternion2)

Parameters

quaternion1 Quaternion

Source Quaternion.

quaternion2 Quaternion

Divisor 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 Quaternion

Source Quaternion.

quaternion2 Quaternion

Divisor Quaternion.

result Quaternion

The 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 Quaternion

The first quaternion.

quaternion2 Quaternion

The 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 Quaternion

The first quaternion.

quaternion2 Quaternion

The second quaternion.

result float

The 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 Quaternion

The 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

obj object

The object to compare.

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 Quaternion

Source 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 Quaternion

Source Quaternion.

result Quaternion

The 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 Quaternion

Source Quaternion.

quaternion2 Quaternion

Source Quaternion.

amount float

The blend amount where 0 returns quaternion1 and 1 quaternion2.

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 Quaternion

Source Quaternion.

quaternion2 Quaternion

Source Quaternion.

amount float

The blend amount where 0 returns quaternion1 and 1 quaternion2.

result Quaternion

The 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 Quaternion

Source Quaternion.

quaternion2 Quaternion

Source 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 Quaternion

Source Quaternion.

scaleFactor float

Scalar 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 Quaternion

Source Quaternion.

quaternion2 Quaternion

Source Quaternion.

result Quaternion

The 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 Quaternion

Source Quaternion.

scaleFactor float

Scalar value.

result Quaternion

The 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 Quaternion

Source 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 Quaternion

Source Quaternion.

result Quaternion

The 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 Quaternion

Source 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 Quaternion

Source Quaternion.

result Quaternion

The 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 Quaternion

Source Quaternion.

quaternion2 Quaternion

Source Quaternion.

amount float

The blend amount where 0 returns quaternion1 and 1 quaternion2.

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 Quaternion

Source Quaternion.

quaternion2 Quaternion

Source Quaternion.

amount float

The blend amount where 0 returns quaternion1 and 1 quaternion2.

result Quaternion

The 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 Quaternion

Source Quaternion.

quaternion2 Quaternion

Source 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 Quaternion

Source Quaternion.

quaternion2 Quaternion

Source Quaternion.

result Quaternion

The result of the quaternion subtraction as an output parameter.

ToNumerics()

Returns a Quaternion.

public Quaternion ToNumerics()

Returns

Quaternion

ToString()

Returns a string representation of this Quaternion in the format: {X:[X] Y:[Y] Z:[Z] W:[W]}

public override string ToString()

Returns

string

A string representation of this Quaternion.

ToVector4()

Gets a Vector4 representation for this object.

public Vector4 ToVector4()

Returns

Vector4

A Vector4 representation for this object.

Operators

operator +(Quaternion, Quaternion)

Adds two quaternions.

public static Quaternion operator +(Quaternion quaternion1, Quaternion quaternion2)

Parameters

quaternion1 Quaternion

Source Quaternion on the left of the add sign.

quaternion2 Quaternion

Source 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 Quaternion

Source Quaternion on the left of the div sign.

quaternion2 Quaternion

Divisor 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 Quaternion

Quaternion instance on the left of the equal sign.

quaternion2 Quaternion

Quaternion 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 Quaternion

The converted value.

Returns

Quaternion

operator !=(Quaternion, Quaternion)

Compares whether two Quaternion instances are not equal.

public static bool operator !=(Quaternion quaternion1, Quaternion quaternion2)

Parameters

quaternion1 Quaternion

Quaternion instance on the left of the not equal sign.

quaternion2 Quaternion

Quaternion 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 Quaternion

Source Quaternion on the left of the mul sign.

quaternion2 Quaternion

Source 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 Quaternion

Source Vector3 on the left of the mul sign.

scaleFactor float

Scalar 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 Quaternion

Source Vector3 on the left of the sub sign.

quaternion2 Quaternion

Source 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 Quaternion

Source Quaternion on the right of the sub sign.

Returns

Quaternion

The result of the quaternion negation.