public final class Quaternion extends Object implements Serializable
Wherever quaternion components are listed in sequence, this class follows the
convention of placing the scalar (w
) component first, e.g. [w, x, y, z
].
Other libraries and textbooks may place the w
component last.
Instances of this class are guaranteed to be immutable.
Modifier and Type | Field and Description |
---|---|
static Quaternion |
I
i.
|
static Quaternion |
J
j.
|
static Quaternion |
K
k.
|
static Quaternion |
ONE
Identity quaternion.
|
static Quaternion |
ZERO
Zero quaternion.
|
Modifier and Type | Method and Description |
---|---|
Quaternion |
add(Quaternion q)
Computes the sum of the instance and another quaternion.
|
static Quaternion |
add(Quaternion q1,
Quaternion q2)
Computes the sum of two quaternions.
|
Quaternion |
conjugate()
Returns the conjugate of this quaternion number.
|
Quaternion |
divide(double alpha)
Divides the instance by a scalar.
|
double |
dot(Quaternion q)
Computes the dot-product of the instance by a quaternion.
|
static double |
dot(Quaternion q1,
Quaternion q2)
Computes the dot-product of two quaternions.
|
boolean |
equals(Object other) |
boolean |
equals(Quaternion q,
double eps)
Checks whether this instance is equal to another quaternion
within a given tolerance.
|
double |
getScalarPart()
Gets the scalar part of the quaternion.
|
double[] |
getVectorPart()
Gets the three components of the vector part of the quaternion.
|
double |
getW()
Gets the first component of the quaternion (scalar part).
|
double |
getX()
Gets the second component of the quaternion (first component
of the vector part).
|
double |
getY()
Gets the third component of the quaternion (second component
of the vector part).
|
double |
getZ()
Gets the fourth component of the quaternion (third component
of the vector part).
|
int |
hashCode() |
Quaternion |
inverse()
Returns the inverse of this instance.
|
boolean |
isPure(double eps)
Checks whether the instance is a pure quaternion within a given
tolerance.
|
boolean |
isUnit(double eps)
Checks whether the instance is a unit quaternion within a given
tolerance.
|
Quaternion |
multiply(double alpha)
Multiplies the instance by a scalar.
|
Quaternion |
multiply(Quaternion q)
Returns the Hamilton product of the instance by a quaternion.
|
static Quaternion |
multiply(Quaternion q1,
Quaternion q2)
Returns the Hamilton product of two quaternions.
|
Quaternion |
negate()
Returns the opposite of this instance.
|
double |
norm()
Computes the norm of the quaternion.
|
Quaternion |
normalize()
Computes the normalized quaternion (the versor of the instance).
|
double |
normSq()
Computes the square of the norm of the quaternion.
|
static Quaternion |
of(double[] v)
Builds a pure quaternion from a vector (assuming that the scalar
part is zero).
|
static Quaternion |
of(double scalar,
double[] v)
Builds a quaternion from scalar and vector parts.
|
static Quaternion |
of(double w,
double x,
double y,
double z)
Builds a quaternion from its components.
|
static Quaternion |
parse(String s)
Parses a string that would be produced by
toString()
and instantiates the corresponding object. |
Quaternion |
positivePolarForm()
Returns the polar form of the quaternion.
|
Quaternion |
subtract(Quaternion q)
Subtracts a quaternion from the instance.
|
static Quaternion |
subtract(Quaternion q1,
Quaternion q2)
Subtracts two quaternions.
|
String |
toString() |
public static final Quaternion ZERO
public static final Quaternion ONE
public static final Quaternion I
public static final Quaternion J
public static final Quaternion K
public static Quaternion of(double w, double x, double y, double z)
w
- Scalar component.x
- First vector component.y
- Second vector component.z
- Third vector component.public static Quaternion of(double scalar, double[] v)
scalar
- Scalar part of the quaternion.v
- Components of the vector part of the quaternion.IllegalArgumentException
- if the array length is not 3.public static Quaternion of(double[] v)
v
- Components of the vector part of the pure quaternion.public Quaternion conjugate()
a + bi + cj + dk
is a - bi -cj -dk
.public static Quaternion multiply(Quaternion q1, Quaternion q2)
q1
- First quaternion.q2
- Second quaternion.q1
and q2
, in that order.public Quaternion multiply(Quaternion q)
q
- Quaternion.q
, in that order.public static Quaternion add(Quaternion q1, Quaternion q2)
q1
- Quaternion.q2
- Quaternion.q1
and q2
.public Quaternion add(Quaternion q)
q
- Quaternion.q
.public static Quaternion subtract(Quaternion q1, Quaternion q2)
q1
- First Quaternion.q2
- Second quaternion.q1
and q2
.public Quaternion subtract(Quaternion q)
q
- Quaternion.q
.public static double dot(Quaternion q1, Quaternion q2)
q1
- Quaternion.q2
- Quaternion.q1
and q2
.public double dot(Quaternion q)
q
- Quaternion.q
.public double norm()
public double normSq()
public Quaternion normalize()
IllegalStateException
- if the norm of the quaternion is NaN, infinite,
or near zero.public boolean equals(Quaternion q, double eps)
q
- Quaternion with which to compare the current quaternion.eps
- Tolerance.true
if the each of the components are equal
within the allowed absolute error.public boolean isUnit(double eps)
eps
- Tolerance (absolute error).true
if the norm is 1 within the given tolerance,
false
otherwisepublic boolean isPure(double eps)
eps
- Tolerance (absolute error).true
if the scalar part of the quaternion is zero.public Quaternion positivePolarForm()
public Quaternion negate()
public Quaternion inverse()
IllegalStateException
- if the norm (squared) of the quaternion is NaN,
infinite, or near zero.public double getW()
public double getX()
public double getY()
public double getZ()
public double getScalarPart()
getW()
public double[] getVectorPart()
public Quaternion multiply(double alpha)
alpha
- Scalar factor.public Quaternion divide(double alpha)
alpha
- Scalar factor.public static Quaternion parse(String s)
toString()
and instantiates the corresponding object.s
- String representation.NumberFormatException
- if the string does not conform
to the specification.Copyright © 2017–2022 The Apache Software Foundation. All rights reserved.