3 qtom, mtoq, qadd, qsub, qneg, qmul, qdiv, qunit, qinv, qlen, slerp, qmid, qsqrt \- Quaternion arithmetic
13 Quaternion qadd(Quaternion q, Quaternion r)
16 Quaternion qsub(Quaternion q, Quaternion r)
19 Quaternion qneg(Quaternion q)
22 Quaternion qmul(Quaternion q, Quaternion r)
25 Quaternion qdiv(Quaternion q, Quaternion r)
28 Quaternion qinv(Quaternion q)
31 double qlen(Quaternion p)
34 Quaternion qunit(Quaternion q)
37 void qtom(Matrix m, Quaternion q)
40 Quaternion mtoq(Matrix mat)
43 Quaternion slerp(Quaternion q, Quaternion r, double a)
46 Quaternion qmid(Quaternion q, Quaternion r)
49 Quaternion qsqrt(Quaternion q)
51 The Quaternions are a non-commutative extension field of the Real numbers, designed
52 to do for rotations in 3-space what the complex numbers do for rotations in 2-space.
53 Quaternions have a real component
55 and an imaginary vector component \fIv\fP=(\fIi\fP,\fIj\fP,\fIk\fP).
56 Quaternions add componentwise and multiply according to the rule
57 (\fIr\fP,\fIv\fP)(\fIs\fP,\fIw\fP)=(\fIrs\fP-\fIv\fP\v'-.3m'.\v'.3m'\fIw\fP, \fIrw\fP+\fIvs\fP+\fIv\fP×\fIw\fP),
58 where \v'-.3m'.\v'.3m' and × are the ordinary vector dot and cross products.
59 The multiplicative inverse of a non-zero quaternion (\fIr\fP,\fIv\fP)
60 is (\fIr\fP,\fI-v\fP)/(\fIr\^\fP\u\s-22\s+2\d-\fIv\fP\v'-.3m'.\v'.3m'\fIv\fP).
62 The following routines do arithmetic on quaternions, represented as
66 typedef struct Quaternion Quaternion;
80 Subtract two quaternions.
86 Multiply two quaternions.
89 Divide two quaternions.
92 Return the multiplicative inverse of a quaternion.
96 .BR sqrt(q.r*q.r+q.i*q.i+q.j*q.j+q.k*q.k) ,
97 the length of a quaternion.
100 Return a unit quaternion
102 with components proportional to
106 A rotation by angle \fIθ\fP about axis
110 is a unit vector) can be represented by
111 the unit quaternion \fIq\fP=(cos \fIθ\fP/2, \fIA\fPsin \fIθ\fP/2).
112 The same rotation is represented by \(mi\fIq\fP; a rotation by \(mi\fIθ\fP about \(mi\fIA\fP is the same as a rotation by \fIθ\fP about \fIA\fP.
113 The quaternion \fIq\fP transforms points by
114 (0,\fIx',y',z'\fP) = \%\fIq\fP\u\s-2-1\s+2\d(0,\fIx,y,z\fP)\fIq\fP.
115 Quaternion multiplication composes rotations.
116 The orientation of an object in 3-space can be represented by a quaternion
117 giving its rotation relative to some `standard' orientation.
119 The following routines operate on rotations or orientations represented as unit quaternions:
123 Convert a rotation matrix (see
125 to a unit quaternion.
128 Convert a unit quaternion to a rotation matrix.
131 Spherical lerp. Interpolate between two orientations.
132 The rotation that carries
136 is \%\fIq\fP\u\s-2-1\s+2\d\fIr\fP, so
138 is \fIq\fP(\fIq\fP\u\s-2-1\s+2\d\fIr\fP)\u\s-2\fIt\fP\s+2\d.
146 This is just a rotation about the same axis by half the angle.
149 .B /usr/local/plan9/src/libgeometry/quaternion.c