com.bergerkiller.bukkit.common.math

## Class Quaternion

• All Implemented Interfaces:
Cloneable

```public class Quaternion
extends Object
implements Cloneable```
A quaternion for performing rotations in 3D space. The quaternion is automatically normalized.
• ### Constructor Summary

Constructors
Constructor and Description
`Quaternion()`
```Quaternion(double x, double y, double z, double w)```
`Quaternion(Quaternion quat)`
• ### Method Summary

All Methods
Modifier and Type Method and Description
`Quaternion` `clone()`
`void` `divide(Quaternion quat)`
Divides this quaternion by another quaternion.
`static Quaternion` ```divide(Quaternion q1, Quaternion q2)```
Performs a division between two quaternions.
`double` `dot(Quaternion q)`
Calculates the dot product of this Quaternion with another
`boolean` `equals(Object o)`
`org.bukkit.util.Vector` `forwardVector()`
Retrieves the forward vector, which is the result of transforming a (0,0,1) point with this Quaternion.
`static Quaternion` ```fromAxisAngles(double axisX, double axisY, double axisZ, double angleDegrees)```
Creates a quaternion for a rotation around an axis
`static Quaternion` ```fromAxisAngles(Vector3 axis, double angleDegrees)```
Creates a quaternion for a rotation around an axis
`static Quaternion` ```fromAxisAngles(org.bukkit.util.Vector axis, double angleDegrees)```
Creates a quaternion for a rotation around an axis
`static Quaternion` `fromLookDirection(org.bukkit.util.Vector dir)`
Creates a quaternion that transforms a forward vector (0, 0, 1) into the output vector (v).
`static Quaternion` ```fromLookDirection(org.bukkit.util.Vector dir, org.bukkit.util.Vector up)```
Creates a quaternion that 'looks' into a given direction, with a known 'up' vector to dictate roll around that direction axis.
`static Quaternion` ```fromToRotation(org.bukkit.util.Vector u, org.bukkit.util.Vector v)```
Creates a quaternion that transforms the input vector (u) into the output vector (v).
`static Quaternion` ```fromToRotation(org.bukkit.util.Vector u, org.bukkit.util.Vector v, org.bukkit.util.Vector d)```
Creates a quaternion that transforms the input vector (u) into the output vector (v).
`static Quaternion` ```fromYawPitchRoll(double pitch, double yaw, double roll)```
Creates a quaternion from yaw/pitch/roll rotations as performed by Minecraft
`static Quaternion` `fromYawPitchRoll(org.bukkit.util.Vector rotation)`
Creates a quaternion from yaw/pitch/roll rotations as performed by Minecraft
`double` `getPitch()`
Deduces the pitch component (x) of `getYawPitchRoll()`
`protected static double` ```getPitch(double x, double y, double z, double w)```
`double` `getRoll()`
Deduces the roll component (z) of `getYawPitchRoll()`
`protected static double` ```getRoll(double x, double y, double z, double w)```
`double` `getW()`
`double` `getX()`
`double` `getY()`
`double` `getYaw()`
Deduces the yaw component (y) of `getYawPitchRoll()`
`protected static double` ```getYaw(double x, double y, double z, double w)```
`org.bukkit.util.Vector` `getYawPitchRoll()`
Deduces the yaw/pitch/roll values in degrees that this quaternion transforms objects with
`protected static org.bukkit.util.Vector` ```getYawPitchRoll(double x, double y, double z, double w)```
`double` `getZ()`
`void` `invert()`
Inverts this Quaternion.
`static Quaternion` ```lerp(Quaternion q0, Quaternion q1, double theta)```
Performs a linear interpolation between two quaternions.
`static Quaternion` ```lerp(Quaternion q0, Quaternion q1, double t0, double t1)```
Performs a linear interpolation between two quaternions.
`void` `multiply(Quaternion quat)`
Multiplies this quaternion with another quaternion.
`static Quaternion` ```multiply(Quaternion q1, Quaternion q2)```
Performs a multiplication between two quaternions.
`org.bukkit.util.Vector` `rightVector()`
Retrieves the right vector, which is the result of transforming a (1,0,0) point with this Quaternion.
`void` ```rotateAxis(double axisX, double axisY, double axisZ, double angleDegrees)```
Multiplies this Quaternion with a rotation around an axis
`void` ```rotateAxis(org.bukkit.util.Vector axis, double angleDegrees)```
Multiplies this Quaternion with a rotation around an axis
`void` `rotateX(double angleDegrees)`
Rotates the Quaternion an angle around the x-axis
`void` ```rotateX(double y, double z)```
Rotates the Quaternion an angle around the X-axis, the angle defined by the y/z vector.
`void` `rotateXFlip()`
Rotates the Quaternion 180 degrees around the x-axis
`void` `rotateY(double angleDegrees)`
Rotates the Quaternion an angle around the y-axis
`void` ```rotateY(double x, double z)```
Rotates the Quaternion an angle around the y-axis, the angle defined by the x/z vector.
`void` ```rotateYawPitchRoll(double pitch, double yaw, double roll)```
Multiplies this quaternion with a rotation transformation in yaw/pitch/roll, based on the Minecraft coordinate system.
`void` `rotateYawPitchRoll(org.bukkit.util.Vector rotation)`
Multiplies this quaternion with a rotation transformation in yaw/pitch/roll, based on the Minecraft coordinate system.
`void` `rotateYawPitchRoll(Vector3 rotation)`
Multiplies this quaternion with a rotation transformation in yaw/pitch/roll, based on the Minecraft coordinate system.
`void` `rotateYFlip()`
Rotates the Quaternion 180 degrees around the y-axis
`void` `rotateZ(double angleDegrees)`
Rotates the Quaternion an angle around the z-axis
`void` ```rotateZ(double x, double y)```
Rotates the Quaternion an angle around the z-axis, the angle defined by the x/y vector.
`void` `rotateZFlip()`
Rotates the Quaternion 180 degrees around the z-axis
`void` `setIdentity()`
Sets this Quaternion to the identity quaternion (0,0,0,1)
`void` `setTo(Quaternion q)`
Sets this Quaternion to the values of another Quaternion
`static Quaternion` ```slerp(Quaternion q0, Quaternion q1, double theta)```
Performs a spherical interpolation between two quaternions.
`Matrix4x4` `toMatrix4x4()`
Converts the rotation transformations defined in this quaternion to a 4x4 transformation matrix.
`String` `toString()`
`void` `transformPoint(org.bukkit.util.Vector point)`
Transforms a point, applying the rotation of this quaternion with 0,0,0 as origin.
`org.bukkit.util.Vector` `upVector()`
Retrieves the up vector, which is the result of transforming a (0,1,0) point with this Quaternion.
• ### Methods inherited from class java.lang.Object

`finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ### Constructor Detail

• #### Quaternion

`public Quaternion()`
• #### Quaternion

`public Quaternion(Quaternion quat)`
• #### Quaternion

```public Quaternion(double x,
double y,
double z,
double w)```
• ### Method Detail

• #### getX

`public double getX()`
• #### getY

`public double getY()`
• #### getZ

`public double getZ()`
• #### getW

`public double getW()`
• #### setIdentity

`public void setIdentity()`
Sets this Quaternion to the identity quaternion (0,0,0,1)
• #### setTo

`public void setTo(Quaternion q)`
Sets this Quaternion to the values of another Quaternion
Parameters:
`q` - to set to
• #### dot

`public double dot(Quaternion q)`
Calculates the dot product of this Quaternion with another
Parameters:
`q` - other quaternion
Returns:
dot product
• #### transformPoint

`public void transformPoint(org.bukkit.util.Vector point)`
Transforms a point, applying the rotation of this quaternion with 0,0,0 as origin.
Parameters:
`point` - to rotate using this quaternion
• #### rightVector

`public org.bukkit.util.Vector rightVector()`
Retrieves the right vector, which is the result of transforming a (1,0,0) point with this Quaternion.
Returns:
right vector
• #### upVector

`public org.bukkit.util.Vector upVector()`
Retrieves the up vector, which is the result of transforming a (0,1,0) point with this Quaternion.
Returns:
up vector
• #### forwardVector

`public org.bukkit.util.Vector forwardVector()`
Retrieves the forward vector, which is the result of transforming a (0,0,1) point with this Quaternion.
Returns:
forward vector
• #### divide

`public void divide(Quaternion quat)`
Divides this quaternion by another quaternion. This operation is equivalent to multiplying with the quaternion after calling `invert()` on it.
Parameters:
`quat` - to divide with
• #### multiply

`public void multiply(Quaternion quat)`
Multiplies this quaternion with another quaternion. The result is stored in this quaternion.
Parameters:
`quat` - to multiply with
• #### rotateAxis

```public final void rotateAxis(org.bukkit.util.Vector axis,
double angleDegrees)```
Multiplies this Quaternion with a rotation around an axis
Parameters:
`axis` - vector
`angleDegrees` - to rotate in degrees
• #### rotateAxis

```public final void rotateAxis(double axisX,
double axisY,
double axisZ,
double angleDegrees)```
Multiplies this Quaternion with a rotation around an axis
Parameters:
`axisX` - vector coordinate
`axisY` - vector coordinate
`axisZ` - vector coordinate
`angleDegrees` - to rotate in degrees
• #### rotateYawPitchRoll

`public final void rotateYawPitchRoll(Vector3 rotation)`
Multiplies this quaternion with a rotation transformation in yaw/pitch/roll, based on the Minecraft coordinate system. This will differ slightly from the standard rotateX/Y/Z functions.
Parameters:
`rotation` - (x=pitch, y=yaw, z=roll)
• #### rotateYawPitchRoll

`public final void rotateYawPitchRoll(org.bukkit.util.Vector rotation)`
Multiplies this quaternion with a rotation transformation in yaw/pitch/roll, based on the Minecraft coordinate system. This will differ slightly from the standard rotateX/Y/Z functions.
Parameters:
`rotation` - (x=pitch, y=yaw, z=roll)
• #### rotateYawPitchRoll

```public final void rotateYawPitchRoll(double pitch,
double yaw,
double roll)```
Multiplies this quaternion with a rotation transformation in yaw/pitch/roll, based on the Minecraft coordinate system. This will differ slightly from the standard rotateX/Y/Z functions.
Parameters:
`pitch` - rotation (X)
`yaw` - rotation (Y)
`roll` - rotation (Z)
• #### getYawPitchRoll

`public final org.bukkit.util.Vector getYawPitchRoll()`
Deduces the yaw/pitch/roll values in degrees that this quaternion transforms objects with
Returns:
axis rotations: {x=pitch, y=yaw, z=roll}
• #### getPitch

`public final double getPitch()`
Deduces the pitch component (x) of `getYawPitchRoll()`
Returns:
pitch
• #### getRoll

`public final double getRoll()`
Deduces the roll component (z) of `getYawPitchRoll()`
Returns:
roll
• #### getYaw

```protected static double getYaw(double x,
double y,
double z,
double w)```
• #### getPitch

```protected static double getPitch(double x,
double y,
double z,
double w)```
• #### getRoll

```protected static double getRoll(double x,
double y,
double z,
double w)```
• #### getYawPitchRoll

```protected static org.bukkit.util.Vector getYawPitchRoll(double x,
double y,
double z,
double w)```
• #### rotateXFlip

`public final void rotateXFlip()`
Rotates the Quaternion 180 degrees around the x-axis
• #### rotateX

`public final void rotateX(double angleDegrees)`
Rotates the Quaternion an angle around the x-axis
Parameters:
`angleDegrees` - to rotate
• #### rotateX

```public final void rotateX(double y,
double z)```
Rotates the Quaternion an angle around the X-axis, the angle defined by the y/z vector. This is equivalent to calling `#rotateX(angleDegrees)` using `Math#atan2(z,y)`.
Parameters:
`y` -
`z` -
• #### rotateYFlip

