pythagoras.d

## Class Quaternion

• ### Field Summary

Fields
Modifier and Type Field and Description
`static IQuaternion` `IDENTITY`
The identity quaternion.
`double` `w`
The components of the quaternion.
`double` `x`
The components of the quaternion.
`double` `y`
The components of the quaternion.
`double` `z`
The components of the quaternion.
• ### Constructor Summary

Constructors
Constructor and Description
`Quaternion()`
Creates an identity quaternion.
`Quaternion(double[] values)`
Creates a quaternion from an array of values.
```Quaternion(double x, double y, double z, double w)```
Creates a quaternion from four components.
`Quaternion(IQuaternion other)`
Copy constructor.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`boolean` `equals(Object other)`
`Quaternion` ```fromAngleAxis(double angle, double x, double y, double z)```
Sets this quaternion to the rotation described by the given angle and normalized axis.
`Quaternion` ```fromAngleAxis(double angle, IVector3 axis)```
Sets this quaternion to the rotation described by the given angle and normalized axis.
`Quaternion` ```fromAngles(double x, double y, double z)```
Sets this quaternion to one that first rotates about x by the specified number of radians, then rotates about y, then about z.
`Quaternion` `fromAngles(Vector3 angles)`
Sets this quaternion to one that first rotates about x by the specified number of radians, then rotates about y, then about z.
`Quaternion` ```fromAnglesXY(double x, double y)```
Sets this quaternion to one that first rotates about x by the specified number of radians, then rotates about y by the specified number of radians.
`Quaternion` ```fromAnglesXZ(double x, double z)```
Sets this quaternion to one that first rotates about x by the specified number of radians, then rotates about z by the specified number of radians.
`Quaternion` ```fromAxes(IVector3 nx, IVector3 ny, IVector3 nz)```
Sets this quaternion to one that rotates onto the given unit axes.
`Quaternion` ```fromVectorFromNegativeZ(double tx, double ty, double tz)```
Sets this quaternion to the rotation of (0, 0, -1) onto the supplied normalized vector.
`Quaternion` `fromVectorFromNegativeZ(IVector3 to)`
Sets this quaternion to the rotation of (0, 0, -1) onto the supplied normalized vector.
`Quaternion` ```fromVectors(IVector3 from, IVector3 to)```
Sets this quaternion to the rotation of the first normalized vector onto the second.
`void` `get(double[] values)`
Populates the supplied array with the contents of this quaternion.
`double` `getRotationZ()`
Returns the amount of rotation about the z axis (for the purpose of flattening the rotation).
`int` `hashCode()`
`boolean` `hasNaN()`
Checks whether any of the components of this quaternion are not-numbers.
`Quaternion` ```integrate(IVector3 velocity, double t)```
Integrates the provided angular velocity over the specified timestep.
`Quaternion` ```integrate(IVector3 velocity, double t, Quaternion result)```
Integrates the provided angular velocity over the specified timestep, storing the result in the object provided.
`Quaternion` ```integrateLocal(IVector3 velocity, double t)```
Integrates in-place the provided angular velocity over the specified timestep.
`Quaternion` `invert()`
Inverts this quaternion.
`Quaternion` `invert(Quaternion result)`
Inverts this quaternion, storing the result in the object provided.
`Quaternion` `invertLocal()`
Inverts this quaternion in-place.
`Quaternion` `mult(IQuaternion other)`
Multiplies this quaternion by another.
`Quaternion` ```mult(IQuaternion other, Quaternion result)```
Multiplies this quaternion by another and stores the result in the provided object.
`Quaternion` `multLocal(IQuaternion other)`
Multiplies this quaternion in-place by another.
`Quaternion` `normalize()`
Normalizes this quaternion.
`Quaternion` `normalize(Quaternion result)`
Normalizes this quaternion, storing the result in the object provided.
`Quaternion` `normalizeLocal()`
Normalizes this quaternion in-place.
`Quaternion` `randomize(Random rand)`
Sets this to a random rotation obtained from a completely uniform distribution.
`Quaternion` `set(double[] values)`
Copies the elements of an array.
`Quaternion` ```set(double x, double y, double z, double w)```
Sets all of the elements of the quaternion.
`Quaternion` `set(IQuaternion other)`
Copies the elements of another quaternion.
`Quaternion` ```slerp(IQuaternion other, double t)```
Interpolates between this and the specified other quaternion.
`Quaternion` ```slerp(IQuaternion other, double t, Quaternion result)```
Interpolates between this and the specified other quaternion, placing the result in the object provided.
`Quaternion` ```slerpLocal(IQuaternion other, double t)```
Interpolates in-place between this and the specified other quaternion.
`Vector3` `toAngles()`
Computes and returns the angles to pass to `fromAngles(pythagoras.d.Vector3)` to reproduce this rotation.
`Vector3` `toAngles(Vector3 result)`
Computes the angles to pass to `fromAngles(pythagoras.d.Vector3)` to reproduce this rotation, placing them in the provided vector.
`String` `toString()`
`Vector3` `transform(IVector3 vector)`
Transforms a vector by this quaternion.
`Vector3` ```transform(IVector3 vector, Vector3 result)```
Transforms a vector by this quaternion and places the result in the provided object.
`Vector3` ```transformAndAdd(IVector3 vector, IVector3 add, Vector3 result)```
Transforms a vector by this quaternion and adds another vector to it, placing the result in the object provided.
`Vector3` `transformLocal(Vector3 vector)`
Transforms a vector in-place by this quaternion.
`Vector3` ```transformScaleAndAdd(IVector3 vector, double scale, IVector3 add, Vector3 result)```
Transforms a vector by this quaternion, applies a uniform scale, and adds another vector to it, placing the result in the object provided.
`Vector3` `transformUnitX(Vector3 result)`
Transforms the unit x vector by this quaternion, placing the result in the provided object.
`Vector3` `transformUnitY(Vector3 result)`
Transforms the unit y vector by this quaternion, placing the result in the provided object.
`Vector3` `transformUnitZ(Vector3 result)`
Transforms the unit z vector by this quaternion, placing the result in the provided object.
`double` `transformZ(IVector3 vector)`
Transforms a vector by this quaternion and returns the z coordinate of the result.
`double` `w()`
Returns the w-component of this quaternion.
`double` `x()`
Returns the x-component of this quaternion.
`double` `y()`
Returns the y-component of this quaternion.
`double` `z()`
Returns the z-component of this quaternion.
• ### Methods inherited from class java.lang.Object

