Quaternion


public final class Quaternion


Represents a rotation component in three-dimensional space. Any vector can be provided and the resulting quaternion will be normalized at construction time.

Summary

Public fields

final @NonNull Quaternion

Public constructors

Creates a new quaternion with the same values as the other quaternion.

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

Public methods

static final float

Returns the angle between start and end quaternion in degrees.

final @NonNull Quaternion
copy(float x, float y, float z, float w)

Returns a copy of the quaternion.

final @NonNull Quaternion
div(float c)

Returns a new quaternion with this quaternion divided by a scalar amount.

final float

Returns the dot product of this quaternion and the other quaternion.

static final float

Returns the dot product of two quaternions.

boolean
equals(Object other)

Returns true if this quaternion is equal to the other.

static final @NonNull Quaternion
fromAxisAngle(@NonNull Vector3 axis, float degrees)

Creates a new quaternion using an axis/angle to define the rotation.

static final @NonNull Quaternion

Returns a new quaternion using Euler angles (in degrees) to define the rotation in YXZ (yaw, pitch, roll) order.

static final @NonNull Quaternion
fromEulerAngles(float pitch, float yaw, float roll)

Returns a new quaternion using Euler angles (in degrees) to define the rotation in YXZ (yaw, pitch, roll) order.

static final @NonNull Quaternion

Returns a new quaternion with the specified forward and upward directions.

static final @NonNull Quaternion

Returns a new quaternion representing the rotation from one quaternion to another.

static final @NonNull Quaternion

Returns a new quaternion representing the rotation from one vector to another.

final @NonNull Pair<@NonNull Vector3, @NonNull Float>

Returns this quaternion as an axis/angle (in degrees) pair.

final @NonNull Vector3

Returns this quaternion as Euler angles (in degrees) applied in YXZ (yaw, pitch, roll) order.

final @NonNull Quaternion

Returns a new quaternion with the inverse rotation.

final float

The normalized w component of the quaternion.

final float

The normalized x component of the quaternion.

final float

The normalized y component of the quaternion.

final float

The normalized z component of the quaternion.

int
static final @NonNull Quaternion
lerp(@NonNull Quaternion start, @NonNull Quaternion end, float ratio)

Returns a new quaternion that is linearly interpolated between start and end using the interpolation amount ratio.

final @NonNull Quaternion

Returns a new quaternion with the difference of this quaternion and the other quaternion.

final @NonNull Quaternion

Returns a new quaternion with the sum of this quaternion and other quaternion.

static final @NonNull Quaternion
slerp(@NonNull Quaternion start, @NonNull Quaternion end, float ratio)

Returns a new quaternion that is spherically interpolated between start and end using the interpolation amount ratio.

final @NonNull Quaternion
times(float c)

Returns a new quaternion with the product of this quaternion and a scalar amount.

final @NonNull Quaternion

Returns a new quaternion with the product of this quaternion and the other quaternion.

final @NonNull Vector3

Rotates a Vector3 by this quaternion.

final @NonNull Quaternion

Returns a new quaternion with a normalized rotation.

@NonNull String
final @NonNull Quaternion

Flips the sign of the quaternion, but represents the same rotation.

Public fields

Identity

public final @NonNull Quaternion Identity

Public constructors

Quaternion

Added in 1.0.0-alpha01
public Quaternion(@NonNull Quaternion other)

Creates a new quaternion with the same values as the other quaternion.

Quaternion

Added in 1.0.0-alpha01
public Quaternion(float x, float y, float z, float w)
Parameters
float x

the x value of the quaternion.

float y

the y value of the quaternion.

float z

the z value of the quaternion.

float w

the rotation of the unit vector, in radians.

Public methods

angle

Added in 1.0.0-alpha01
public static final float angle(@NonNull Quaternion start, @NonNull Quaternion end)

Returns the angle between start and end quaternion in degrees.

copy

Added in 1.0.0-alpha01
public final @NonNull Quaternion copy(float x, float y, float z, float w)

Returns a copy of the quaternion.

div

Added in 1.0.0-alpha01
public final @NonNull Quaternion div(float c)

Returns a new quaternion with this quaternion divided by a scalar amount.

dot

Added in 1.0.0-alpha01
public final float dot(@NonNull Quaternion other)

Returns the dot product of this quaternion and the other quaternion.

dot

Added in 1.0.0-alpha01
public static final float dot(@NonNull Quaternion lhs, @NonNull Quaternion rhs)

Returns the dot product of two quaternions.

equals

public boolean equals(Object other)