`public final void rotateYFlip()`
Rotates the Quaternion 180 degrees around the y-axis
• #### rotateY

`public final void rotateY(double angleDegrees)`
Rotates the Quaternion an angle around the y-axis
Parameters:
`angleDegrees` - to rotate
• #### rotateY

```public final void rotateY(double x,
double z)```
Rotates the Quaternion an angle around the y-axis, the angle defined by the x/z vector. This is equivalent to calling `#rotateY(angleDegrees)` using `Math#atan2(z,x)`.
Parameters:
`x` -
`z` -
• #### rotateZFlip

`public final void rotateZFlip()`
Rotates the Quaternion 180 degrees around the z-axis
• #### rotateZ

`public final void rotateZ(double angleDegrees)`
Rotates the Quaternion an angle around the z-axis
Parameters:
`angleDegrees` - to rotate
• #### rotateZ

```public final void rotateZ(double x,
double y)```
Rotates the Quaternion an angle around the z-axis, the angle defined by the x/y vector. This is equivalent to calling `#rotateZ(angleDegrees)` using `Math#atan2(y,x)`.
Parameters:
`x` -
`y` -
• #### toMatrix4x4

`public Matrix4x4 toMatrix4x4()`
Converts the rotation transformations defined in this quaternion to a 4x4 transformation matrix. This is as if the unit matrix was multiplied with this quaternion.
Returns:
4x4 transformation matrix.
• #### invert

`public void invert()`
Inverts this Quaternion.
• #### clone

`public Quaternion clone()`
Overrides:
`clone` in class `Object`
• #### equals

`public boolean equals(Object o)`
Overrides:
`equals` in class `Object`
• #### toString

`public String toString()`
Overrides:
`toString` in class `Object`
• #### multiply

```public static Quaternion multiply(Quaternion q1,
Quaternion q2)```
Performs a multiplication between two quaternions. A new quaternion instance is returned.
Parameters:
`q1` -
`q2` -
Returns:
q1 x q2
• #### divide

