Table of contents
CSPICE_QDQ2AV derives angular velocity from a unit quaternion and
its derivative with respect to time.
Given:
q a unit length double precision 4-vector representing a
SPICE-style quaternion.
help, q
DOUBLE = Array[4]
Note that multiple styles of quaternions are in use.
This routine will not work properly if the input
quaternions do not conform to the SPICE convention.
See the -Particulars section for details.
dq a double precision 4-vector representing the derivative of `q'
with respect to time.
help, dq
DOUBLE = Array[4]
the call:
cspice_qdq2av, q, dq, av
returns:
av a double precision 3-vector representing the angular velocity
defined by `q' and `dq', that is, the angular velocity of the
frame defined by the rotation matrix associated with `q'.
help, av
DOUBLE = Array[3]
None.
Any numerical results shown for this example may differ between
platforms as the results depend on the SPICE kernels used as input
and the machine specific arithmetic implementation.
1) The following test program creates a quaternion and quaternion
derivative from a known rotation matrix and angular velocity
vector. The angular velocity is recovered from the quaternion
and quaternion derivative by calling cspice_qdq2av and by an
alternate method; the results are displayed for comparison.
Example code begins here.
PRO qdq2av_ex1
;;
;; Pick some Euler angles and form a rotation matrix.
;;
angle = [ -20.d, 50.d, -60.d ] * cspice_rpd()
cspice_eul2m, angle[2], angle[1], angle[0], 3, 1, 3, m
cspice_m2q, m, q
;;
;; Choose an angular velocity vector.
;;
expav = [ 1.d, 2., 3. ]
;;
;; Form the quaternion derivative.
;;
qav = [ 0.0, expav ]
cspice_qxq, q, qav, dq
dq = -0.5d * dq
;;
;; Recover angular velocity from `q' and `dq' using cspice_qdq2av.
;;
cspice_qdq2av, q, dq, av
;;
;; Now we'll obtain the angular velocity from `q' and
;; `dq' by an alternate method.
;;
;; Convert `q' back to a rotation matrix.
;;
cspice_q2m, q, m
;;
;; Convert `q' and `dq' to a rotation derivative matrix. This
;; somewhat messy procedure is based on differentiating the
;; formula for deriving a rotation from a quaternion, then
;; substituting components of `q' and `dq' into the derivative
;; formula.
;;
dm = dblarr(3,3)
dm[0,0] = -4.d0 * ( q[2]*dq[2] + q[3]*dq[3] )
dm[1,0] = 2.d0 * ( q[1]*dq[2] + q[2]*dq[1] $
- q[0]*dq[3] - q[3]*dq[0] )
dm[2,0] = 2.d0 * ( q[1]*dq[3] + q[3]*dq[1] $
+ q[0]*dq[2] + q[2]*dq[0] )
dm[0,1] = 2.d0 * ( q[1]*dq[2] + q[2]*dq[1] $
+ q[0]*dq[3] + q[3]*dq[0] )
dm[1,1] = -4.d0 * ( q[1]*dq[1] + q[3]*dq[3] )
dm[2,1] = 2.d0 * ( q[2]*dq[3] + q[3]*dq[2] $
- q[0]*dq[1] - q[1]*dq[0] )
dm[0,2] = 2.d0 * ( q[3]*dq[1] + q[1]*dq[3] $
- q[0]*dq[2] - q[2]*dq[0] )
dm[1,2] = 2.d0 * ( q[2]*dq[3] + q[3]*dq[2] $
+ q[0]*dq[1] + q[1]*dq[0] )
dm[2,2] = -4.d0 * ( q[1]*dq[1] + q[2]*dq[2] )
xtrans = dblarr(6,6)
;;
;; Upper left block:
;;
xtrans[0,0] = m[*,0]
xtrans[0,1] = m[*,1]
xtrans[0,2] = m[*,2]
;;
;; Lower left block:
;;
xtrans[0,3] = dm[*,0]
xtrans[0,4] = dm[*,1]
xtrans[0,5] = dm[*,2]
;;
;; Lower right block:
;;
xtrans[3,3] = m[*,0]
xtrans[3,4] = m[*,1]
xtrans[3,5] = m[*,2]
;;
;; Now use cspice_xf2rav to produce the expected angular velocity.
;;
cspice_xf2rav, xtrans, mout, avx
;;
;; The results should match to nearly full double precision.
;;
print, "Original angular velocity : ", expav
print, "cspice_qdq2av angular velocity: ", av
print, "cspice_xf2rav angular velocity: ", avx
END
When this program was executed on a Mac/Intel/IDL8.x/64-bit
platform, the output was:
Original angular velocity : 1.0000000 2.0000000
3.0000000
cspice_qdq2av angular velocity: 1.0000000 2.0000000
3.0000000
cspice_xf2rav angular velocity: 1.0000000 2.0000000
3.0000000
About SPICE quaternions
=======================
There are (at least) two popular "styles" of quaternions; these
differ in the layout of the quaternion elements, the definition
of the multiplication operation, and the mapping between the set
of unit quaternions and corresponding rotation matrices.
SPICE-style quaternions have the scalar part in the first
component and the vector part in the subsequent components. The
SPICE convention, along with the multiplication rules for SPICE
quaternions, are those used by William Rowan Hamilton, the
inventor of quaternions.
Another common quaternion style places the scalar component
last. This style is often used in engineering applications.
1) A unitized version of input quaternion is used in the
computation. No attempt is made to diagnose an invalid
input quaternion.
2) If any of the input arguments, `q' or `dq', is undefined, an
error is signaled by the IDL error handling system.
3) If any of the input arguments, `q' or `dq', is not of the
expected type, or it does not have the expected dimensions and
size, an error is signaled by the Icy interface.
4) If the output argument `av' is not a named variable, an error
is signaled by the Icy interface.
None.
None.
ICY.REQ
ROTATION.REQ
None.
J. Diaz del Rio (ODC Space)
E.D. Wright (JPL)
-Icy Version 1.0.1, 10-AUG-2021 (JDR)
Added -Parameters and -Index_Entries sections. Edited the header to
comply with NAIF standard.
Added code example's description.
Removed reference to the routine's corresponding CSPICE header from
-Abstract section.
Added arguments' type and size information in the -I/O section.
-Icy Version 1.0.0, 06-NOV-2005 (EDW)
angular velocity from quaternion and derivative
|