Class Quatd
- All Implemented Interfaces:
Cloneable
Methods with names ending in "Local" modify the current instance. They are used to avoid creating temporary objects.
Mathematically, quaternions are an extension of complex numbers. In mathematics texts, W often appears first, but here the conventional order is (X, Y, Z, W).
-
Field Summary
-
Constructor Summary
ConstructorDescriptionQuatd()
Instantiates an identity quaternion: all components zeroed exceptw
, which is set to 1.Quatd
(double x, double y, double z, double w) Instantiates a quaternion with the specified components.Quatd
(Quaternion quat) Instantiates based on the specified (single-precision) Quaternion.Instantiates a copy of the argument. -
Method Summary
Modifier and TypeMethodDescriptionfinal Quatd
clone()
Creates a copy.boolean
Tests for exact equality with the argument, distinguishing -0 from 0.fromAngles
(double xAngle, double yAngle, double zAngle) Builds a Quaternion from the Euler rotation angles (x,y,z) aka (pitch, yaw, roll).int
hashCode()
Returns a hash code.inverse()
Returns the multiplicative inverse.boolean
Tests for an identity rotation.boolean
isZero()
Tests for a zero value.final double
lengthSq()
Returns the squared length.final Quatd
Takes the Hamilton product of the current instance times the argument to yield a new Quatd.final Quatd
Takes the Hamilton product of the current instance times the first argument and returns the product in the 2nd argument.Rotates the argument vector to produce a new vector.Rotates a specified vector and return the result in another vector.final Quatd
Takes the Hamilton product of the current instance times the argument, in place.final Quatd
Normalizes the current instance in place.final Quatd
set
(double x, double y, double z, double w) Sets all 4 components to the specified values.final Quatd
set
(Quaternion quat) Copies all 4 components of the specified (single-precision) Quaternion to the current instance.final Quatd
Copies all 4 components from the argument.Creates a (single-precision) Quaternion that approximates the current instance.Converts the quaternion to an equivalent rotation matrix.toString()
Returns a string representation of the quaternion, which is unaffected.
-
Field Details
-
x
public double xThe first imaginary (X) component. Not an angle! -
y
public double yThe 2nd imaginary (Y) component. Not an angle! -
z
public double zThe 3rd imaginary (Z) component. Not an angle! -
w
public double wThe real (W) component. Not an angle!
-
-
Constructor Details
-
Quatd
public Quatd()Instantiates an identity quaternion: all components zeroed exceptw
, which is set to 1. -
Quatd
public Quatd(double x, double y, double z, double w) Instantiates a quaternion with the specified components.- Parameters:
x
- the desired X componenty
- the desired Y componentz
- the desired Z componentw
- the desired W component
-
Quatd
Instantiates a copy of the argument.- Parameters:
quat
- the quaternion to copy (not null, unaffected)
-
Quatd
Instantiates based on the specified (single-precision) Quaternion.- Parameters:
quat
- the input Quaternion (not null, unaffected)
-
-
Method Details
-
clone
Creates a copy. The current instance is unaffected. -
toQuaternion
Creates a (single-precision) Quaternion that approximates the current instance.- Returns:
- a new Quaternion
-
hashCode
public int hashCode()Returns a hash code. If two quaternions have identical values, they will have the same hash code. The current instance is unaffected. -
equals
Tests for exact equality with the argument, distinguishing -0 from 0. Ifo
is null, false is returned. Either way, the current instance is unaffected. -
isRotationIdentity
public boolean isRotationIdentity()Tests for an identity rotation. The quaternion is unaffected.- Returns:
- true if W is non-zero and not NaN and X, Y, and Z are all 0 or -0, otherwise false
-
isZero
public boolean isZero()Tests for a zero value. The quaternion is unaffected.- Returns:
- true if all components are 0 or -0, otherwise false
-
set
Sets all 4 components to the specified values.- Parameters:
x
- the desired X componenty
- the desired Y componentz
- the desired Z componentw
- the desired W component- Returns:
- the (modified) current instance (for chaining)
-
set
Copies all 4 components from the argument.- Parameters:
q
- the quaternion to copy (not null, unaffected)- Returns:
- the (modified) current instance (for chaining)
-
set
Copies all 4 components of the specified (single-precision) Quaternion to the current instance.- Parameters:
quat
- the input Quaternion (not null, unaffected)- Returns:
- the (modified) current instance (for chaining)
-
mult
Takes the Hamilton product of the current instance times the argument to yield a new Quatd. The current instance is unaffected.It is safe for
q
andthis
to be the same object.This method is used to combine rotations. Note that the Hamilton product is noncommutative, so generally q * p != p * q.
- Parameters:
q
- the right factor (not null, unaffected)- Returns:
this * q
(a new instance)
-
mult
Takes the Hamilton product of the current instance times the first argument and returns the product in the 2nd argument. The current instance is unaffected, unless it'sresult
.This method is used to combine rotations. Note that the Hamilton product is noncommutative, so generally q * p != p * q.
It is safe for any or all of
q
,result
, andthis
to be the same object.- Parameters:
q
- the right factor (not null, unaffected unless it'sresult
)result
- storage for the product, or null for a new Quatd- Returns:
this * q
(eitherresult
or a new Quatd)
-
multLocal
Takes the Hamilton product of the current instance times the argument, in place.This method is used to combine rotations. Note that the Hamilton product is noncommutative, so generally q * p != p * q.
It IS safe for
q
andthis
to be the same object.- Parameters:
q
- the right factor (not null, unaffected unless it'sthis
)- Returns:
- the (modified) current instance (for chaining)
-
mult
Rotates the argument vector to produce a new vector. The quaternion is unaffected.- Parameters:
v
- the input vector (not null, unaffected)- Returns:
- a new instance
-
mult
Rotates a specified vector and return the result in another vector. The quaternion is unaffected.It IS safe for
v
andresult
to be the same object.- Parameters:
v
- the vector to rotate (not null, unaffected unless it'sresult
)result
- storage for the result (not null)- Returns:
- the (rotated) vector
result
-
lengthSq
public final double lengthSq()Returns the squared length.- Returns:
- the squared length (≥0)
-
normalizeLocal
Normalizes the current instance in place.- Returns:
- the (modified) current instance (for chaining)
-
toRotationMatrix
Converts the quaternion to an equivalent rotation matrix. The quaternion is unaffected.Note: the result is created from a normalized version of the current instance.
- Returns:
- a new 3x3 rotation matrix
-
inverse
Returns the multiplicative inverse. For a quaternion with norm=0,null
is returned. Either way, the current instance is unaffected.- Returns:
- a new instance, or null if not invertible
-
fromAngles
Builds a Quaternion from the Euler rotation angles (x,y,z) aka (pitch, yaw, roll). They are applied in order: (y, z, x) aka (yaw, roll, pitch).- Parameters:
xAngle
- the desired rotation about the +X axis (in radians)yAngle
- the desired rotation about the +Y axis (in radians)zAngle
- the desired rotation about the +Z axis (in radians)- Returns:
- the (modified) current instance (for chaining)
- See Also:
-
toString
Returns a string representation of the quaternion, which is unaffected. For example, the identity quaternion is represented by:Quatd[0.0, 0.0, 0.0, 1.0]
-