Struct quaternion
Inherited Members
Namespace: Unity.Mathematics
Syntax
[Serializable]
public struct quaternion : IEquatable<quaternion>, IFormattable
Constructors
quaternion(Single, Single, Single, Single)
Constructs a quaternion from four float values.
Declaration
public quaternion(float x, float y, float z, float w)
Parameters
Type | Name | Description |
---|---|---|
System.Single | x | |
System.Single | y | |
System.Single | z | |
System.Single | w |
quaternion(float3x3)
Constructs a unit quaternion from a float3x3 rotation matrix. The matrix must be orthonormal.
Declaration
public quaternion(float3x3 m)
Parameters
Type | Name | Description |
---|---|---|
float3x3 | m |
quaternion(float4)
Constructs a quaternion from float4 vector.
Declaration
public quaternion(float4 value)
Parameters
Type | Name | Description |
---|---|---|
float4 | value |
quaternion(float4x4)
Constructs a unit quaternion from an orthonormal float4x4 matrix.
Declaration
public quaternion(float4x4 m)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | m |
Fields
identity
A quaternion representing the identity transform.
Declaration
public static readonly quaternion identity
Field Value
Type | Description |
---|---|
quaternion |
value
Declaration
public float4 value
Field Value
Type | Description |
---|---|
float4 |
Methods
AxisAngle(float3, Single)
Returns a quaternion representing a rotation around a unit axis by an angle in radians. The rotation direction is clockwise when looking along the rotation axis towards the origin.
Declaration
public static quaternion AxisAngle(float3 axis, float angle)
Parameters
Type | Name | Description |
---|---|---|
float3 | axis | |
System.Single | angle |
Returns
Type | Description |
---|---|
quaternion |
Equals(Object)
Returns whether true if the quaternion is equal to a given quaternion, false otherwise.
Declaration
public override bool Equals(object x)
Parameters
Type | Name | Description |
---|---|---|
System.Object | x |
Returns
Type | Description |
---|---|
System.Boolean |
Overrides
Equals(quaternion)
Returns true if the quaternion is equal to a given quaternion, false otherwise.
Declaration
public bool Equals(quaternion x)
Parameters
Type | Name | Description |
---|---|---|
quaternion | x |
Returns
Type | Description |
---|---|
System.Boolean |
Implements
Euler(Single, Single, Single, RotationOrder)
Returns a quaternion constructed by first performing 3 rotations around the principal axes in a given order. All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin. When the rotation order is known at compile time, it is recommended for performance reasons to use specific Euler rotation constructors such as EulerZXY(...).
Declaration
public static quaternion Euler(float x, float y, float z, RotationOrder order = null)
Parameters
Type | Name | Description |
---|---|---|
System.Single | x | The rotation angle around the x-axis in radians. |
System.Single | y | The rotation angle around the y-axis in radians. |
System.Single | z | The rotation angle around the z-axis in radians. |
RotationOrder | order | The order in which the rotations are applied. |
Returns
Type | Description |
---|---|
quaternion |
Euler(float3, RotationOrder)
Returns a quaternion constructed by first performing 3 rotations around the principal axes in a given order. All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin. When the rotation order is known at compile time, it is recommended for performance reasons to use specific Euler rotation constructors such as EulerZXY(...).
Declaration
public static quaternion Euler(float3 xyz, RotationOrder order = null)
Parameters
Type | Name | Description |
---|---|---|
float3 | xyz | A float3 vector containing the rotation angles around the x-, y- and z-axis measures in radians. |
RotationOrder | order | The order in which the rotations are applied. |
Returns
Type | Description |
---|---|
quaternion |
EulerXYZ(Single, Single, Single)
Returns a quaternion constructed by first performing a rotation around the x-axis, then the y-axis and finally the z-axis. All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin.
Declaration
public static quaternion EulerXYZ(float x, float y, float z)
Parameters
Type | Name | Description |
---|---|---|
System.Single | x | The rotation angle around the x-axis in radians. |
System.Single | y | The rotation angle around the y-axis in radians. |
System.Single | z | The rotation angle around the z-axis in radians. |
Returns
Type | Description |
---|---|
quaternion |
EulerXYZ(float3)
Returns a quaternion constructed by first performing a rotation around the x-axis, then the y-axis and finally the z-axis. All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin.
Declaration
public static quaternion EulerXYZ(float3 xyz)
Parameters
Type | Name | Description |
---|---|---|
float3 | xyz | A float3 vector containing the rotation angles around the x-, y- and z-axis measures in radians. |
Returns
Type | Description |
---|---|
quaternion |
EulerXZY(Single, Single, Single)
Returns a quaternion constructed by first performing a rotation around the x-axis, then the z-axis and finally the y-axis. All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin.
Declaration
public static quaternion EulerXZY(float x, float y, float z)
Parameters
Type | Name | Description |
---|---|---|
System.Single | x | The rotation angle around the x-axis in radians. |
System.Single | y | The rotation angle around the y-axis in radians. |
System.Single | z | The rotation angle around the z-axis in radians. |
Returns
Type | Description |
---|---|
quaternion |
EulerXZY(float3)
Returns a quaternion constructed by first performing a rotation around the x-axis, then the z-axis and finally the y-axis. All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin.
Declaration
public static quaternion EulerXZY(float3 xyz)
Parameters
Type | Name | Description |
---|---|---|
float3 | xyz | A float3 vector containing the rotation angles around the x-, y- and z-axis measures in radians. |
Returns
Type | Description |
---|---|
quaternion |
EulerYXZ(Single, Single, Single)
Returns a quaternion constructed by first performing a rotation around the y-axis, then the x-axis and finally the z-axis. All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin.
Declaration
public static quaternion EulerYXZ(float x, float y, float z)
Parameters
Type | Name | Description |
---|---|---|
System.Single | x | The rotation angle around the x-axis in radians. |
System.Single | y | The rotation angle around the y-axis in radians. |
System.Single | z | The rotation angle around the z-axis in radians. |
Returns
Type | Description |
---|---|
quaternion |
EulerYXZ(float3)
Returns a quaternion constructed by first performing a rotation around the y-axis, then the x-axis and finally the z-axis. All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin.
Declaration
public static quaternion EulerYXZ(float3 xyz)
Parameters
Type | Name | Description |
---|---|---|
float3 | xyz | A float3 vector containing the rotation angles around the x-, y- and z-axis measures in radians. |
Returns
Type | Description |
---|---|
quaternion |
EulerYZX(Single, Single, Single)
Returns a quaternion constructed by first performing a rotation around the y-axis, then the z-axis and finally the x-axis. All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin.
Declaration
public static quaternion EulerYZX(float x, float y, float z)
Parameters
Type | Name | Description |
---|---|---|
System.Single | x | The rotation angle around the x-axis in radians. |
System.Single | y | The rotation angle around the y-axis in radians. |
System.Single | z | The rotation angle around the z-axis in radians. |
Returns
Type | Description |
---|---|
quaternion |
EulerYZX(float3)
Returns a quaternion constructed by first performing a rotation around the y-axis, then the z-axis and finally the x-axis. All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin.
Declaration
public static quaternion EulerYZX(float3 xyz)
Parameters
Type | Name | Description |
---|---|---|
float3 | xyz | A float3 vector containing the rotation angles around the x-, y- and z-axis measures in radians. |
Returns
Type | Description |
---|---|
quaternion |
EulerZXY(Single, Single, Single)
Returns a quaternion constructed by first performing a rotation around the z-axis, then the x-axis and finally the y-axis. All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin. This is the default order rotation order in Unity.
Declaration
public static quaternion EulerZXY(float x, float y, float z)
Parameters
Type | Name | Description |
---|---|---|
System.Single | x | The rotation angle around the x-axis in radians. |
System.Single | y | The rotation angle around the y-axis in radians. |
System.Single | z | The rotation angle around the z-axis in radians. |
Returns
Type | Description |
---|---|
quaternion |
EulerZXY(float3)
Returns a quaternion constructed by first performing a rotation around the z-axis, then the x-axis and finally the y-axis. All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin. This is the default order rotation order in Unity.
Declaration
public static quaternion EulerZXY(float3 xyz)
Parameters
Type | Name | Description |
---|---|---|
float3 | xyz | A float3 vector containing the rotation angles around the x-, y- and z-axis measures in radians. |
Returns
Type | Description |
---|---|
quaternion |
EulerZYX(Single, Single, Single)
Returns a quaternion constructed by first performing a rotation around the z-axis, then the y-axis and finally the x-axis. All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin.
Declaration
public static quaternion EulerZYX(float x, float y, float z)
Parameters
Type | Name | Description |
---|---|---|
System.Single | x | The rotation angle around the x-axis in radians. |
System.Single | y | The rotation angle around the y-axis in radians. |
System.Single | z | The rotation angle around the z-axis in radians. |
Returns
Type | Description |
---|---|
quaternion |
EulerZYX(float3)
Returns a quaternion constructed by first performing a rotation around the z-axis, then the y-axis and finally the x-axis. All rotation angles are in radians and clockwise when looking along the rotation axis towards the origin.
Declaration
public static quaternion EulerZYX(float3 xyz)
Parameters
Type | Name | Description |
---|---|---|
float3 | xyz | A float3 vector containing the rotation angles around the x-, y- and z-axis measures in radians. |
Returns
Type | Description |
---|---|
quaternion |
GetHashCode()
Returns a hash code for the quaternion.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 |
Overrides
LookRotation(float3, float3)
Returns a quaternion view rotation given a unit length forward vector and a unit length up vector. The two input vectors are assumed to be unit length and not collinear. If these assumptions are not met use float3x3.LookRotationSafe instead.
Declaration
public static quaternion LookRotation(float3 forward, float3 up)
Parameters
Type | Name | Description |
---|---|---|
float3 | forward | |
float3 | up |
Returns
Type | Description |
---|---|
quaternion |
LookRotationSafe(float3, float3)
Returns a quaternion view rotation given a forward vector and an up vector. The two input vectors are not assumed to be unit length. If the magnitude of either of the vectors is so extreme that the calculation cannot be carried out reliably or the vectors are collinear, the identity will be returned instead.
Declaration
public static quaternion LookRotationSafe(float3 forward, float3 up)
Parameters
Type | Name | Description |
---|---|---|
float3 | forward | |
float3 | up |
Returns
Type | Description |
---|---|
quaternion |
RotateX(Single)
Returns a float4x4 matrix that rotates around the x-axis by a given number of radians.
Declaration
public static quaternion RotateX(float angle)
Parameters
Type | Name | Description |
---|---|---|
System.Single | angle | The clockwise rotation angle when looking along the x-axis towards the origin in radians. |
Returns
Type | Description |
---|---|
quaternion |
RotateY(Single)
Returns a float4x4 matrix that rotates around the y-axis by a given number of radians.
Declaration
public static quaternion RotateY(float angle)
Parameters
Type | Name | Description |
---|---|---|
System.Single | angle | The clockwise rotation angle when looking along the y-axis towards the origin in radians. |
Returns
Type | Description |
---|---|
quaternion |
RotateZ(Single)
Returns a float4x4 matrix that rotates around the z-axis by a given number of radians.
Declaration
public static quaternion RotateZ(float angle)
Parameters
Type | Name | Description |
---|---|---|
System.Single | angle | The clockwise rotation angle when looking along the z-axis towards the origin in radians. |
Returns
Type | Description |
---|---|
quaternion |
ToString()
Returns a string representation of the quaternion.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String |
Overrides
ToString(String, IFormatProvider)
Returns a string representation of the quaternion using a specified format and culture-specific format information.
Declaration
public string ToString(string format, IFormatProvider formatProvider)
Parameters
Type | Name | Description |
---|---|---|
System.String | format | |
System.IFormatProvider | formatProvider |
Returns
Type | Description |
---|---|
System.String |
Implements
Operators
Implicit(Quaternion to quaternion)
Declaration
public static implicit operator quaternion(Quaternion q)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | q |
Returns
Type | Description |
---|---|
quaternion |
Implicit(float4 to quaternion)
Implicitly converts a float4 vector to a quaternion.
Declaration
public static implicit operator quaternion(float4 v)
Parameters
Type | Name | Description |
---|---|---|
float4 | v |
Returns
Type | Description |
---|---|
quaternion |
Implicit(quaternion to Quaternion)
Declaration
public static implicit operator Quaternion(quaternion q)
Parameters
Type | Name | Description |
---|---|---|
quaternion | q |
Returns
Type | Description |
---|---|
Quaternion |