`getClass, notify, notifyAll, wait, wait, wait`
• ### Field Detail

• #### IDENTITY

`public static final IQuaternion IDENTITY`
The identity quaternion.
• #### x

`public double x`
The components of the quaternion.
• #### y

`public double y`
The components of the quaternion.
• #### z

`public double z`
The components of the quaternion.
• #### w

`public double w`
The components of the quaternion.
• ### Constructor Detail

• #### Quaternion

```public Quaternion(double x,
double y,
double z,
double w)```
Creates a quaternion from four components.
• #### Quaternion

`public Quaternion(double[] values)`
Creates a quaternion from an array of values.
• #### Quaternion

`public Quaternion(IQuaternion other)`
Copy constructor.
• #### Quaternion

`public Quaternion()`
Creates an identity quaternion.
• ### Method Detail

• #### set

`public Quaternion set(IQuaternion other)`
Copies the elements of another quaternion.
Returns:
a reference to this quaternion, for chaining.
• #### set

`public Quaternion set(double[] values)`
Copies the elements of an array.
Returns:
a reference to this quaternion, for chaining.
• #### set

```public Quaternion set(double x,
double y,
double z,
double w)```
Sets all of the elements of the quaternion.
Returns:
a reference to this quaternion, for chaining.
• #### fromVectors

```public Quaternion fromVectors(IVector3 from,
IVector3 to)```
Sets this quaternion to the rotation of the first normalized vector onto the second.
Returns:
a reference to this quaternion, for chaining.
• #### fromVectorFromNegativeZ

`public Quaternion fromVectorFromNegativeZ(IVector3 to)`
Sets this quaternion to the rotation of (0, 0, -1) onto the supplied normalized vector.
Returns:
a reference to the quaternion, for chaining.
• #### fromVectorFromNegativeZ

```public Quaternion fromVectorFromNegativeZ(double tx,
double ty,
double tz)```
Sets this quaternion to the rotation of (0, 0, -1) onto the supplied normalized vector.
Returns:
a reference to the quaternion, for chaining.
• #### fromAxes

```public Quaternion fromAxes(IVector3 nx,
IVector3 ny,
IVector3 nz)```
Sets this quaternion to one that rotates onto the given unit axes.
Returns:
a reference to this quaternion, for chaining.
• #### fromAngleAxis

```public Quaternion fromAngleAxis(double angle,
IVector3 axis)```
Sets this quaternion to the rotation described by the given angle and normalized axis.
Returns:
a reference to this quaternion, for chaining.
• #### fromAngleAxis

```public Quaternion fromAngleAxis(double angle,
double x,
double y,
double z)```
Sets this quaternion to the rotation described by the given angle and normalized axis.
Returns:
a reference to this quaternion, for chaining.
• #### randomize

