maspack.matrix
Class DualQuaternion

java.lang.Object
  extended by maspack.matrix.DualQuaternion

public class DualQuaternion
extends java.lang.Object

Dual Quaternions a + A + e*(b + B), where 'e' is the dual parameter Useful for representing rigid transformations and blending see: Dual Quaternions for Rigid Transformation Blending (Kavan, 2006)

Author:
antonio

Field Summary
static int DEFAULT_DIB_MAX_ITERS
           
static double DEFAULT_DIB_TOLERANCE
           
 
Constructor Summary
DualQuaternion()
          Constructs the identity Dual Quaternion
DualQuaternion(double a, Vector3d A, double b, Vector3d B)
          Creates a dual quaternion with the supplied values
DualQuaternion(DualQuaternion d)
          Creates a dual quaternion by copying an existing one
DualQuaternion(Quaternion qReal, Quaternion qDual)
          Creates a dual quaternion from two regular quaternions
DualQuaternion(RigidTransform3d A)
          Creates a dual quaternion from a rigid transformation
 
Method Summary
 void add(DualQuaternion q)
          Adds the supplied dual quaternion to this
 void add(DualQuaternion q1, DualQuaternion q2)
          Adds two dual quaternions and places the result in this
 DualQuaternion clone()
          Returns a copy of this dual quaternion
 void conjugate()
          Conjugates this
 void conjugate(DualQuaternion q)
          Conjugates q and places the result in this (a+A + e*(b+B))^* = a-A + e*(b-B)
 double dot(DualQuaternion q)
          Dot product of this and supplied dual quaternion
static double dot(DualQuaternion q1, DualQuaternion q2)
          Dot product of the two supplied dual quaternions q1.a*q2.a + q1.A .
 void dualQuaternionIterativeBlending(double[] w, DualQuaternion[] q, int numq)
          Dual Quaternion Iterative Blending (DIB), which approximates ScLeRP and applies to multiple inputs.
 void dualQuaternionIterativeBlending(double[] w, DualQuaternion[] q, int numq, double tol, int maxIters)
           
 void dualQuaternionLinearBlending(double[] w, DualQuaternion[] q, int numq)
          Dual Quaternion Linear Blending (DLB) of many dual quaternions.
 void dualQuaternionLinearBlending(DualQuaternion q1, double t, DualQuaternion q2)
          Dual Quaternion Linear Blending (DLB) of two dual quaternions q = (1-t)*q1 + t*q2, with ||q|| = 1.
 void exp(DualQuaternion q)
          Performs the exponentiation to dual quaternion q, which must have a zero scalar part.
 void get(double[] vals)
          Fills the 8-element vector of values
 void get(DualQuaternion d)
          Copies this dual quaternion to supplied d
 double get(int idx)
          Gets the value at the supplied index, 1-4 are real parameters, 5-7 are dual.
 Quaternion getDual()
          Gets the dual (translation) quaternion associated with this
 void getDual(Quaternion q)
          Gets the dual (translation) quaternion associated with this
 Quaternion getReal()
          Gets the real (rotation) quaternion associated with this
 void getReal(Quaternion q)
          Gets the real (rotation) quaternion associated with this
 void getRigidTransform3d(RigidTransform3d trans)
          Fills trans with the rigid transformation implied by this dual quaternion
 double getScrewParameters(Vector3d l, Vector3d m, double[] angles)
          Extracts screw parameters from this dual quaternion
static double getScrewParameters(Vector3d l, Vector3d m, double[] angles, DualQuaternion q)
          Extracts screw parameters from the dual quaternion q
 void inverseTransform(Point3d p)
          Performs the inverse of the rigid transformation implied by this dual quaternion to point p
static void inverseTransform(Point3d pr, DualQuaternion q, Point3d p)
          Performs the inverse of the rigid transformation implied by the dual quaternion q to point p and places the result in pr.
 void inverseTransform(Point3d pr, Point3d p)
          Performs the inverse of the rigid transformation implied by this dual quaternion to point p and places the result in pr.
 void inverseTransform(Vector3d v)
          Performs the inverse of the rotation implied by this dual quaternion to vector v and places the result in vr.
