public final class QuaternionRotation extends Object implements Rotation3D
w
).Quaternion
Modifier and Type | Method and Description |
---|---|
Vector3D |
apply(Vector3D v)
Apply this rotation to the given vector.
|
Vector3D |
applyVector(Vector3D vec)
Apply this transform to the given vector, ignoring translations.
|
static QuaternionRotation |
createBasisRotation(Vector3D u1,
Vector3D u2,
Vector3D v1,
Vector3D v2)
Return an instance that rotates the basis defined by the first two vectors into the basis
defined by the second two.
|
static QuaternionRotation |
createVectorRotation(Vector3D u,
Vector3D v)
Return an instance that rotates the first vector to the second.
|
boolean |
equals(Object obj) |
static QuaternionRotation |
fromAxisAngle(Vector3D axis,
double angle)
Create a new instance representing a rotation of
angle radians around
axis . |
static QuaternionRotation |
fromAxisAngleSequence(AxisAngleSequence sequence)
Create a new instance equivalent to the given sequence of axis-angle rotations.
|
double |
getAngle()
Get the angle of rotation in radians.
|
Vector3D |
getAxis()
Get the axis of rotation as a normalized
Vector3D . |
Quaternion |
getQuaternion()
Get the underlying quaternion instance.
|
int |
hashCode() |
static QuaternionRotation |
identity()
Return an instance representing a rotation of zero.
|
QuaternionRotation |
inverse()
Get the inverse of this rotation.
|
QuaternionRotation |
multiply(QuaternionRotation q)
Multiply this instance by the given argument, returning the result as
a new instance.
|
static QuaternionRotation |
of(double w,
double x,
double y,
double z)
Create a new instance from the given quaternion values.
|
static QuaternionRotation |
of(Quaternion quat)
Create a new instance from the given quaternion.
|
QuaternionRotation |
premultiply(QuaternionRotation q)
Multiply the argument by this instance, returning the result as
a new instance.
|
boolean |
preservesOrientation() |
DoubleFunction<QuaternionRotation> |
slerp(QuaternionRotation end)
Creates a function that performs a
spherical
linear interpolation between this instance and the argument.
|
AxisAngleSequence |
toAbsoluteAxisAngleSequence(AxisSequence axes)
Get a sequence of axis-angle rotations that produce an overall rotation equivalent to this instance.
|
AxisAngleSequence |
toAxisAngleSequence(AxisReferenceFrame frame,
AxisSequence axes)
Get a sequence of axis-angle rotations that produce an overall rotation equivalent to this instance.
|
AffineTransformMatrix3D |
toMatrix()
Return an
AffineTransformMatrix3D representing the same rotation as this
instance. |
AxisAngleSequence |
toRelativeAxisAngleSequence(AxisSequence axes)
Get a sequence of axis-angle rotations that produce an overall rotation equivalent to this instance.
|
String |
toString() |
public Quaternion getQuaternion()
public Vector3D getAxis()
Vector3D
. The rotation axis
is not well defined when the rotation is the identity rotation, ie it has a
rotation angle of zero. In this case, the vector representing the positive
x-axis is returned.getAxis
in interface Rotation3D
Rotation3D.getAngle()
public double getAngle()
pi
.getAngle
in interface Rotation3D
[0, pi]
.Rotation3D.getAxis()
public QuaternionRotation inverse()
r.apply(u)
is equal to v
, then r.negate().apply(v)
is equal
to u
.inverse
in interface Transform<Vector3D>
inverse
in interface Rotation3D
public Vector3D applyVector(Vector3D vec)
This method can be used to transform vector instances representing displacements between points.
For example, if v
represents the difference between points p1
and p2
,
then transform.applyVector(v)
will represent the difference between p1
and p2
after transform
is applied.
This method simply calls apply(vec)
since rotations treat
points and vectors similarly.
applyVector
in interface EuclideanTransform<Vector3D>
vec
- the vector to transformpublic boolean preservesOrientation()
This method simply returns true since rotations always preserve the orientation of the space.
preservesOrientation
in interface Transform<Vector3D>
public AffineTransformMatrix3D toMatrix()
AffineTransformMatrix3D
representing the same rotation as this
instance.public QuaternionRotation multiply(QuaternionRotation q)
t * q
where
q
is the argument and t
is this instance.
Multiplication of quaternions behaves similarly to transformation
matrices in regard to the order that operations are performed.
For example, if q1
and q2
are unit
quaternions, then the quaternion qr = q1*q2
will give the effect of applying the rotation in q2
followed
by the rotation in q1
. In other words, the rightmost element
in the multiplication is applied first.
q
- quaternion to multiply with the current instancepublic QuaternionRotation premultiply(QuaternionRotation q)
q * t
where
q
is the argument and t
is this instance.
Multiplication of quaternions behaves similarly to transformation
matrices in regard to the order that operations are performed.
For example, if q1
and q2
are unit
quaternions, then the quaternion qr = q1*q2
will give the effect of applying the rotation in q2
followed
by the rotation in q1
. In other words, the rightmost element
in the multiplication is applied first.
q
- quaternion to multiply by the current instancepublic DoubleFunction<QuaternionRotation> slerp(QuaternionRotation end)
The argument to the function returned by this method is the
interpolation parameter t
.
If t = 0
, the rotation is equal to this instance.
If t = 1
, the rotation is equal to the end
instance.
All other values are interpolated (or extrapolated if t
is
outside of the [0, 1]
range).
end
- end value of the interpolationSlerp
public AxisAngleSequence toAxisAngleSequence(AxisReferenceFrame frame, AxisSequence axes)
In most cases, the returned rotation sequence will be unique. However, at points of singularity
(second angle equal to 0
or -pi
for Euler angles and +pi/2
or -pi/2
for Tait-Bryan angles), there are an infinite number of possible sequences that produce the same result.
In these cases, the result is returned that leaves the last rotation equal to 0 (in the case of a relative
reference frame) or the first rotation equal to 0 (in the case of an absolute reference frame).
frame
- the reference frame used to interpret the positions of the rotation axesaxes
- the sequence of rotation axespublic AxisAngleSequence toRelativeAxisAngleSequence(AxisSequence axes)
axes
- the sequence of rotation axestoAxisAngleSequence(AxisReferenceFrame, AxisSequence)
public AxisAngleSequence toAbsoluteAxisAngleSequence(AxisSequence axes)
axes
- the sequence of rotation axestoAxisAngleSequence(AxisReferenceFrame, AxisSequence)
public static QuaternionRotation of(Quaternion quat)
quat
- the quaternion to use for the rotationIllegalStateException
- if the the norm of the given components is zero,
NaN, or infiniteQuaternion.normalize()
,
Quaternion.positivePolarForm()
public static QuaternionRotation of(double w, double x, double y, double z)
w
- quaternion scalar componentx
- first quaternion vectorial componenty
- second quaternion vectorial componentz
- third quaternion vectorial componentIllegalStateException
- if the the norm of the given components is zero,
NaN, or infiniteQuaternion.normalize()
,
Quaternion.positivePolarForm()
public static QuaternionRotation identity()
public static QuaternionRotation fromAxisAngle(Vector3D axis, double angle)
angle
radians around
axis
.
Rotation direction follows the right-hand rule, meaning that if one places their right hand such that the thumb points in the direction of the vector, the curl of the fingers indicates the direction of rotation.
Note that the returned quaternion will represent the defined rotation but the values
returned by getAxis()
and getAngle()
may not match the ones given here.
This is because the axis and angle are normalized such that the axis has unit length,
and the angle lies in the range [0, pi]
. Depending on the inputs, the axis may
need to be inverted in order for the angle to lie in this range.
axis
- the axis of rotationangle
- angle of rotation in radiansIllegalArgumentException
- if the given axis cannot be normalized or the angle is NaN or infinitepublic static QuaternionRotation createVectorRotation(Vector3D u, Vector3D v)
Except for a possible scale factor, if the returned instance is
applied to vector u
, it will produce the vector v
. There are an
infinite number of such rotations; this method chooses the one with the smallest
associated angle, meaning the one whose axis is orthogonal to the (u, v)
plane. If u
and v
are collinear, an arbitrary rotation axis is
chosen.
u
- origin vectorv
- target vectoru
to point in the direction of v
IllegalArgumentException
- if either vector has a norm of zero, NaN, or infinitypublic static QuaternionRotation createBasisRotation(Vector3D u1, Vector3D u2, Vector3D v1, Vector3D v2)
The given basis vectors do not have to be directly orthogonal. A right-handed orthonormal basis is created from each pair by normalizing the first vector, making the second vector orthogonal to the first, and then taking the cross product. A rotation is then calculated that rotates the first to the second.
u1
- first vector of the source basisu2
- second vector of the source basisv1
- first vector of the target basisv2
- second vector of the target basisIllegalArgumentException
- if any of the input vectors cannot be normalized
or the vectors defining either basis are collinearpublic static QuaternionRotation fromAxisAngleSequence(AxisAngleSequence sequence)
sequence
- the axis-angle rotation sequence to convert to a quaternion rotationCopyright © 2016–2021 The Apache Software Foundation. All rights reserved.