public class Quaternion extends VectorBase
Modifier and Type | Field and Description |
---|---|
static Quaternion |
IDENTITY |
double |
s
Scalar element
|
Vector3d |
u
Vector element
|
static Quaternion |
ZERO |
Constructor and Description |
---|
Quaternion()
Creates a Quaternion and initializes its elements to 0.
|
Quaternion(AxisAngle axisAng)
Creates a Quaternion from an AxisAngle.
|
Quaternion(double s,
double ux,
double uy,
double uz)
Creates a Quaternion with the supplied element values.
|
Quaternion(double s,
Vector3d u)
Creates a Quaternion with the supplied element values.
|
Quaternion(Quaternion q)
Creates a Quaternion by copying an existing one.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Quaternion q1)
Adds this quaternion to q1 and places the result in this quaternion.
|
void |
add(Quaternion q1,
Quaternion q2)
Adds q1 quaternion to q2 and places the result in this quaternion.
|
java.lang.String |
axisAngleString() |
Quaternion |
clone() |
void |
combine(double r1,
Quaternion q1,
double r2,
Quaternion q2)
Computes
r1 q1 + r2 q2 and places the result in this
quaternion. |
void |
conjugate()
Conjugates this quaternion in place.
|
void |
conjugate(Quaternion q1)
Sets this quaternion to the conjugate of q1.
|
double |
distance(Quaternion q)
Returns the Euclidean distance between this quaternion and quaternion q.
|
double |
distanceSquared(Quaternion q)
Returns the squared of the Euclidean distance between this quaternion and
quaternion q.
|
double |
dot(Quaternion q1)
Returns the dot product of this quaternion and q1.
|
boolean |
epsilonEquals(Quaternion q1,
double eps)
Returns true if the elements of this quaternion equal those of quaternion
q1 within a prescribed tolerance epsilon . |
boolean |
equals(Quaternion q1)
Returns true if the elements of this quaternion exactly equal those of
quaternion
q1 . |
void |
extrapolateLocal(Quaternion q1,
Vector3d w,
double t)
Extrapolates a quaternion q1 by a constant angular velocity applied for
time t.
|
void |
extrapolateWorld(Quaternion q1,
Vector3d w,
double t)
Extrapolates a quaternion q1 by a constant angular velocity applied for
time t.
|
void |
get(double[] values)
Copies the elements of this quaternion into an array of doubles.
|
double |
get(int i)
Gets a single element of this quaternion.
|
void |
getAxisAngle(AxisAngle axisAng) |
void |
getRotationMatrix(RotationMatrix3d R) |
double |
infinityNorm()
Returns the infinity norm of this quaternion.
|
void |
interpolate(double r,
Quaternion q1)
Computes the interpolation
(1-r) this + r q1 and places the
result in this quaternion. |
void |
interpolate(Quaternion q1,
double r,
Quaternion q2)
Computes the interpolation
(1-r) q1 + r q2 and places the
result in this quaternion. |
void |
inverseTransform(Vector3d vr,
Vector3d v1)
Transforms a vector v1 by the inverse rotation implied by this
quaternion.
|
void |
invert()
Inverts this quaternion in place.
|
void |
invert(Quaternion q1)
Sets this quaternion to the inverse of q1.
|
double |
length()
Returns the 2 norm of this quaternion.
|
double |
lengthSquared()
Returns the square of the 2 norm of this quaternion.
|
double |
log(Vector3d v) |
void |
mul(Quaternion q1)
Multiplies this quaternion by quaternion q1 and places the result in this
quaternion.
|
void |
mul(Quaternion q1,
Quaternion q2)
Multiplies quaternion q1 by quaternion q2 and places the result in this
quaternion.
|
void |
mulInverse(Quaternion q1)
Post-multiplies this quaternion by the inverse of quaternion q1 and places
the result in this quaternion.
|
void |
mulInverseBoth(Quaternion q1,
Quaternion q2)
Multiplies the inverse of quaternion q1 by the inverse of quaternion q2
and places the result in this quaternion.
|
void |
mulInverseLeft(Quaternion q1,
Quaternion q2)
Multiplies the inverse of quaternion q1 by quaternion q2 and places the
result in this quaternion.
|
void |
mulInverseRight(Quaternion q1,
Quaternion q2)
Multiplies quaternion q1 by the inverse of quaternion q2 and places the
result in this quaternion.
|
void |
negate()
Negates this quaternion in place.
|
void |
negate(Quaternion q1)
Sets this quaternion to the negative of q1.
|
void |
normalize()
Normalizes this quaternion in place.
|
void |
normalize(Quaternion q1)
Computes a unit quaternion in the direction of q1 and places the result in
this quaternion.
|
void |
normalizedInterpolate(double r,
Quaternion q1)
Computes a normalized rotational interpolation between this quaternion and
q1 and places the result in this quaternion.
|
void |
normalizedInterpolate(Quaternion q1,
double r,
Quaternion q2)
Computes a normalized rotational interpolation between quaternions q1 and
q2 and places the result in this quaternion.
|
double |
oneNorm()
Returns the 1 norm of this quaternion.
|
double |
rotationAngle(Quaternion q1)
Returns the angular distance between the rotations represented by this
quaternion and q1.
|
void |
scale(double r)
Scales the elements of this quaternion by
r . |
void |
scale(double r,
Quaternion q1)
Scales the elements of quaternion q1 by
r and places the
results in this quaternion. |
void |
scaledAdd(double r,
Quaternion q1)
Computes
r q1 and add the result to this quaternion. |
void |
scaledAdd(double r,
Quaternion q1,
Quaternion q2)
Computes
r q1 + q2 and places the result in this
quaternion. |
void |
set(AxisAngle axisAng) |
void |
set(double[] values)
Sets the elements of this quaternion from an array of doubles.
|
int |
set(double[] values,
int idx)
Sets the elements of this quaternion from an array of doubles, starting
from a particular location.
|
void |
set(double s,
double ux,
double uy,
double uz)
Sets the elements of this quaternion to the prescribed values.
|
void |
set(double s,
Vector3d u)
Sets the elements of this quaternion to the prescribed values.
|
void |
set(int i,
double value)
Sets a single element of this quaternion.
|
void |
set(Quaternion q1)
Sets the values of this quaternion to those of q1.
|
void |
set(RotationMatrix3d R)
Sets this quaternion to a unit quaternion corresponding to a specified
rotation.
|
void |
setAxisAngle(AxisAngle axisAng)
Sets this quaternion to a unit quaternion corresponding to a specified
rotation.
|
void |
setAxisAngle(Vector3d axis,
double angle) |
void |
setExp(double scale,
Vector3d v) |
void |
setIdentity() |
void |
setRandom()
Sets the elements of this quaternion to uniformly distributed random
values in the range -0.5 (inclusive) to 0.5 (exclusive).
|
void |
setRandom(double lower,
double upper)
Sets the elements of this quaternion to uniformly distributed random
values in a specified range.
|
void |
setRandom(double lower,
double upper,
java.util.Random generator)
Sets the elements of this quaternion to uniformly distributed random
values in a specified range, using a supplied random number generator.
|
void |
setRandomUnit()
Sets this quaternion to a random unit value.
|
void |
setRandomUnit(java.util.Random generator)
Sets this quaternion to a random unit value, using a supplied random
number generator.
|
void |
setZero()
Sets the elements of this quaternion to zero.
|
int |
size()
Returns the size of this quaternion (which is always 4)
|
static void |
sphericalBezier(Quaternion qr,
Quaternion q0,
Quaternion qa,
Quaternion qb,
Quaternion q1,
double s)
Interpolates a point on a quaternion curve using cubic Bezier
interpolation.
|
static void |
sphericalBezierShoemake(Quaternion qr,
Quaternion q0,
Quaternion qa,
Quaternion qb,
Quaternion q1,
double s)
Interpolates a point on a quaternion curve using the Bezier interpolation
scheme described by Shoemake in his 1985 SIGGRAPH paper, "Animating
Rotation with Quaternion Curves".
|
static void |
sphericalHermiteGlobal(Quaternion qr,
Vector3d vr,
Quaternion q0,
Vector3d w0,
Quaternion q1,
Vector3d w1,
double s,
double h)
Interpolates a point on a quaternion curve using cubic Hermite
interpolation.
|
static void |
sphericalHermiteLocal(Quaternion qr,
Vector3d vr,
Quaternion q0,
Vector3d w0,
Quaternion q1,
Vector3d w1,
double s,
double h)
Interpolates a point on a quaternion curve using cubic Hermite
interpolation.
|
void |
sphericalInterpolate(double r,
Quaternion q1)
Computes a spherical (great circle) interpolation between this quaternion
and q1 and places the result in this quaternion.
|
void |
sphericalInterpolate(Quaternion q1,
double r,
Quaternion q2)
Computes a spherical (great circle) interpolation between quaternions q1
and q2 and places the result in this quaternion.
|
static void |
sphericalQuad(Quaternion qr,
Quaternion q0,
Quaternion qa,
Quaternion qb,
Quaternion q1,
double s)
Implements the 'squad' interpolation described by Ken Shoemake in his
1987 SIGGRAPH course notes.
|
void |
sub(Quaternion q1)
Subtracts q1 from this quaternion and places the result in this
quaternion.
|
void |
sub(Quaternion q1,
Quaternion q2)
Subtracts quaternion q1 from q2 and places the result in this quaternion.
|
void |
transform(Vector3d vr,
Vector3d v1)
Transforms a vector v1 by the rotation implied by this quaternion.
|
containsNaN, copy, copyAndAdd, copyAndNegate, copyAndScale, copyAndSub, copyAndSubLeft, dot, epsilonEquals, equals, get, getDefaultFormat, hasInf, hasNaN, isColumnVectorStringsVertical, isFixedSize, isRowVector, isWritable, maxElement, minElement, norm, normSquared, scan, scan, set, set, setColumnVectorStringsVertical, setDefaultFormat, setRowVector, setSize, toString, toString, toString, write, write, write, writeToFile
public static final Quaternion IDENTITY
public static final Quaternion ZERO
public double s
public Vector3d u
public Quaternion()
public Quaternion(Quaternion q)
q
- quaternion to be copiedpublic Quaternion(AxisAngle axisAng)
axisAng
- axis-angle used to specify the rotationpublic Quaternion(double s, double ux, double uy, double uz)
s
- scalar elementux
- first vector elementuy
- second vector elementuz
- third vector elementpublic Quaternion(double s, Vector3d u)
s
- scalar elementu
- vector componentpublic int size()
size
in interface Vector
size
in class VectorBase
public double get(int i)
get
in interface Vector
get
in class VectorBase
i
- element indexpublic void get(double[] values)
>=
4.get
in interface Vector
get
in class VectorBase
values
- array into which values are copiedpublic void set(int i, double value)
set
in interface Vector
set
in class VectorBase
i
- element indexvalue
- element valuejava.lang.ArrayIndexOutOfBoundsException
- if i is not in the range 0 to 3.public void setIdentity()
public void set(double[] values)
set
in interface Vector
set
in class VectorBase
values
- array from which values are copiedpublic int set(double[] values, int idx)
values
- array from which values are copiedidx
- starting point within values from which copying should beginpublic void set(Quaternion q1)
q1
- quaternion whose values are copiedpublic void add(Quaternion q1, Quaternion q2)
q1
- left-hand quaternionq2
- right-hand quaternionpublic void add(Quaternion q1)
q1
- right-hand quaternionpublic void sub(Quaternion q1, Quaternion q2)
q1
- left-hand quaternionq2
- right-hand quaternionpublic void sub(Quaternion q1)
q1
- right-hand quaternionpublic void negate(Quaternion q1)
q1
- quaternion to negatepublic void negate()
public void scale(double r)
r
.r
- scaling factorpublic void scale(double r, Quaternion q1)
r
and places the
results in this quaternion.r
- scaling factorq1
- quaternion to be scaledpublic void interpolate(Quaternion q1, double r, Quaternion q2)
(1-r) q1 + r q2
and places the
result in this quaternion.q1
- left-hand quaternionr
- interpolation factorq2
- right-hand quaternionpublic void interpolate(double r, Quaternion q1)
(1-r) this + r q1
and places the
result in this quaternion.r
- interpolation factorq1
- right-hand quaternionpublic void sphericalInterpolate(Quaternion q1, double r, Quaternion q2)
In the literature, this operation is sometimes known as "Slerp", a name that was coined by Ken Showmake when he described the process in SIGGRAPH 1985.
q1
- left-hand quaternionr
- interpolation factorq2
- right-hand quaternionpublic void normalizedInterpolate(Quaternion q1, double r, Quaternion q2)
This operation is sometimes known as "Nlerp", and is faster than spherical interpolation. Essentially, it involves doing a linear interpolation between q1 qnd q2 and then normalizing the result. q1 and q2 are assumed to be unit quaternions. If they are not, unit versions of them are created internally although this will slow the routine down. Also, if -q1 is closer to q2 than q1, then the interpolation is done between -q1 and q2; this ensures that the shortest rotationa; path is used.
q1
- left-hand quaternionr
- interpolation factorq2
- right-hand quaternionpublic void getAxisAngle(AxisAngle axisAng)
public void getRotationMatrix(RotationMatrix3d R)
public void setExp(double scale, Vector3d v)
public double log(Vector3d v)
public static void sphericalBezierShoemake(Quaternion qr, Quaternion q0, Quaternion qa, Quaternion qb, Quaternion q1, double s)
The inputs to the procedure consist of four orientations defining the
desired orientation at the interval end-points, along with two
intermediate control points. The desired interpolation location is
described by a parameter s
. A unit quaternion is
returned. The input quaternions are assumed to be unit quaternions.
qr
- interpolated rotation resultq0
- unit quaternion giving the rotation at the interval beginningqa
- unit quaternion giving the first control pointqb
- unit quaternion giving the second control pointq1
- unit quaternion giving the rotation at the interval ends
- interpolation location on the interval (in the range [0,1])public static void sphericalBezier(Quaternion qr, Quaternion q0, Quaternion qa, Quaternion qb, Quaternion q1, double s)
The inputs to the procedure consist of four orientations defining the
desired orientation at the interval end-points, along with two
intermediate control points. The desired interpolation location is
described by a parameter s
. A unit quaternion is
returned. The input quaternions are assumed to be unit quaternions.
qr
- interpolated rotation resultq0
- unit quaternion giving the rotation at the interval beginningqa
- unit quaternion giving the first control pointqb
- unit quaternion giving the second control pointq1
- unit quaternion giving the rotation at the interval ends
- interpolation location on the interval (in the range [0,1])public static void sphericalHermiteGlobal(Quaternion qr, Vector3d vr, Quaternion q0, Vector3d w0, Quaternion q1, Vector3d w1, double s, double h)
The inputs to the procedure consist of orientations and angular
velocities at the beginning and end-points of an interval, along with the
desired interpolation location (described by a parameter s
)
and the length of time associated with the interval (h
).
The angular velocities are supplied (and returned) in global coordinates.
If local coordinates are preferred, then the routine sphericalHermiteLocal(maspack.matrix.Quaternion, maspack.matrix.Vector3d, maspack.matrix.Quaternion, maspack.matrix.Vector3d, maspack.matrix.Quaternion, maspack.matrix.Vector3d, double, double)
should be used instead. The result quaternion is
a unit quaternion. The input quaternions are assumed to be unit
quaternions.
qr
- interpolated rotation resultvr
- interpolated angular velocity result in global coordinates (can
be set to null
if not desired).q0
- unit quaternion giving rotation at the interval beginningw0
- angular velocity (in global coordinates) at the interval beginningq1
- unit quaternion giving rotation at the interval endw1
- angular velocity (in global coordinates) at the interval ends
- interpolation location on the interval (in the range [0,1])h
- interval time durationpublic static void sphericalHermiteLocal(Quaternion qr, Vector3d vr, Quaternion q0, Vector3d w0, Quaternion q1, Vector3d w1, double s, double h)
sphericalHermiteGlobal(maspack.matrix.Quaternion, maspack.matrix.Vector3d, maspack.matrix.Quaternion, maspack.matrix.Vector3d, maspack.matrix.Quaternion, maspack.matrix.Vector3d, double, double)
except that angular velocities are input (and
returned) in local instead of global coordinates.qr
- interpolated rotation resultvr
- interpolated angular velocity result in local coordinates
(can be set to null
if not desired).q0
- unit quaternion giving rotation at the interval beginningw0
- angular velocity (in local coordinates) at the interval beginningq1
- unit quaternion giving rotation at the interval endw1
- angular velocity (in local coordinates) at the interval ends
- interpolation location on the interval (in the range [0,1])h
- interval time durationpublic static void sphericalQuad(Quaternion qr, Quaternion q0, Quaternion qa, Quaternion qb, Quaternion q1, double s)
sphericalHermiteLocal(maspack.matrix.Quaternion, maspack.matrix.Vector3d, maspack.matrix.Quaternion, maspack.matrix.Vector3d, maspack.matrix.Quaternion, maspack.matrix.Vector3d, double, double)
or sphericalHermiteGlobal(maspack.matrix.Quaternion, maspack.matrix.Vector3d, maspack.matrix.Quaternion, maspack.matrix.Vector3d, maspack.matrix.Quaternion, maspack.matrix.Vector3d, double, double)
.qr
- result quaternionq0
- initial quaternionqa
- first control point quaternionqb
- second control point quaternionq1
- final quaternions
- parametric distance along the interal (in the range [0,1]).public void sphericalInterpolate(double r, Quaternion q1)
r
- interpolation factorq1
- right-hand quaternionpublic void normalizedInterpolate(double r, Quaternion q1)
r
- interpolation factorq1
- right-hand quaternionnormalizedInterpolate(Quaternion,double,Quaternion)
public void extrapolateLocal(Quaternion q1, Vector3d w, double t)
q1
- quaternion to extrapolatew
- angular velocity used to form extrapolationt
- extrapolation timepublic void extrapolateWorld(Quaternion q1, Vector3d w, double t)
q1
- quaternion to extrapolatew
- angular velocity used to form extrapolationt
- extrapolation timepublic void scaledAdd(double r, Quaternion q1)
r q1
and add the result to this quaternion.r
- scaling factorq1
- quaternion to be scaled and addedpublic void scaledAdd(double r, Quaternion q1, Quaternion q2)
r q1 + q2
and places the result in this
quaternion.r
- scaling factorq1
- quaternion to be scaledq2
- quaternion to be addedpublic void combine(double r1, Quaternion q1, double r2, Quaternion q2)
r1 q1 + r2 q2
and places the result in this
quaternion.r1
- left-hand scaling factorq1
- left-hand quaternionr2
- right-hand scaling factorq2
- right-hand quaternionpublic double length()
public double lengthSquared()
public void conjugate(Quaternion q1)
q1
- quaternion to conjugatepublic void conjugate()
public void invert(Quaternion q1)
q1
- quaternion to invertpublic void invert()
public void mul(Quaternion q1)
q1
- right-hand quaternionpublic void mul(Quaternion q1, Quaternion q2)
q1
- left-hand quaternionq2
- right-hand quaternionpublic void mulInverse(Quaternion q1)
q1
- right-hand quaternionpublic void mulInverseRight(Quaternion q1, Quaternion q2)
q1
- left-hand quaternionq2
- right-hand quaternionpublic void mulInverseLeft(Quaternion q1, Quaternion q2)
q1
- left-hand quaternionq2
- right-hand quaternionpublic void mulInverseBoth(Quaternion q1, Quaternion q2)
q1
- left-hand quaternionq2
- right-hand quaternionpublic double distance(Quaternion q)
public double distanceSquared(Quaternion q)
public double infinityNorm()
infinityNorm
in interface Vector
infinityNorm
in class VectorBase
public double oneNorm()
oneNorm
in interface Vector
oneNorm
in class VectorBase
public double dot(Quaternion q1)
q1
- right-hand quaternionpublic double rotationAngle(Quaternion q1)
q1
- right-hand quaternionpublic void normalize()
public void normalize(Quaternion q1)
q1
- quaternion to normalizepublic boolean epsilonEquals(Quaternion q1, double eps)
q1
within a prescribed tolerance epsilon
.q1
- quaternion to compare witheps
- comparison tolerancepublic boolean equals(Quaternion q1)
q1
.q1
- quaternion to compare withpublic void setAxisAngle(AxisAngle axisAng)
axisAng
- gives the rotation axis and corresponding anglepublic void setAxisAngle(Vector3d axis, double angle)
public void set(AxisAngle axisAng)
public void set(RotationMatrix3d R)
R
- rotation specified as a matrixpublic void setZero()
public void set(double s, double ux, double uy, double uz)
s
- scalar valueux
- first vector valueuy
- second vector valueuz
- thirs vector valuepublic void set(double s, Vector3d u)
s
- scalar valueu
- vector valuepublic void setRandomUnit()
public void transform(Vector3d vr, Vector3d v1)
vr = q (0, v1) inv(q)where q is this quaternion.
vr
- result vectorv1
- vector to be transformedpublic void inverseTransform(Vector3d vr, Vector3d v1)
vr = inv(q) (0, v1) qwhere q is this quaternion.
vr
- result vectorv1
- vector to be transformedpublic void setRandomUnit(java.util.Random generator)
generator
- random number generatorpublic void setRandom()
public void setRandom(double lower, double upper)
lower
- lower random value (inclusive)upper
- upper random value (exclusive)public void setRandom(double lower, double upper, java.util.Random generator)
lower
- lower random value (inclusive)upper
- upper random value (exclusive)generator
- random number generatorpublic java.lang.String axisAngleString()
public Quaternion clone()
clone
in interface Clonable
clone
in class VectorBase