static void inverseTransform(Vector3d vr, DualQuaternion q, Vector3d v)
          Performs the inverse of the rotation implied by the dual quaternion q to vector v and places the result in vr.
 void inverseTransform(Vector3d vr, Vector3d v)
          Performs the inverse of the rotation implied by this dual quaternion to vector v and places the result in vr.
 void invert()
          Inverts this dual quaternion s.t.
 void invert(DualQuaternion q)
          Computes the inverse qinv = q^(-1) s.t.
 void log()
          Performs the logarithm of this, which results in a zero scalar part.
 void log(DualQuaternion q)
          Performs the logarithm of q, which results in a zero scalar part, and places the answer in this.
 void mul(DualQuaternion q1, DualQuaternion q2)
          Multiplies two dual quaternions and places the result in this.
 void mulLeft(DualQuaternion q)
          Multiplies this on the left by the dual quaternion q
 void mulRight(DualQuaternion q)
          Multiplies this on the right by the dual quaternion q
 DualScalar norm()
          Computes the norm, which is a dual scalar
static DualScalar norm(DualQuaternion q)
          Computes the norm of the supplied dual quaternion.
 void normalize()
          Normalizes this dual quaternion
 void normalize(DualQuaternion q)
          Normalizes the supplied dual quaternion and places the result in this ||result|| = 1 + e*0
 DualScalar normSquared()
          Computes the squared norm, which is a dual scalar
static DualScalar normSquared(DualQuaternion q)
          Computes the squared norm of the supplied dual quaternion.
 void pow(DualQuaternion q, double e)
          Raises the supplied quaternion to the power e according to euler's formula and places the result in this.
 void pow(DualQuaternion q, DualScalar e)
          Raises the supplied quaternion to the dual power e according to euler's formula and places the result in this.
 void scale(double s)
          Scales this by the supplied value
 void scale(double s, DualQuaternion q)
          Scales the dual quaternion q by s and places the result in this
 void scale(DualScalar s)
          Scales this by the supplied dual scalar
 void scale(DualScalar s, DualQuaternion q)
          Scales q by the dual scalar s and places the result in this
 void scaledAdd(double s, DualQuaternion q)
          Adds s*q1 to this
 void scaledAdd(double s, DualQuaternion q1, DualQuaternion q2)
          Computes the scaled addition s*q1+q2 and places the result in this
 void scaledAdd(DualScalar s, DualQuaternion q)
          Adds s*q to this
 void scaledAdd(DualScalar s, DualQuaternion q1, DualQuaternion q2)
          Computes the scaled addition s*q1+q2 and places the result in this
 void screwLinearInterpolate(DualQuaternion q1, double t, DualQuaternion q2)
          Screw Linear Interpolation ScLERP between two dual quaternions t represent the normalized distance between the two (t=0.5 is half-way), q = q1*(q1^-1q2)^t.
 void set(double[] vals)
          Sets parameters based on the 8-element array of vals:
 void set(double a, Vector3d A, double b, Vector3d B)
          Sets parameters according to supplied values
 void set(DualQuaternion d)
          Copies an existing dual quaternion
 void set(int idx, double val)
          Sets the value at the supplied index, 1-4 are real parameters, 5-7 are dual.
 void set(Quaternion qReal, Quaternion qDual)
          Sets values based on real and dual quaternions
 void set(RigidTransform3d trans)
          Sets the values of this dual quaternion to represent the supplied rigid transformation
 void setDual(Quaternion q)
          Gets the dual (translational) quaternion associated with this
 void setIdentity()
          Sets to the identity dual quaternion 1 + 0e
 void setReal(Quaternion q)
          Sets the real (rotation) quaternion associated with this
 void setScrewParameters(Vector3d l, Vector3d m, double theta, double alpha)
          Sets this quaternion based on screw parameters
 void setZero()
          Sets to the zero quaternion 0 + 0e
 int size()
          Number of entries = 8
 void sub(DualQuaternion q)
          Subtracts q from this
 void sub(DualQuaternion q1, DualQuaternion q2)
          Computes q1-q2 and places the result in this
 java.lang.String toString()
          Converts to a string
 java.lang.String toString(NumberFormat fmt)
           
 java.lang.String toString(java.lang.String fmtStr)
           
 void transform(Point3d p)
          Performs the rigid transformation implied by this dual quaternion
static void transform(Point3d pr, DualQuaternion q, Point3d p)
          Performs the rigid transformation implied by the dual quaternion q to point p and places the result in pr.
 void transform(Point3d pr, Point3d p)
          Performs the rigid transformation implied by this dual quaternion to point p and places the result in pr.
 void transform(Vector3d v)
          Performs the rigid transformation implied by this dual quaternion
