maspack.matrix
Class Quaternion

java.lang.Object
  extended by maspack.matrix.VectorBase
      extended by maspack.matrix.Quaternion
All Implemented Interfaces:
java.lang.Cloneable, Vector, Clonable

public class Quaternion
extends VectorBase

Implements a quaternion as a fixed-size 4 element vector. Element 0 is the scalar element, while elements 1-3 are the vector components.


Field Summary
static Quaternion IDENTITY
           
 double s
          Scalar element
 Vector3d u
          Vector element
static Quaternion ZERO
           
 
Constructor Summary
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.
 
Method Summary
 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 q1within 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)
           
 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.
static void normalizedHermiteLocal(Quaternion qr, Vector3d vr, Quaternion q0, Vector3d w0, Quaternion q1, Vector3d w1, double s, double h)
          Interpolates a point on a quaternion curve using direct cubic Hermite interpolation.
 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.
 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.
 
Methods inherited from class maspack.matrix.VectorBase
containsNaN, copy, copyAndAdd, copyAndNegate, copyAndScale, copyAndSub, copyAndSubLeft, dot, epsilonEquals, equals, get, getDefaultFormat, hasNaN, isColumnVectorStringsVertical, isFixedSize, isRowVector, maxElement, minElement, norm, normSquared, scan, set, set, setColumnVectorStringsVertical, setDefaultFormat, setRowVector, setSize, toString, toString, toString, write, write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

IDENTITY

public static final Quaternion IDENTITY

ZERO

public static final Quaternion ZERO

s

public double s
Scalar element


u

public Vector3d u
Vector element

Constructor Detail

Quaternion

public Quaternion()
Creates a Quaternion and initializes its elements to 0.


Quaternion

public Quaternion(Quaternion q)
Creates a Quaternion by copying an existing one.

Parameters:
q - quaternion to be copied

Quaternion

public Quaternion(AxisAngle axisAng)
Creates a Quaternion from an AxisAngle.

Parameters:
axisAng - axis-angle used to specify the rotation

Quaternion

public Quaternion(double s,
                  double ux,
                  double uy,
                  double uz)
Creates a Quaternion with the supplied element values.

Parameters:
s - scalar element
ux - first vector element
uy - second vector element
uz - third vector element

Quaternion

public Quaternion(double s,
                  Vector3d u)
Creates a Quaternion with the supplied element values.

Parameters:
s - scalar element
u - vector component
Method Detail

size

public int size()
Returns the size of this quaternion (which is always 4)

Specified by:
size in interface Vector
Specified by:
size in class VectorBase
Returns:
4

get

public double get(int i)
Gets a single element of this quaternion. Elements 0, 1, 2, and 3 correspond to s, u.x, u.y, and u.z.

Specified by:
get in interface Vector
Specified by:
get in class VectorBase
Parameters:
i - element index
Returns:
element value throws ArrayIndexOutOfBoundsException if i is not in the range 0 to 3.

get

public void get(double[] values)
Copies the elements of this quaternion into an array of doubles.

Specified by:
get in interface Vector
Overrides:
get in class VectorBase
Parameters:
values - array into which values are copied

set

public void set(int i,
                double value)
Sets a single element of this quaternion. Elements 0, 1, 2, and 3 correspond to s, u.x, u.y, and u.z.

Specified by:
set in interface Vector
Specified by:
set in class VectorBase
Parameters:
i - element index
value - element value
Throws:
java.lang.ArrayIndexOutOfBoundsException - if i is not in the range 0 to 3.

setIdentity

public void setIdentity()

set

public void set(double[] values)
Sets the elements of this quaternion from an array of doubles.

Specified by:
set in interface Vector
Overrides:
set in class VectorBase
Parameters:
values - array from which values are copied

set

public void set(Quaternion q1)
Sets the values of this quaternion to those of q1.

Parameters:
q1 - quaternion whose values are copied

add

public void add(Quaternion q1,
                Quaternion q2)
Adds q1 quaternion to q2 and places the result in this quaternion.

Parameters:
q1 - left-hand quaternion
q2 - right-hand quaternion

add

public void add(Quaternion q1)
Adds this quaternion to q1 and places the result in this quaternion.

Parameters:
q1 - right-hand quaternion

sub

public void sub(Quaternion q1,
                Quaternion q2)
Subtracts quaternion q1 from q2 and places the result in this quaternion.

Parameters:
q1 - left-hand quaternion
q2 - right-hand quaternion

sub

public void sub(Quaternion q1)
Subtracts q1 from this quaternion and places the result in this quaternion.

Parameters:
q1 - right-hand quaternion

negate

public void negate(Quaternion q1)
Sets this quaternion to the negative of q1.

Parameters:
q1 - quaternion to negate

negate

