public final class Quaternion
- Object
- Quaternion
Portable quaternion math used by the 3D, AR and VR APIs. Every operation
works on plain
float[4] arrays laid out as {x, y, z, w} so it behaves
identically on every platform. A quaternion of this form represents a
rotation; {0, 0, 0, 1} is the identity (no rotation). Rotation matrices
produced by toMatrix(float[], float[]) use the same column-major layout
as Matrix4.Methods
public static float[] identity() | Allocates a new identity quaternion {0, 0, 0, 1}. |
public static void setIdentity(float[] q) | Resets the supplied quaternion to the identity rotation. |
public static void copy(float[] src, float[] dst) | Copies the contents of src into dst. |
public static void multiply(float[] a, float[] b, float[] dst) | Multiplies a * b (apply b first, then a) and stores the result in dst. |
public static float[] fromAxisAngle(float angleRadians, float x, float y, float z) | Returns a quaternion representing a rotation of angleRadians around the axis (x, y, z). |
public static void setAxisAngle(float[] q, float angleRadians, float x, float y, float z) | Stores a rotation of angleRadians around the axis (x, y, z) into q. |
public static void normalize(float[] q) | Normalizes q in place to unit length. |
public static void conjugate(float[] q, float[] dst) | Stores the conjugate of q (the inverse rotation for a unit quaternion) into dst. |
public static void toMatrix(float[] q, float[] dst16) | Writes the rotation matrix equivalent of the unit quaternion q into the 16 element column-major matrix dst16. |
public static void rotateVector(float[] q, float[] xyzInOut) | Rotates the vector stored in xyzInOut (3 floats) by the unit quaternion q, writing the result back in place. |
public static void slerp(float[] a, float[] b, float t, float[] dst) | Spherically interpolates between the unit quaternions a and b by the factor t in [0, 1], storing the result in dst. |
public static void integrateGyro(float[] q, float gx, float gy, float gz, float dtSeconds, float[] dst) | Integrates a body-frame angular velocity into the orientation quaternion q, storing the result in dst. |
Inherited methods
Method details
identity
public static float[] identity()Allocates a new identity quaternion
{0, 0, 0, 1}.setIdentity
public static void setIdentity(float[] q)Resets the supplied quaternion to the identity rotation.
copy
public static void copy(float[] src, float[] dst)Copies the contents of
src into dst. Both arrays must hold 4 floats.multiply
public static void multiply(float[] a, float[] b, float[] dst)Multiplies
a * b (apply b first, then a) and stores the result in
dst. dst may alias a or b.fromAxisAngle
public static float[] fromAxisAngle(float angleRadians, float x, float y, float z)Returns a quaternion representing a rotation of
angleRadians around the
axis (x, y, z). The axis need not be normalized; a zero axis returns
the identity.setAxisAngle
public static void setAxisAngle(float[] q, float angleRadians, float x, float y, float z)Stores a rotation of
angleRadians around the axis (x, y, z) into q.
The axis need not be normalized; a zero axis produces the identity.normalize
public static void normalize(float[] q)Normalizes
q in place to unit length. A zero quaternion is reset to the
identity.conjugate
public static void conjugate(float[] q, float[] dst)Stores the conjugate of
q (the inverse rotation for a unit quaternion)
into dst. dst may alias q.toMatrix
public static void toMatrix(float[] q, float[] dst16)Writes the rotation matrix equivalent of the unit quaternion
q into the
16 element column-major matrix dst16. The result matches
Matrix4.rotation(float, float, float, float) for the same axis and
angle.rotateVector
public static void rotateVector(float[] q, float[] xyzInOut)Rotates the vector stored in
xyzInOut (3 floats) by the unit quaternion
q, writing the result back in place.slerp
public static void slerp(float[] a, float[] b, float t, float[] dst)Spherically interpolates between the unit quaternions
a and b by the
factor t in [0, 1], storing the result in dst. Takes the shortest
arc; falls back to linear interpolation when the quaternions are nearly
parallel.integrateGyro
public static void integrateGyro(float[] q, float gx, float gy, float gz, float dtSeconds, float[] dst)Integrates a body-frame angular velocity into the orientation quaternion
q, storing the result in dst. gx, gy and gz are rotation rates
in radians per second around the body X, Y and Z axes (the convention
used by gyroscope sensors) and dtSeconds is the integration interval.
dst may alias q. The result is normalized.