static void transform(Vector3d vr, DualQuaternion q, Vector3d v)
          Performs the rigid transformation implied by q to vector v and places the result in vr.
 void transform(Vector3d vr, Vector3d v)
          Performs the rigid transformation implied by this dual quaternion to vector v and places the result in vr.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_DIB_TOLERANCE

public static double DEFAULT_DIB_TOLERANCE

DEFAULT_DIB_MAX_ITERS

public static int DEFAULT_DIB_MAX_ITERS
Constructor Detail

DualQuaternion

public DualQuaternion()
Constructs the identity Dual Quaternion


DualQuaternion

public DualQuaternion(double a,
                      Vector3d A,
                      double b,
                      Vector3d B)
Creates a dual quaternion with the supplied values

Parameters:
a - scalar part of the real portion
A - vector part of the real portion
b - scalar part of the dual portion
B - vector part of the dual portion

DualQuaternion

public DualQuaternion(DualQuaternion d)
Creates a dual quaternion by copying an existing one


DualQuaternion

public DualQuaternion(RigidTransform3d A)
Creates a dual quaternion from a rigid transformation


DualQuaternion

public DualQuaternion(Quaternion qReal,
                      Quaternion qDual)
Creates a dual quaternion from two regular quaternions

Parameters:
qReal - the "real" part, corresponding to the rotation
qDual - the "dual" part, corresponding to translation
Method Detail

setIdentity

public void setIdentity()
Sets to the identity dual quaternion 1 + 0e


setZero

public void setZero()
Sets to the zero quaternion 0 + 0e


set

public void set(double a,
                Vector3d A,
                double b,
                Vector3d B)
Sets parameters according to supplied values

Parameters:
a - real scalar
A - real vector
b - dual scalar
B - dual vector

set

public void set(double[] vals)
Sets parameters based on the 8-element array of vals:

Parameters:
vals - 0: real scalar 1-3: real vector 4: dual scalar 5-7: dual vector

get

public void get(double[] vals)
Fills the 8-element vector of values

Parameters:
vals - 0: real scalar 1-3: real vector 4: dual scalar 5-7: dual vector

set

public void set(DualQuaternion d)
Copies an existing dual quaternion


get

public void get(DualQuaternion d)
Copies this dual quaternion to supplied d


set

public void set(RigidTransform3d trans)
Sets the values of this dual quaternion to represent the supplied rigid transformation


set

public void set(Quaternion qReal,
                Quaternion qDual)
Sets values based on real and dual quaternions

Parameters:
qReal - the rotation part
qDual - the dual translation part

getReal

public Quaternion getReal()
Gets the real (rotation) quaternion associated with this


getDual

public Quaternion getDual()
Gets the dual (translation) quaternion associated with this


getReal

public void getReal(Quaternion q)
Gets the real (rotation) quaternion associated with this


getDual

public void getDual(Quaternion q)
Gets the dual (translation) quaternion associated with this


setReal

public void setReal(Quaternion q)
Sets the real (rotation) quaternion associated with this


setDual

public void setDual(Quaternion q)
Gets the dual (translational) quaternion associated with this


getRigidTransform3d

public void getRigidTransform3d(RigidTransform3d trans)
Fills trans with the rigid transformation implied by this dual quaternion


get

public double get(int idx)
Gets the value at the supplied index, 1-4 are real parameters, 5-7 are dual.


set

public void set(int idx,
                double val)
Sets the value at the supplied index, 1-4 are real parameters, 5-7 are dual.


add

public void add(DualQuaternion q1,
                DualQuaternion q2)
Adds two dual quaternions and places the result in this


add

public void add(DualQuaternion q)
Adds the supplied dual quaternion to this


scaledAdd

public void scaledAdd(double s,
                      DualQuaternion q1,
                      DualQuaternion q2)
Computes the scaled addition s*q1+q2 and places the result in this


scaledAdd

public void scaledAdd(double s,
                      DualQuaternion q)
Adds s*q1 to this


scaledAdd

public void scaledAdd(DualScalar s,
                      DualQuaternion q1,
                      DualQuaternion q2)
Computes the scaled addition s*q1+q2 and places the result in this


scaledAdd

public void scaledAdd(DualScalar s,
                      DualQuaternion q)