Returns true if this quaternion is equal to the other.

fromAxisAngle

Added in 1.0.0-alpha01
public static final @NonNull Quaternion fromAxisAngle(@NonNull Vector3 axis, float degrees)

Creates a new quaternion using an axis/angle to define the rotation.

fromEulerAngles

Added in 1.0.0-alpha01
public static final @NonNull Quaternion fromEulerAngles(@NonNull Vector3 eulerAngles)

Returns a new quaternion using Euler angles (in degrees) to define the rotation in YXZ (yaw, pitch, roll) order.

fromEulerAngles

Added in 1.0.0-alpha01
public static final @NonNull Quaternion fromEulerAngles(float pitch, float yaw, float roll)

Returns a new quaternion using Euler angles (in degrees) to define the rotation in YXZ (yaw, pitch, roll) order.

fromLookTowards

Added in 1.0.0-alpha01
public static final @NonNull Quaternion fromLookTowards(@NonNull Vector3 forward, @NonNull Vector3 up)

Returns a new quaternion with the specified forward and upward directions.

fromRotation

Added in 1.0.0-alpha01
public static final @NonNull Quaternion fromRotation(@NonNull Quaternion start, @NonNull Quaternion end)

Returns a new quaternion representing the rotation from one quaternion to another.

fromRotation

Added in 1.0.0-alpha01
public static final @NonNull Quaternion fromRotation(@NonNull Vector3 start, @NonNull Vector3 end)

Returns a new quaternion representing the rotation from one vector to another.

getAxisAngle

Added in 1.0.0-alpha01
public final @NonNull Pair<@NonNull Vector3, @NonNull FloatgetAxisAngle()

Returns this quaternion as an axis/angle (in degrees) pair.

getEulerAngles

Added in 1.0.0-alpha01
public final @NonNull Vector3 getEulerAngles()

Returns this quaternion as Euler angles (in degrees) applied in YXZ (yaw, pitch, roll) order.

getInverse

Added in 1.0.0-alpha01
public final @NonNull Quaternion getInverse()

Returns a new quaternion with the inverse rotation. Assumes unit length.

getW

Added in 1.0.0-alpha01
public final float getW()

The normalized w component of the quaternion.

getX

Added in 1.0.0-alpha01
public final float getX()

The normalized x component of the quaternion.

getY

Added in 1.0.0-alpha01
public final float getY()

The normalized y component of the quaternion.

getZ

Added in 1.0.0-alpha01
public final float getZ()

The normalized z component of the quaternion.

hashCode

public int hashCode()

lerp

Added in 1.0.0-alpha01
public static final @NonNull Quaternion lerp(@NonNull Quaternion start, @NonNull Quaternion end, float ratio)

Returns a new quaternion that is linearly interpolated between start and end using the interpolation amount ratio.

If ratio is outside of the range [0, 1], the returned quaternion will be extrapolated.

minus

Added in 1.0.0-alpha01
public final @NonNull Quaternion minus(@NonNull Quaternion other)

Returns a new quaternion with the difference of this quaternion and the other quaternion.

plus

Added in 1.0.0-alpha01
public final @NonNull Quaternion plus(@NonNull Quaternion other)

Returns a new quaternion with the sum of this quaternion and other quaternion.

slerp

Added in 1.0.0-alpha01
public static final @NonNull Quaternion slerp(@NonNull Quaternion start, @NonNull Quaternion end, float ratio)

Returns a new quaternion that is spherically interpolated between start and end using the interpolation amount ratio. If ratio is 0, this returns start. As ratio approaches 1, the result of this function may approach either +end or -end (whichever is closest to start).

If ratio is outside of the range [0, 1], the returned quaternion will be extrapolated.

times

Added in 1.0.0-alpha01
public final @NonNull Quaternion times(float c)

Returns a new quaternion with the product of this quaternion and a scalar amount.

times

Added in 1.0.0-alpha01
public final @NonNull Quaternion times(@NonNull Quaternion other)

Returns a new quaternion with the product of this quaternion and the other quaternion. The order of the multiplication is [this] * [other].

times

Added in 1.0.0-alpha01
public final @NonNull Vector3 times(@NonNull Vector3 src)

Rotates a Vector3 by this quaternion.

toNormalized

Added in 1.0.0-alpha01
public final @NonNull Quaternion toNormalized()

Returns a new quaternion with a normalized rotation.

toString

public @NonNull String toString()

unaryMinus

Added in 1.0.0-alpha01
public final @NonNull Quaternion unaryMinus()

Flips the sign of the quaternion, but represents the same rotation.