public void negate()
Negates this quaternion in place.


scale

public void scale(double r)
Scales the elements of this quaternion by r.

Parameters:
r - scaling factor

scale

public void scale(double r,
                  Quaternion q1)
Scales the elements of quaternion q1 by r and places the results in this quaternion.

Parameters:
r - scaling factor
q1 - quaternion to be scaled

interpolate

public void interpolate(Quaternion q1,
                        double r,
                        Quaternion q2)
Computes the interpolation (1-r) q1 + r q2 and places the result in this quaternion.

Parameters:
q1 - left-hand quaternion
r - interpolation factor
q2 - right-hand quaternion

interpolate

public void interpolate(double r,
                        Quaternion q1)
Computes the interpolation (1-r) this + r q1 and places the result in this quaternion.

Parameters:
r - interpolation factor
q1 - right-hand quaternion

sphericalInterpolate

public 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. The result is a unit quaternion. Non-unit quaternions can be used for input.

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.

Parameters:
q1 - left-hand quaternion
r - interpolation factor
q2 - right-hand quaternion

normalizedInterpolate

public 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. The result is a unit quaternion.

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.

Parameters:
q1 - left-hand quaternion
r - interpolation factor
q2 - right-hand quaternion

getAxisAngle

public void getAxisAngle(AxisAngle axisAng)

setExp

public void setExp(double scale,
                   Vector3d v)

log

public double log(Vector3d v)

sphericalBezierShoemake

public 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".

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.

Parameters:
qr - interpolated rotation result
q0 - unit quaternion giving the rotation at the interval beginning
qa - unit quaternion giving the first control point
qb - unit quaternion giving the second control point
q1 - unit quaternion giving the rotation at the interval end
s - interpolation location on the interval (in the range [0,1])

sphericalBezier

public 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. The method used is described ``A General Construction Scheme for Unit Quaternion Curves with Simple High Order Derivatives'', by Kim, Kim, and Shin, in SIGGRAPH '95.

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.

Parameters:
qr - interpolated rotation result
q0 - unit quaternion giving the rotation at the interval beginning
qa - unit quaternion giving the first control point
qb - unit quaternion giving the second control point
q1 - unit quaternion giving the rotation at the interval end
s - interpolation location on the interval (in the range [0,1])

sphericalHermiteGlobal

public 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. The method used is described ``A General Construction Scheme for Unit Quaternion Curves with Simple High Order Derivatives'', by Kim, Kim, and Shin, in SIGGRAPH '95. We use this method instead of the de Casteljau and 'squad' procedures described by Shoemake because it admits an easy way to interpolate the angular velocity.

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.

Parameters:
qr - interpolated rotation result
vr - interpolated angular velocity result in global coordinates (can be set to null if not desired).
q0 - unit quaternion giving rotation at the interval beginning
w0 - angular velocity (in global coordinates) at the interval beginning
q1 - unit quaternion giving rotation at the interval end
w1 - angular velocity (in global coordinates) at the interval end
s - interpolation location on the interval (in the range [0,1])
h - interval time duration

sphericalHermiteLocal

public 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. This method is identical to 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.

Parameters:
qr - interpolated rotation result
vr - interpolated angular velocity result in local coordinates (can be set to null if not desired).
q0 - unit quaternion giving rotation at the interval beginning
w0 - angular velocity (in local coordinates) at the interval beginning
q1 - unit quaternion giving rotation at the interval end
w1 - angular velocity (in local coordinates) at the interval end
s - interpolation location on the interval (in the range [0,1])
h - interval time duration

sphericalQuad

public 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. This is also a Bezier curve interpolation technique, but achieved using only three interpolation steps instead of the six required by the de Casteljau algorithm. Details of squad can be found in Quaternion Algebra and Calculus, by David Eberly. However, it should be noted that the derivative information supplied in that paper is incorrect, as mentioned in ``A Compact Differential Formula for the First Derivative of a Unit Quaternion Curve'', by Kim, Kim, and Shin (Journal of Visualization and Computer Animation. In fact, the derivative formula is rather complicated, making interpolation of angular velocity difficult. If angular velocity is also desired, one can use 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).

Parameters:
qr - result quaternion
q0 - initial quaternion
qa - first control point quaternion
qb - second control point quaternion
q1 - final quaternion
s - parametric distance along the interal (in the range [0,1]).

sphericalInterpolate

public void sphericalInterpolate(double r,
                                 Quaternion q1)
Computes a spherical (great circle) interpolation between this quaternion and q1 and places the result in this quaternion. It is assumed that both are unit quaternions; otherwise, the results are undefined.

Parameters:
r - interpolation factor
q1 - right-hand quaternion

normalizedInterpolate

public void normalizedInterpolate(double r,
                                  Quaternion q1)