Adds s*q to this


sub

public void sub(DualQuaternion q1,
                DualQuaternion q2)
Computes q1-q2 and places the result in this


sub

public void sub(DualQuaternion q)
Subtracts q from this


mul

public void mul(DualQuaternion q1,
                DualQuaternion q2)
Multiplies two dual quaternions and places the result in this. Note: multiplication is not transitive

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

mulRight

public void mulRight(DualQuaternion q)
Multiplies this on the right by the dual quaternion q


mulLeft

public void mulLeft(DualQuaternion q)
Multiplies this on the left by the dual quaternion q


conjugate

public void conjugate(DualQuaternion q)
Conjugates q and places the result in this (a+A + e*(b+B))^* = a-A + e*(b-B)


conjugate

public void conjugate()
Conjugates this


normSquared

public static DualScalar normSquared(DualQuaternion q)
Computes the squared norm of the supplied dual quaternion. Note the result is a dual scalar.


norm

public static DualScalar norm(DualQuaternion q)
Computes the norm of the supplied dual quaternion. Note the result is a dual scalar


norm

public DualScalar norm()
Computes the norm, which is a dual scalar


normSquared

public DualScalar normSquared()
Computes the squared norm, which is a dual scalar


scale

public void scale(DualScalar s,
                  DualQuaternion q)
Scales q by the dual scalar s and places the result in this


scale

public void scale(double s,
                  DualQuaternion q)
Scales the dual quaternion q by s and places the result in this


scale

public void scale(DualScalar s)
Scales this by the supplied dual scalar


scale

public void scale(double s)
Scales this by the supplied value


normalize

public void normalize(DualQuaternion q)
Normalizes the supplied dual quaternion and places the result in this ||result|| = 1 + e*0


normalize

public void normalize()
Normalizes this dual quaternion


invert

public void invert(DualQuaternion q)
Computes the inverse qinv = q^(-1) s.t. qinv*q = q*qinv = 1+0e and places the result in this.


invert

public void invert()
Inverts this dual quaternion s.t. qinv*q = q*qinv = 1+0e


transform

public static void transform(Vector3d vr,
                             DualQuaternion q,
                             Vector3d v)
Performs the rigid transformation implied by q to vector v and places the result in vr. Note that this only applies the rotational component on a vector.

Parameters:
vr - result
q - transform
v - input

transform

public void transform(Vector3d vr,
                      Vector3d v)
Performs the rigid transformation implied by this dual quaternion to vector v and places the result in vr. Note that this only applies the rotational component on a vector.

Parameters:
vr - result
v - input

transform

public void transform(Vector3d v)
Performs the rigid transformation implied by this dual quaternion

Parameters:
v - vector to transform

transform

public static void transform(Point3d pr,
                             DualQuaternion q,
                             Point3d p)
Performs the rigid transformation implied by the dual quaternion q to point p and places the result in pr.

Parameters:
pr - result
q - transform
p - input

transform

public void transform(Point3d pr,
                      Point3d p)
Performs the rigid transformation implied by this dual quaternion to point p and places the result in pr.

Parameters:
pr - result
p - input

transform

public void transform(Point3d p)
Performs the rigid transformation implied by this dual quaternion

Parameters:
p - transformed vector

inverseTransform

public static void inverseTransform(Point3d pr,
                                    DualQuaternion q,
                                    Point3d p)
Performs the inverse of the rigid transformation implied by the dual quaternion q to point p and places the result in pr.

Parameters:
pr - result
q - transform to invert
p - input

inverseTransform

public void inverseTransform(Point3d pr,
                             Point3d p)
Performs the inverse of the rigid transformation implied by this dual quaternion to point p and places the result in pr.

Parameters:
pr - result
p - input

inverseTransform

public void inverseTransform(Point3d p)
Performs the inverse of the rigid transformation implied by this dual quaternion to point p

Parameters:
p - input

inverseTransform

public static void inverseTransform(Vector3d vr,
                                    DualQuaternion q,
                                    Vector3d v)
Performs the inverse of the rotation implied by the dual quaternion q to vector v and places the result in vr.

Parameters:
vr - result
q - transform to invert
v - input

inverseTransform

public void inverseTransform(Vector3d vr,
                             Vector3d v)
Performs the inverse of the rotation implied by this dual quaternion to vector v and places the result in vr.

Parameters:
vr - result
v - input

