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. A zero-length input (all components zero) cannot be normalized and falls back to the identity rotation.
Summary
Public fields |
|
|---|---|
static final @NonNull Quaternion |
Public constructors |
|---|
Quaternion(@NonNull Quaternion other)Creates a new quaternion with the same values as the |
Quaternion(float x, float y, float z, float w) |
Public methods |
|
|---|---|
static final float |
angle(@NonNull Quaternion start, @NonNull Quaternion end)Returns the angle between |
final @NonNull Quaternion |
copy(float x, float y, float z, float w)Returns a copy of the quaternion. |
final float |
dot(@NonNull Quaternion other)Returns the dot product of this quaternion and the |
static final float |
dot(@NonNull Quaternion lhs, @NonNull Quaternion rhs)Returns the dot product of two quaternions. |
boolean |
Returns true if this quaternion is equal to the |
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 |
fromEulerAngles(@NonNull Vector3 eulerAngles)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 |
fromLookTowards(@NonNull Vector3 forward, @NonNull Vector3 up)Returns a new quaternion with the specified forward and upward directions. |
static final @NonNull Quaternion |
fromRotation(@NonNull Quaternion start, @NonNull Quaternion end)Returns a new quaternion representing the rotation from one quaternion to another. |
static final @NonNull Quaternion |
fromRotation(@NonNull Vector3 start, @NonNull Vector3 end)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 |
getW()The normalized w component of the quaternion. |
final float |
getX()The normalized x component of the quaternion. |
final float |
getY()The normalized y component of the quaternion. |
final float |
getZ()The normalized z component of the quaternion. |
int |
hashCode() |
static final @NonNull Quaternion |
lerp(@NonNull Quaternion start, @NonNull Quaternion end, float ratio)Returns a new quaternion that is linearly interpolated between |
final @NonNull Quaternion |
minus(@NonNull Quaternion other)Returns a new quaternion with the difference of this quaternion and the |
final @NonNull Quaternion |
plus(@NonNull Quaternion other)Returns a new quaternion with the sum of this quaternion and |
static final @NonNull Quaternion |
slerp(@NonNull Quaternion start, @NonNull Quaternion end, float ratio)Returns a new quaternion that is spherically interpolated between |
final @NonNull Quaternion |
times(@NonNull Quaternion other)Returns a new quaternion with the product of this quaternion and the |
final @NonNull Vector3 |
Rotates a |
@NonNull String |
toString() |
final @NonNull Quaternion |
Flips the sign of the quaternion, but represents the same rotation. |
Public fields
Public constructors
Quaternion
public Quaternion(@NonNull Quaternion other)
Creates a new quaternion with the same values as the other quaternion.
Public methods
angle
public static final float angle(@NonNull Quaternion start, @NonNull Quaternion end)
Returns the angle between start and end quaternion in degrees.
| Parameters | |
|---|---|
@NonNull Quaternion start |
the starting quaternion |
@NonNull Quaternion end |
the ending quaternion |
copy
public final @NonNull Quaternion copy(float x, float y, float z, float w)
Returns a copy of the quaternion.
| Parameters | |
|---|---|
float x |
the new x value for the copied quaternion |
float y |
the new y value for the copied quaternion |
float z |
the new z value for the copied quaternion |
float w |
the new w value for the copied quaternion |
dot
public final float dot(@NonNull Quaternion other)
Returns the dot product of this quaternion and the other quaternion.
dot
public static final float dot(@NonNull Quaternion lhs, @NonNull Quaternion rhs)
Returns the dot product of two quaternions.
| Parameters | |
|---|---|
@NonNull Quaternion lhs |
the first quaternion |
@NonNull Quaternion rhs |
the second quaternion |
fromAxisAngle
public static final @NonNull Quaternion fromAxisAngle(@NonNull Vector3 axis, float degrees)
Creates a new quaternion using an axis/angle to define the rotation.
fromEulerAngles
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
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.
| Parameters | |
|---|---|
float pitch |
the pitch in degrees |
float yaw |
the yaw in degrees |
float roll |
the roll in degrees |
fromLookTowards
public static final @NonNull Quaternion fromLookTowards(@NonNull Vector3 forward, @NonNull Vector3 up)
Returns a new quaternion with the specified forward and upward directions. If up is parallel (or antiparallel) to forward, an alternate up axis is chosen so the resulting orientation basis is still well-defined.
fromRotation
public static final @NonNull Quaternion fromRotation(@NonNull Quaternion start, @NonNull Quaternion end)
Returns a new quaternion representing the rotation from one quaternion to another.
| Parameters | |
|---|---|
@NonNull Quaternion start |
the starting quaternion |
@NonNull Quaternion end |
the ending quaternion |
fromRotation
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
public final @NonNull Pair<@NonNull Vector3, @NonNull Float> getAxisAngle()
Returns this quaternion as an axis/angle (in degrees) pair.
getEulerAngles
public final @NonNull Vector3 getEulerAngles()
Returns this quaternion as Euler angles (in degrees) applied in YXZ (yaw, pitch, roll) order.
getInverse
public final @NonNull Quaternion getInverse()
Returns a new quaternion with the inverse rotation. Assumes unit length.
lerp
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.
| Parameters | |
|---|---|
@NonNull Quaternion start |
the starting quaternion |
@NonNull Quaternion end |
the ending quaternion |
float ratio |
the interpolation ratio |
minus
public final @NonNull Quaternion minus(@NonNull Quaternion other)
Returns a new quaternion with the difference of this quaternion and the other quaternion.
plus
public final @NonNull Quaternion plus(@NonNull Quaternion other)
Returns a new quaternion with the sum of this quaternion and other quaternion.
slerp
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.
| Parameters | |
|---|---|
@NonNull Quaternion start |
the starting quaternion |
@NonNull Quaternion end |
the ending quaternion |
float ratio |
the interpolation ratio |
times
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
public final @NonNull Vector3 times(@NonNull Vector3 src)
Rotates a Vector3 by this quaternion.
unaryMinus
public final @NonNull Quaternion unaryMinus()
Flips the sign of the quaternion, but represents the same rotation.