```public static Quaternion divide(Quaternion q1,
Quaternion q2)```
Performs a division between two quaternions. A new quaternion instance is returned.
Parameters:
`q1` -
`q2` -
Returns:
q1 / q2
• #### fromAxisAngles

```public static Quaternion fromAxisAngles(Vector3 axis,
double angleDegrees)```
Creates a quaternion for a rotation around an axis
Parameters:
`axis` -
`angleDegrees` -
Returns:
quaternion for the rotation around the axis
• #### fromAxisAngles

```public static Quaternion fromAxisAngles(org.bukkit.util.Vector axis,
double angleDegrees)```
Creates a quaternion for a rotation around an axis
Parameters:
`axis` -
`angleDegrees` -
Returns:
quaternion for the rotation around the axis
• #### fromAxisAngles

```public static Quaternion fromAxisAngles(double axisX,
double axisY,
double axisZ,
double angleDegrees)```
Creates a quaternion for a rotation around an axis
Parameters:
`axisX` -
`axisY` -
`axisZ` -
`angleDegrees` -
Returns:
quaternion for the rotation around the axis
• #### fromYawPitchRoll

`public static Quaternion fromYawPitchRoll(org.bukkit.util.Vector rotation)`
Creates a quaternion from yaw/pitch/roll rotations as performed by Minecraft
Parameters:
`rotation` - (x=pitch, y=yaw, z=roll)
Returns:
quaternion for the yaw/pitch/roll rotation
• #### fromYawPitchRoll

```public static Quaternion fromYawPitchRoll(double pitch,
double yaw,
double roll)```
Creates a quaternion from yaw/pitch/roll rotations as performed by Minecraft
Parameters:
`pitch` - rotation (X)
`yaw` - rotation (Y)
`roll` - rotation (Z)
Returns:
quaternion for the yaw/pitch/roll rotation
• #### fromToRotation

```public static Quaternion fromToRotation(org.bukkit.util.Vector u,
org.bukkit.util.Vector v,
org.bukkit.util.Vector d)```
Creates a quaternion that transforms the input vector (u) into the output vector (v). The vectors do not have to be unit vectors for this function to work. The d vector specifies an axis to rotate around when a 180-degree rotation is encountered.
Parameters:
`u` - input vector (from)
`v` - expected output vector (to)
`d` - direction axis around which to rotate for 180-degree angles
Returns:
quaternion that rotates u to become v
• #### fromToRotation

```public static Quaternion fromToRotation(org.bukkit.util.Vector u,
org.bukkit.util.Vector v)```
Creates a quaternion that transforms the input vector (u) into the output vector (v). The vectors do not have to be unit vectors for this function to work.
Parameters:
`u` - input vector (from)
`v` - expected output vector (to)
Returns:
quaternion that rotates u to become v
• #### fromLookDirection

`public static Quaternion fromLookDirection(org.bukkit.util.Vector dir)`
Creates a quaternion that transforms a forward vector (0, 0, 1) into the output vector (v). The vector does not have to be a unit vector for this function to work. If the 'up' axis is important, use `#fromLookDirection(dir, up)` instead.
Parameters:
`v` - expected output vector (to)
Returns:
quaternion that rotates (0,0,1) to become v
• #### fromLookDirection

```public static Quaternion fromLookDirection(org.bukkit.util.Vector dir,
org.bukkit.util.Vector up)```
Creates a quaternion that 'looks' into a given direction, with a known 'up' vector to dictate roll around that direction axis.
Parameters:
`dir` - to look into
`up` - direction
Returns:
Quaternion with the look-direction transformation
• #### lerp

```public static Quaternion lerp(Quaternion q0,
Quaternion q1,
double t0,
double t1)```
Performs a linear interpolation between two quaternions. Separate theta values can be specified to set how much of each quaternion to keep For smoother interpolation, `#slerp(q0, q1, theta)` can be used instead.
Parameters:
`q0` - quaternion at theta=0
`q1` - quaternion at theta=1
`t0` - theta value for q0 amount (range 0 to 1)
`t1` - theta value for q1 amount (range 0 to 1)
Returns:
lerp result
• #### lerp

```public static Quaternion lerp(Quaternion q0,
Quaternion q1,
double theta)```
Performs a linear interpolation between two quaternions. For smoother interpolation, `#slerp(q0, q1, theta)` can be used instead.
Parameters:
`q0` - quaternion at theta=0
`q1` - quaternion at theta=1
`theta` - value (range 0 to 1)
Returns:
lerp result
• #### slerp

```public static Quaternion slerp(Quaternion q0,
Quaternion q1,
double theta)```
Performs a spherical interpolation between two quaternions.
Parameters:
`q0` - quaternion at theta=0
`q1` - quaternion at theta=0
`theta` - value (range 0 to 1)
Returns:
slerp result