/QuatDualQuat

Quick and Dirty Mathematica package for Quaternions and Dual Quaternions prompted mostly by not being able to easily use symbolics in the official Quaternion package.

Primary LanguageMathematicaMIT LicenseMIT

QuatDualQuat Mathematica Package for Quaternions and Dual Quaternions

Description

Q&D (Quick and Dirty) Mathematica package for Quaternions and Dual Quaternions prompted mostly by not being able to easily use symbolics in the official Quaternion package. This package is simpler and does not attempt to provide a Quaternion object, instead it just uses plain lists to represent quaternions and nested list of lists for dual quaternions in pretty much the same way you would implement a C library ie passing in parameters and returning quaternions/dual quaternions etc. It does however work with symbolics and the use of plain lists means things like scalar multiplication and norms can be provided by normal Mathematica operations.

Disclaimer I haven't done much (any) Mathematica programming so the code could probably be improved upon

Functions

Quaternions

QCreate[w, x, y, z], QCreate[vec4], QCreate[scalar, vec3] creates a quaternion as a 4-list.

QW[Q] returns the non-imaginary (w) part of Q.

QV[Q] returns the imaginary ({x, y, z}) part of Q as a 3-list.

QAdd[Q1, Q2] returns the quaternion as a 4-list representing the addition of Q1 and Q2.

QTimes[Q1, Q2] returns the quaternion as a 4-list representing the (non-commutative) multiplication of Q1 and Q2.

QSandwich[Q, P] returns the quaternion as a 4-list representing the multiplication of quaternion Q, the 3-list P and the conjugate of Q.

QRotate[[p, axis, angle] returns the quaternion as a 4-list representing the rotation angle around axis (3-list) of a point p (3-list).

QRotateBetween[v1, v2, simplify:True] returns the quaternion as a 4-list representing the shortest arc rotation between two vectors v1 (3-list) and v2 (3-list). simplify specifies whether to run FullSimplify on the quaternion components.

QRotationMatrix[Q] returns the 3x3 matrix representing the rotation specified by quaternion Q (4-list).

QConjugate[Q] returns the quaternion as a 4-list representing the conjugate of Q.

QInverse[Q] returns the quaternion as a 4-list representing the inverse of Q.

QCollect[Q, var] returns a list comprising a scalar/variable and a 4-list representing a quaternion. The return values are the result of calling Collect[Q, var] on the quaternion components. If Collect cannot separate var from all the expressions in Q then 1 is returned as the first element of the return list]. Note This could possibly be implemented more cleanly by returning var * Q, however Mathematica evaluates the return and distributes var again. http://community.wolfram.com/groups/-/m/t/858630 provides some sort of work around (for Mathematica 10 and up) but it doesn't seem to work for function returns.

QString[Q, format] returns a formatted string representation of the quaternion Q using format (defaults to TraditionalForm).

QStringCollect[Q, var, format] returns a formatted string representation of the quaternion Q using format (defaults to TraditionalForm) after applying Collect(Q. var).

Dual Quaternions

DQCreate[w1, x1, y1, z1, w2, x2, y2, z2], DQCreate[Q1, Q2] creates a Dual Quaternion as a nested list of two quaternions with the 2nd quaternion representing the dual number quaternion.

DQReal[DQ] returns a 4-list representing a quaternion which is the real part of the dual quaternion DQ.

DQRealScalar[DQ] returns the real part of the quaternion which is the real part of the dual quaternion DQ.

DQRealVector[DQ] returns the imaginary part of the quaternion which is the real part of the dual quaternion DQ.

DQDual[DQ] returns a 4-list representing a quaternion which is the dual part of the dual quaternion DQ.

DQDualScalar[DQ] returns the real part of the quaternion which is the dual part of the dual quaternion DQ.

DQDualVector[DQ] returns the imaginary part of the quaternion which is the dual part of the dual quaternion DQ.

DQAdd[DQ1, DQ2] returns a nested list of two quaternions representing the dual quaternion resulting from adding DQ1 and DQ2.

DQTimes[DQ1, DQ2] returns the dual quaternion as a nested list of two quaternions representing the (non-commutative) multiplication of DQ1 and DQ2.

DQSandwich[DQ, P] returns the dual quaternion as a nested list of two quaternions representing the multiplication of DQ, the 3-list P and the conjugate of DQ.

DQRigidTransform[p, raxis_, theta_, t_]_ returns the dual quaternion as a nested list of two quaternions representing the rotation of point p (3-list) of angle theta around axis (3-list) followed by translation t (3-list).

DQConjugate[DQ] returns the dual quaternion as a nested list of two quaternions representing the first conjugate of DQ (p* + eq*).

DQConjugate2[DQ] returns the dual quaternion as a nested list of two quaternions representing the second conjugate of DQ (p* - eq*).

DQNorm[DQ] returns the norm of DQ.

DQString[DQ, format] returns a formatted string representation of the dual quaternion DQ using format (defaults to TraditionalForm).

DQStringCollect[Q, var, format] returns a formatted string representation of the dual quaternion DQ using format (defaults to TraditionalForm) after applying Collect(Q. var) to both components of DQ.