`public Quaternion randomize(Random rand)`
Sets this to a random rotation obtained from a completely uniform distribution.
• #### fromAnglesXZ

```public Quaternion fromAnglesXZ(double x,
double z)```
Sets this quaternion to one that first rotates about x by the specified number of radians, then rotates about z by the specified number of radians.
• #### fromAnglesXY

```public Quaternion fromAnglesXY(double x,
double y)```
Sets this quaternion to one that first rotates about x by the specified number of radians, then rotates about y by the specified number of radians.
• #### fromAngles

`public Quaternion fromAngles(Vector3 angles)`
Sets this quaternion to one that first rotates about x by the specified number of radians, then rotates about y, then about z.
• #### fromAngles

```public Quaternion fromAngles(double x,
double y,
double z)```
Sets this quaternion to one that first rotates about x by the specified number of radians, then rotates about y, then about z.
• #### normalizeLocal

`public Quaternion normalizeLocal()`
Normalizes this quaternion in-place.
Returns:
a reference to this quaternion, for chaining.
• #### invertLocal

`public Quaternion invertLocal()`
Inverts this quaternion in-place.
Returns:
a reference to this quaternion, for chaining.
• #### multLocal

`public Quaternion multLocal(IQuaternion other)`
Multiplies this quaternion in-place by another.
Returns:
a reference to this quaternion, for chaining.
• #### slerpLocal

```public Quaternion slerpLocal(IQuaternion other,
double t)```
Interpolates in-place between this and the specified other quaternion.
Returns:
a reference to this quaternion, for chaining.
• #### transformLocal

`public Vector3 transformLocal(Vector3 vector)`
Transforms a vector in-place by this quaternion.
Returns:
a reference to the vector, for chaining.
• #### integrateLocal

```public Quaternion integrateLocal(IVector3 velocity,
double t)```
Integrates in-place the provided angular velocity over the specified timestep.
Returns:
a reference to this quaternion, for chaining.
• #### x

`public double x()`
Description copied from interface: `IQuaternion`
Returns the x-component of this quaternion.
Specified by:
`x` in interface `IQuaternion`
• #### y

`public double y()`
Description copied from interface: `IQuaternion`
Returns the y-component of this quaternion.
Specified by:
`y` in interface `IQuaternion`
• #### z

`public double z()`
Description copied from interface: `IQuaternion`
Returns the z-component of this quaternion.
Specified by:
`z` in interface `IQuaternion`
• #### w

`public double w()`
Description copied from interface: `IQuaternion`
Returns the w-component of this quaternion.
Specified by:
`w` in interface `IQuaternion`
• #### get

`public void get(double[] values)`
Description copied from interface: `IQuaternion`
Populates the supplied array with the contents of this quaternion.
Specified by:
`get` in interface `IQuaternion`
• #### hasNaN

`public boolean hasNaN()`
Description copied from interface: `IQuaternion`
Checks whether any of the components of this quaternion are not-numbers.
Specified by:
`hasNaN` in interface `IQuaternion`
• #### toAngles

`public Vector3 toAngles(Vector3 result)`
Description copied from interface: `IQuaternion`
Computes the angles to pass to `fromAngles(pythagoras.d.Vector3)` to reproduce this rotation, placing them in the provided vector. This uses the factorization method described in David Eberly's Euler Angle Formulas.
Specified by:
`toAngles` in interface `IQuaternion`
Returns:
a reference to the result vector, for chaining.
• #### toAngles

`public Vector3 toAngles()`
Description copied from interface: `IQuaternion`
Computes and returns the angles to pass to `fromAngles(pythagoras.d.Vector3)` to reproduce this rotation.
Specified by:
`toAngles` in interface `IQuaternion`
Returns:
a new vector containing the resulting angles.
• #### normalize

`public Quaternion normalize()`
Description copied from interface: `IQuaternion`
Normalizes this quaternion.
Specified by:
`normalize` in interface `IQuaternion`
Returns:
a new quaternion containing the result.
• #### normalize

`public Quaternion normalize(Quaternion result)`
Description copied from interface: `IQuaternion`
Normalizes this quaternion, storing the result in the object provided.
Specified by:
`normalize` in interface `IQuaternion`
Returns:
a reference to the result, for chaining.
• #### invert

`public Quaternion invert()`
Description copied from interface: `IQuaternion`
Inverts this quaternion.
Specified by:
`invert` in interface `IQuaternion`
Returns:
a new quaternion containing the result.
• #### invert

`public Quaternion invert(Quaternion result)`
Description copied from interface: `IQuaternion`
Inverts this quaternion, storing the result in the object provided.
Specified by:
`invert` in interface `IQuaternion`
Returns:
a reference to the result, for chaining.
• #### mult