inverseTransform

public void inverseTransform(Vector3d v)
Performs the inverse of the rotation implied by this dual quaternion to vector v and places the result in vr.

Parameters:
v - input and result

pow

public void pow(DualQuaternion q,
                double e)
Raises the supplied quaternion to the power e according to euler's formula and places the result in this. Note: only applies to unit quaternions


pow

public void pow(DualQuaternion q,
                DualScalar e)
Raises the supplied quaternion to the dual power e according to euler's formula and places the result in this. Note: only applies to unit quaternions


getScrewParameters

public static double getScrewParameters(Vector3d l,
                                        Vector3d m,
                                        double[] angles,
                                        DualQuaternion q)
Extracts screw parameters from the dual quaternion q

Parameters:
l - the screw axis
m - the moment vector
angles - the dual angle angles[0] + e*angles[1]
q - input
Returns:
the norm of the real vector component of q, which must be > 0 for screw parameters to be reliable

getScrewParameters

public double getScrewParameters(Vector3d l,
                                 Vector3d m,
                                 double[] angles)
Extracts screw parameters from this dual quaternion

Parameters:
l - the screw axis
m - the moment vector
angles - the dual angle angles[0] + e*angles[1]
Returns:
the norm of the real vector component, which must be > 0 for screw parameters to be reliable

setScrewParameters

public void setScrewParameters(Vector3d l,
                               Vector3d m,
                               double theta,
                               double alpha)
Sets this quaternion based on screw parameters

Parameters:
l - the screw axis
m - the moment vector
theta - the real part of the screw angle
alpha - the dual part of the screw angle (pitch)

dualQuaternionLinearBlending

public void dualQuaternionLinearBlending(DualQuaternion q1,
                                         double t,
                                         DualQuaternion q2)
Dual Quaternion Linear Blending (DLB) of two dual quaternions q = (1-t)*q1 + t*q2, with ||q|| = 1. Note that to ensure shortest path, q1 and q2 should be in the same direction (q1.q2 > 0)


dualQuaternionLinearBlending

public void dualQuaternionLinearBlending(double[] w,
                                         DualQuaternion[] q,
                                         int numq)
Dual Quaternion Linear Blending (DLB) of many dual quaternions. out = sum(w[i]*q[i], i=1..n), with ||out|| = 1. Signs on the dual quaternions should remain consistent.

Parameters:
w - vector of weights
q - vector of dual quaternions
numq - number of dual quaternions

log

public void log(DualQuaternion q)
Performs the logarithm of q, which results in a zero scalar part, and places the answer in this. This only applies to unit dual quaternions


log

public void log()
Performs the logarithm of this, which results in a zero scalar part. This only applies to unit dual quaternions


exp

public void exp(DualQuaternion q)
Performs the exponentiation to dual quaternion q, which must have a zero scalar part. The result is placed in this.


dualQuaternionIterativeBlending

public void dualQuaternionIterativeBlending(double[] w,
                                            DualQuaternion[] q,
                                            int numq,
                                            double tol,
                                            int maxIters)

dualQuaternionIterativeBlending

public void dualQuaternionIterativeBlending(double[] w,
                                            DualQuaternion[] q,
                                            int numq)
Dual Quaternion Iterative Blending (DIB), which approximates ScLeRP and applies to multiple inputs. Uses default tolerance and maximum iterations

Parameters:
w - array of weights
q - quaternions
numq - number of quaternions

dot

public double dot(DualQuaternion q)
Dot product of this and supplied dual quaternion


dot

public static double dot(DualQuaternion q1,
                         DualQuaternion q2)
Dot product of the two supplied dual quaternions q1.a*q2.a + q1.A . q2.A


screwLinearInterpolate

public void screwLinearInterpolate(DualQuaternion q1,
                                   double t,
                                   DualQuaternion q2)
Screw Linear Interpolation ScLERP between two dual quaternions t represent the normalized distance between the two (t=0.5 is half-way), q = q1*(q1^-1q2)^t. For the shortest distance, q1 and q2 should have the same orientation.


toString

public java.lang.String toString()
Converts to a string

Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(NumberFormat fmt)

toString

public java.lang.String toString(java.lang.String fmtStr)

size

public int size()
Number of entries = 8


clone

public DualQuaternion clone()
Returns a copy of this dual quaternion

Overrides:
clone in class java.lang.Object