Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


quaternion

A quaternion type for representing rotations.
Read time 3 minutesLast updated 11 days ago

Definition

public struct quaternion : IEquatable<quaternion>, IFormattable

Fields

Value

Description

valueThe quaternion component values.

Static Fields

Value

Description

identityA quaternion representing the identity transform.

Constructors

Constructor

Description

quaternion(System.Single,System.Single,System.Single,System.Single)Constructs a quaternion from four float values.
quaternion(Unity.Mathematics.float3x3)Constructs a unit quaternion from a float3x3 rotation matrix. The matrix must be orthonormal.
quaternion(Unity.Mathematics.float4)Constructs a quaternion from float4 vector.
quaternion(Unity.Mathematics.float4x4)Constructs a unit quaternion from an orthonormal float4x4 matrix.

Methods

Method

Description

EqualsReturns whether true if the quaternion is equal to a given quaternion, false otherwise.
GetHashCodeReturns a hash code for the quaternion.
ToStringReturns a string representation of the quaternion.

Static Methods

Method

Description

AxisAngleReturns 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.
EulerReturns 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(...).
EulerXYZReturns 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.
EulerXZYReturns 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.
EulerYXZReturns 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.
EulerYZXReturns 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.
EulerZXYReturns 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.
EulerZYXReturns 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.
LookRotationReturns 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.
LookRotationSafeReturns 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.
RotateXReturns a quaternion that rotates around the x-axis by a given number of radians.
RotateYReturns a quaternion that rotates around the y-axis by a given number of radians.
RotateZReturns a quaternion that rotates around the z-axis by a given number of radians.

Operators

Operator

Description

quaternionImplicitly converts a float4 vector to a quaternion.