# Quat¶

Quaternion.

## Description¶

A unit quaternion used for representing 3D rotations. Quaternions need to be normalized to be used for rotation.

It is similar to Basis, which implements matrix representation of rotations, and can be parametrized using both an axis-angle pair or Euler angles. Basis stores rotation, scale, and shearing, while Quat only stores rotation.

Due to its compactness and the way it is stored in memory, certain operations (obtaining axis-angle and performing SLERP, in particular) are more efficient and robust against floating-point errors.

## Properties¶

 float w 1 float x 0 float y 0 float z 0

## Methods¶

 Quat Quat ( Basis from ) Quat Quat ( Vector3 euler ) Quat Quat ( Vector3 axis, float angle ) Quat Quat ( float x, float y, float z, float w ) float angle_to ( Quat to ) Quat cubic_slerp ( Quat b, Quat pre_a, Quat post_b, float weight ) float dot ( Quat b ) Vector3 Quat inverse ( ) bool is_equal_approx ( Quat quat ) bool float length ( ) float Quat void set_axis_angle ( Vector3 axis, float angle ) void set_euler ( Vector3 euler ) Quat slerp ( Quat to, float weight ) Quat slerpni ( Quat to, float weight ) Vector3 xform ( Vector3 v )

## Constants¶

IDENTITY = Quat( 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.

## Method Descriptions¶

Quat Quat ( Basis from )

Constructs a quaternion from the given Basis.

Quat Quat ( Vector3 euler )

Constructs a quaternion that will perform a rotation specified by Euler angles (in the YXZ convention: when decomposing, first Z, then X, and Y last), given in the vector format as (X angle, Y angle, Z angle).

Quat Quat ( 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.

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

Constructs a quaternion defined by the given values.

float angle_to ( Quat to )

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: This method has an abnormally high amount of floating-point error, so methods such as @GDScript.is_zero_approx will not work reliably.

Quat cubic_slerp ( Quat b, Quat pre_a, Quat post_b, float weight )

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

float dot ( Quat b )

Returns the dot product of two quaternions.

Vector3 get_euler ( )

Returns Euler angles (in the YXZ convention: when decomposing, first Z, then X, and Y last) corresponding to the rotation represented by the unit quaternion. Returned vector contains the rotation angles in the format (X angle, Y angle, Z angle).

Quat inverse ( )

Returns the inverse of the quaternion.

bool is_equal_approx ( Quat quat )

Returns true if this quaternion and quat are approximately equal, by running @GDScript.is_equal_approx on each component.

bool is_normalized ( )

Returns whether the quaternion is normalized or not.

float length ( )

Returns the length of the quaternion.

float length_squared ( )

Returns the length of the quaternion, squared.

Quat normalized ( )

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

void set_axis_angle ( Vector3 axis, float angle )

Sets the quaternion to a rotation which rotates around axis by the specified angle, in radians. The axis must be a normalized vector.

void set_euler ( Vector3 euler )

Sets the quaternion to a rotation specified by Euler angles (in the YXZ convention: when decomposing, first Z, then X, and Y last), given in the vector format as (X angle, Y angle, Z angle).

Quat slerp ( Quat to, float weight )

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

Note: Both quaternions must be normalized.

Quat slerpni ( Quat to, float weight )

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.

Vector3 xform ( Vector3 v )

Returns a vector transformed (multiplied) by this quaternion.