Computes a normalized rotational interpolation between this quaternion and q1 and places the result in this quaternion. The result is a unit quaternion.

Parameters:
r - interpolation factor
q1 - right-hand quaternion
See Also:
normalizedInterpolate(Quaternion,double,Quaternion)

normalizedHermiteLocal

public static void normalizedHermiteLocal(Quaternion qr,
                                          Vector3d vr,
                                          Quaternion q0,
                                          Vector3d w0,
                                          Quaternion q1,
                                          Vector3d w1,
                                          double s,
                                          double h)
Interpolates a point on a quaternion curve using direct cubic Hermite interpolation. This method is identical to normalizedHermiteGlobal(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.

Parameters:
qr - interpolated rotation result
vr - interpolated angular velocity result in local coordinates (can be set to null if not desired).
q0 - unit quaternion giving rotation at the interval beginning
w0 - angular velocity (in local coordinates) at the interval beginning
q1 - unit quaternion giving rotation at the interval end
w1 - angular velocity (in local coordinates) at the interval end
s - interpolation location on the interval (in the range [0,1])
h - interval time duration

extrapolateLocal

public void extrapolateLocal(Quaternion q1,
                             Vector3d w,
                             double t)
Extrapolates a quaternion q1 by a constant angular velocity applied for time t. It is assumed that the velocity is represented in the local (rotated) coordinates associated with q1. This computation produces a unit quaternion. q1 can be a non-unit quaternion.

Parameters:
q1 - quaternion to extrapolate
w - angular velocity used to form extrapolation
t - extrapolation time

extrapolateWorld

public void extrapolateWorld(Quaternion q1,
                             Vector3d w,
                             double t)
Extrapolates a quaternion q1 by a constant angular velocity applied for time t. It is assumed that the velocity is represented in world coordinates. This computation produces a unit quaternion. q1 can be a non-unit quaternion.

Parameters:
q1 - quaternion to extrapolate
w - angular velocity used to form extrapolation
t - extrapolation time

scaledAdd

public void scaledAdd(double r,
                      Quaternion q1)
Computes r q1 and add the result to this quaternion.

Parameters:
r - scaling factor
q1 - quaternion to be scaled and added

scaledAdd

public void scaledAdd(double r,
                      Quaternion q1,
                      Quaternion q2)
Computes r q1 + q2 and places the result in this quaternion.

Parameters:
r - scaling factor
q1 - quaternion to be scaled
q2 - quaternion to be added

combine

public void combine(double r1,
                    Quaternion q1,
                    double r2,
                    Quaternion q2)
Computes r1 q1 + r2 q2 and places the result in this quaternion.

Parameters:
r1 - left-hand scaling factor
q1 - left-hand quaternion
r2 - right-hand scaling factor
q2 - right-hand quaternion

length

public double length()
Returns the 2 norm of this quaternion. This is the square root of the sum of the squares of the elements.

Returns:
quaternion 2 norm

lengthSquared

public double lengthSquared()
Returns the square of the 2 norm of this quaternion. This is the sum of the squares of the elements.

Returns:
square of the 2 norm

conjugate

public void conjugate(Quaternion q1)
Sets this quaternion to the conjugate of q1. Conjugation entails negating the values of u.

Parameters:
q1 - quaternion to conjugate

conjugate

public void conjugate()
Conjugates this quaternion in place. Conjugation entails negating the values of u.


invert

public void invert(Quaternion q1)
Sets this quaternion to the inverse of q1.

Parameters:
q1 - quaternion to invert

invert

public void invert()
Inverts this quaternion in place.


mul

public void mul(Quaternion q1)
Multiplies this quaternion by quaternion q1 and places the result in this quaternion.

Parameters:
q1 - right-hand quaternion

mul

public void mul(Quaternion q1,
                Quaternion q2)
Multiplies quaternion q1 by quaternion q2 and places the result in this quaternion.

Parameters:
q1 - left-hand quaternion
q2 - right-hand quaternion

mulInverse

public void mulInverse(Quaternion q1)
Post-multiplies this quaternion by the inverse of quaternion q1 and places the result in this quaternion.

Parameters:
q1 - right-hand quaternion

mulInverseRight

public void mulInverseRight(Quaternion q1,
                            Quaternion q2)
Multiplies quaternion q1 by the inverse of quaternion q2 and places the result in this quaternion.

Parameters:
q1 - left-hand quaternion
q2 - right-hand quaternion

mulInverseLeft

public void mulInverseLeft(Quaternion q1,
                           Quaternion q2)
Multiplies the inverse of quaternion q1 by quaternion q2 and places the result in this quaternion.

Parameters:
q1 - left-hand quaternion
q2 - right-hand quaternion

mulInverseBoth

public 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.

Parameters:
q1 - left-hand quaternion
q2 - right-hand quaternion

distance

public double distance(Quaternion q)
Returns the Euclidean distance between this quaternion and quaternion q.

Returns:
distance between this quaternion and q

distanceSquared

public double distanceSquared(Quaternion q)
Returns the squared of the Euclidean distance between this quaternion and quaternion q.

Returns:
squared distance between this quaternion and q

infinityNorm

public double infinityNorm()
Returns the infinity norm of this quaternion. This is the maximum absolute value over all elements, treating it as a 4-vector.

Specified by:
infinityNorm in interface Vector
Overrides:
infinityNorm in class VectorBase
Returns:
quaternion infinity norm

oneNorm

public double oneNorm()
Returns the 1 norm of this quaternion. This is the sum of the absolute values of the elements, treating it as a 4-vector.

Specified by:
oneNorm in interface Vector
Overrides:
oneNorm in class VectorBase
Returns:
quaternion 1 norm

dot

public double dot(Quaternion q1)
Returns the dot product of this quaternion and q1.

Parameters:
q1 - right-hand quaternion
Returns:
dot product

rotationAngle

public double rotationAngle(Quaternion q1)
Returns the angular distance between the rotations represented by this quaternion and q1. The returned value is in the range 0 to Math.PI.

Parameters:
q1 - right-hand quaternion
Returns:
angular rotational distance, in radians

normalize

public void normalize()
Normalizes this quaternion in place.


normalize

public void normalize(Quaternion q1)
Computes a unit quaternion in the direction of q1 and places the result in this quaternion.

Parameters:
q1 - quaternion to normalize

epsilonEquals

public boolean epsilonEquals(Quaternion q1,
                             double eps)
Returns true if the elements of this quaternion equal those of quaternion q1within a prescribed tolerance epsilon.

Parameters:
q1 - quaternion to compare with
eps - comparison tolerance
Returns:
false if the vectors are not equal within the specified tolerance

equals

public boolean equals(Quaternion q1)
Returns true if the elements of this quaternion exactly equal those of quaternion q1.

Parameters:
q1 - quaternion to compare with
Returns:
false if the vectors are not equal

setAxisAngle

public void setAxisAngle(AxisAngle axisAng)
Sets this quaternion to a unit quaternion corresponding to a specified rotation.

Parameters:
axisAng - gives the rotation axis and corresponding angle

setAxisAngle

public void setAxisAngle(Vector3d axis,
                         double angle)

set

public void set(AxisAngle axisAng)

set

public void set(RotationMatrix3d R)
Sets this quaternion to a unit quaternion corresponding to a specified rotation.

Parameters:
R - rotation specified as a matrix

setZero

public void setZero()
Sets the elements of this quaternion to zero.


set

public void set(double s,
                double ux,
                double uy,
                double uz)
Sets the elements of this quaternion to the prescribed values.

Parameters:
s - scalar value
ux - first vector value
uy - second vector value
uz - thirs vector value

set

public void set(double s,
                Vector3d u)
Sets the elements of this quaternion to the prescribed values.

Parameters:
s - scalar value
u - vector value

setRandomUnit

public void setRandomUnit()
Sets this quaternion to a random unit value.


transform

public void transform(Vector3d vr,
                      Vector3d v1)
Transforms a vector v1 by the rotation implied by this quaternion. More specifically, this method converts v1 from rotated coordinates to base coordinates, by forming the product
 vr = q (0, v1) inv(q)
 
where q is this quaternion.

Parameters:
vr - result vector
v1 - vector to be transformed

inverseTransform

public void inverseTransform(Vector3d vr,
                             Vector3d v1)
Transforms a vector v1 by the inverse rotation implied by this quaternion. More specifically, this method converts v1 from world coordinates to rotated coordinates, by forming the product
 vr = inv(q) (0, v1) q
 
where q is this quaternion.

Parameters:
vr - result vector
v1 - vector to be transformed

setRandomUnit

public void setRandomUnit(java.util.Random generator)
Sets this quaternion to a random unit value, using a supplied random number generator.

Parameters:
generator - random number generator

setRandom

public void setRandom()
Sets the elements of this quaternion to uniformly distributed random values in the range -0.5 (inclusive) to 0.5 (exclusive).


setRandom

public void setRandom(double lower,
                      double upper)
Sets the elements of this quaternion to uniformly distributed random values in a specified range.

Parameters:
lower - lower random value (inclusive)
upper - upper random value (exclusive)

setRandom

public 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.

Parameters:
lower - lower random value (inclusive)
upper - upper random value (exclusive)
generator - random number generator

axisAngleString

public java.lang.String axisAngleString()

clone

public Quaternion clone()
Specified by:
clone in interface Clonable
Overrides:
clone in class VectorBase