`public Quaternion mult(IQuaternion other)`
Description copied from interface: `IQuaternion`
Multiplies this quaternion by another.
Specified by:
`mult` in interface `IQuaternion`
Returns:
a new quaternion containing the result.
• #### mult

```public Quaternion mult(IQuaternion other,
Quaternion result)```
Description copied from interface: `IQuaternion`
Multiplies this quaternion by another and stores the result in the provided object.
Specified by:
`mult` in interface `IQuaternion`
Returns:
a reference to the result, for chaining.
• #### slerp

```public Quaternion slerp(IQuaternion other,
double t)```
Description copied from interface: `IQuaternion`
Interpolates between this and the specified other quaternion.
Specified by:
`slerp` in interface `IQuaternion`
Returns:
a new quaternion containing the result.
• #### slerp

```public Quaternion slerp(IQuaternion other,
double t,
Quaternion result)```
Description copied from interface: `IQuaternion`
Interpolates between this and the specified other quaternion, placing the result in the object provided. Based on the code in Nick Bobick's article, Rotating Objects Using Quaternions.
Specified by:
`slerp` in interface `IQuaternion`
Returns:
a reference to the result quaternion, for chaining.
• #### transform

`public Vector3 transform(IVector3 vector)`
Description copied from interface: `IQuaternion`
Transforms a vector by this quaternion.
Specified by:
`transform` in interface `IQuaternion`
Returns:
a new vector containing the result.
• #### transform

```public Vector3 transform(IVector3 vector,
Vector3 result)```
Description copied from interface: `IQuaternion`
Transforms a vector by this quaternion and places the result in the provided object.
Specified by:
`transform` in interface `IQuaternion`
Returns:
a reference to the result, for chaining.
• #### transformUnitX

`public Vector3 transformUnitX(Vector3 result)`
Description copied from interface: `IQuaternion`
Transforms the unit x vector by this quaternion, placing the result in the provided object.
Specified by:
`transformUnitX` in interface `IQuaternion`
Returns:
a reference to the result, for chaining.
• #### transformUnitY

`public Vector3 transformUnitY(Vector3 result)`
Description copied from interface: `IQuaternion`
Transforms the unit y vector by this quaternion, placing the result in the provided object.
Specified by:
`transformUnitY` in interface `IQuaternion`
Returns:
a reference to the result, for chaining.
• #### transformUnitZ

`public Vector3 transformUnitZ(Vector3 result)`
Description copied from interface: `IQuaternion`
Transforms the unit z vector by this quaternion, placing the result in the provided object.
Specified by:
`transformUnitZ` in interface `IQuaternion`
Returns:
a reference to the result, for chaining.

```public Vector3 transformAndAdd(IVector3 vector,
Vector3 result)```
Description copied from interface: `IQuaternion`
Transforms a vector by this quaternion and adds another vector to it, placing the result in the object provided.
Specified by:
`transformAndAdd` in interface `IQuaternion`
Returns:
a reference to the result, for chaining.

```public Vector3 transformScaleAndAdd(IVector3 vector,
double scale,
Vector3 result)```
Description copied from interface: `IQuaternion`
Transforms a vector by this quaternion, applies a uniform scale, and adds another vector to it, placing the result in the object provided.
Specified by:
`transformScaleAndAdd` in interface `IQuaternion`
Returns:
a reference to the result, for chaining.
• #### transformZ

`public double transformZ(IVector3 vector)`
Description copied from interface: `IQuaternion`
Transforms a vector by this quaternion and returns the z coordinate of the result.
Specified by:
`transformZ` in interface `IQuaternion`
• #### getRotationZ

`public double getRotationZ()`
Description copied from interface: `IQuaternion`
Returns the amount of rotation about the z axis (for the purpose of flattening the rotation).
Specified by:
`getRotationZ` in interface `IQuaternion`
• #### integrate

```public Quaternion integrate(IVector3 velocity,
double t)```
Description copied from interface: `IQuaternion`
Integrates the provided angular velocity over the specified timestep.
Specified by:
`integrate` in interface `IQuaternion`
Returns:
a new quaternion containing the result.
• #### integrate

```public Quaternion integrate(IVector3 velocity,
double t,
Quaternion result)```
Description copied from interface: `IQuaternion`
Integrates the provided angular velocity over the specified timestep, storing the result in the object provided.
Specified by:
`integrate` in interface `IQuaternion`
Returns:
a reference to the result object, for chaining.
• #### toString

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

`public int hashCode()`
Overrides:
`hashCode` in class `Object`
• #### equals

`public boolean equals(Object other)`
Overrides:
`equals` in class `Object`