Attention: Here be dragons

This is the `latest` (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

# Quaternion¶

A unit quaternion used for representing 3D rotations.

## Description¶

Quaternions are similar to Basis, which implements the matrix representation of rotations. Unlike Basis, which stores rotation, scale, and shearing, quaternions only store rotation.

Quaternions can be parametrized using both an axis-angle pair or Euler angles. Due to their compactness and the way they are stored in memory, certain operations (obtaining axis-angle and performing SLERP, in particular) are more efficient and robust against floating-point errors.

Note: Quaternions need to be normalized before being used for rotation.

## Properties¶

 float w `1.0` float x `0.0` float y `0.0` float z `0.0`

## Constructors¶

 Quaternion Quaternion Quaternion ( Quaternion from ) Quaternion Quaternion ( Vector3 arc_from, Vector3 arc_to ) Quaternion Quaternion ( Vector3 axis, float angle ) Quaternion Quaternion ( Basis from ) Quaternion Quaternion ( float x, float y, float z, float w )

## Methods¶

 float angle_to ( Quaternion to ) const float dot ( Quaternion with ) const Quaternion exp ( ) const Quaternion from_euler ( Vector3 euler ) static float get_angle ( ) const Vector3 get_axis ( ) const Vector3 get_euler ( int order=2 ) const Quaternion inverse ( ) const bool is_equal_approx ( Quaternion to ) const bool is_finite ( ) const bool is_normalized ( ) const float length ( ) const float length_squared ( ) const Quaternion log ( ) const Quaternion normalized ( ) const Quaternion slerp ( Quaternion to, float weight ) const Quaternion slerpni ( Quaternion to, float weight ) const Quaternion spherical_cubic_interpolate ( Quaternion b, Quaternion pre_a, Quaternion post_b, float weight ) const Quaternion spherical_cubic_interpolate_in_time ( Quaternion b, Quaternion pre_a, Quaternion post_b, float weight, float b_t, float pre_a_t, float post_b_t ) const

## Operators¶

 bool operator != ( Quaternion right ) Quaternion operator * ( Quaternion right ) Vector3 operator * ( Vector3 right ) Quaternion operator * ( float right ) Quaternion operator * ( int right ) Quaternion operator + ( Quaternion right ) Quaternion operator - ( Quaternion right ) Quaternion operator / ( float right ) Quaternion operator / ( int right ) bool operator == ( Quaternion right ) float operator [] ( int index ) Quaternion Quaternion

## Constants¶

IDENTITY = `Quaternion(0, 0, 0, 1)`

The identity quaternion, representing no rotation. Equivalent to an identity Basis matrix. If a vector is transformed by an identity quaternion, it will not change.

## Property Descriptions¶

float w = `1.0`

W component of the quaternion (real part).

Quaternion components should usually not be manipulated directly.

float x = `0.0`

X component of the quaternion (imaginary `i` axis part).

Quaternion components should usually not be manipulated directly.

float y = `0.0`

Y component of the quaternion (imaginary `j` axis part).

Quaternion components should usually not be manipulated directly.

float z = `0.0`

Z component of the quaternion (imaginary `k` axis part).

Quaternion components should usually not be manipulated directly.

## Constructor Descriptions¶

Quaternion Quaternion ( )

Constructs a default-initialized quaternion with all components set to `0`.

Quaternion Quaternion ( Quaternion from )

Constructs a Quaternion as a copy of the given Quaternion.

Quaternion Quaternion ( Vector3 arc_from, Vector3 arc_to )

Constructs a quaternion representing the shortest arc between two points on the surface of a sphere with a radius of `1.0`.

Quaternion Quaternion ( Vector3 axis, float angle )

Constructs a quaternion that will rotate around the given axis by the specified angle. The axis must be a normalized vector.

Quaternion Quaternion ( Basis from )

Constructs a quaternion from the given Basis.

Quaternion Quaternion ( float x, float y, float z, float w )

Constructs a quaternion defined by the given values.

## Method Descriptions¶

float angle_to ( Quaternion to ) const

Returns the angle between this quaternion and `to`. This is the magnitude of the angle you would need to rotate by to get from one to the other.

Note: The magnitude of the floating-point error for this method is abnormally high, so methods such as `is_zero_approx` will not work reliably.

float dot ( Quaternion with ) const

Returns the dot product of two quaternions.

Quaternion exp ( ) const

Quaternion from_euler ( Vector3 euler ) static

Constructs a Quaternion from Euler angles in YXZ rotation order.

float get_angle ( ) const

Vector3 get_axis ( ) const

Vector3 get_euler ( int order=2 ) const

Returns the quaternion's rotation in the form of Euler angles. The Euler order depends on the `order` parameter, for example using the YXZ convention: since this method decomposes, first Z, then X, and Y last. See the EulerOrder enum for possible values. The returned vector contains the rotation angles in the format (X angle, Y angle, Z angle).

Quaternion inverse ( ) const

Returns the inverse of the quaternion.

bool is_equal_approx ( Quaternion to ) const

Returns `true` if this quaternion and `to` are approximately equal, by running @GlobalScope.is_equal_approx on each component.

bool is_finite ( ) const

Returns `true` if this quaternion is finite, by calling @GlobalScope.is_finite on each component.

bool is_normalized ( ) const

Returns whether the quaternion is normalized or not.

float length ( ) const

Returns the length of the quaternion.

float length_squared ( ) const

Returns the length of the quaternion, squared.

Quaternion log ( ) const

Quaternion normalized ( ) const

Returns a copy of the quaternion, normalized to unit length.

Quaternion slerp ( Quaternion to, float weight ) const

Returns the result of the spherical linear interpolation between this quaternion and `to` by amount `weight`.

Note: Both quaternions must be normalized.

Quaternion slerpni ( Quaternion to, float weight ) const

Returns the result of the spherical linear interpolation between this quaternion and `to` by amount `weight`, but without checking if the rotation path is not bigger than 90 degrees.

Quaternion spherical_cubic_interpolate ( Quaternion b, Quaternion pre_a, Quaternion post_b, float weight ) const

Performs a spherical cubic interpolation between quaternions `pre_a`, this vector, `b`, and `post_b`, by the given amount `weight`.

Quaternion spherical_cubic_interpolate_in_time ( Quaternion b, Quaternion pre_a, Quaternion post_b, float weight, float b_t, float pre_a_t, float post_b_t ) const

Performs a spherical cubic interpolation between quaternions `pre_a`, this vector, `b`, and `post_b`, by the given amount `weight`.

It can perform smoother interpolation than `spherical_cubic_interpolate()` by the time values.

## Operator Descriptions¶

bool operator != ( Quaternion right )

Returns `true` if the quaternions are not equal.

Note: Due to floating-point precision errors, consider using is_equal_approx<