3 qtom, mtoq, qadd, qsub, qneg, qmul, qdiv, qunit, qinv, qlen, slerp, qmid, qsqrt \- Quaternion arithmetic
12 Quaternion qadd(Quaternion q, Quaternion r)
15 Quaternion qsub(Quaternion q, Quaternion r)
18 Quaternion qneg(Quaternion q)
21 Quaternion qmul(Quaternion q, Quaternion r)
24 Quaternion qdiv(Quaternion q, Quaternion r)
27 Quaternion qinv(Quaternion q)
30 double qlen(Quaternion p)
33 Quaternion qunit(Quaternion q)
36 void qtom(Matrix m, Quaternion q)
39 Quaternion mtoq(Matrix mat)
42 Quaternion slerp(Quaternion q, Quaternion r, double a)
45 Quaternion qmid(Quaternion q, Quaternion r)
48 Quaternion qsqrt(Quaternion q)
50 The Quaternions are a non-commutative extension field of the Real numbers, designed
51 to do for rotations in 3-space what the complex numbers do for rotations in 2-space.
52 Quaternions have a real component
54 and an imaginary vector component \fIv\fP=(\fIi\fP,\fIj\fP,\fIk\fP).
55 Quaternions add componentwise and multiply according to the rule
56 (\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),
57 where \v'-.3m'.\v'.3m' and × are the ordinary vector dot and cross products.
58 The multiplicative inverse of a non-zero quaternion (\fIr\fP,\fIv\fP)
59 is (\fIr\fP,\fI-v\fP)/(\fIr\^\fP\u\s-22\s+2\d-\fIv\fP\v'-.3m'.\v'.3m'\fIv\fP).
61 The following routines do arithmetic on quaternions, represented as
65 typedef struct Quaternion Quaternion;
79 Subtract two quaternions.
85 Multiply two quaternions.
88 Divide two quaternions.
91 Return the multiplicative inverse of a quaternion.
95 .BR sqrt(q.r*q.r+q.i*q.i+q.j*q.j+q.k*q.k) ,
96 the length of a quaternion.
99 Return a unit quaternion
101 with components proportional to
105 A rotation by angle \fIθ\fP about axis
109 is a unit vector) can be represented by
110 the unit quaternion \fIq\fP=(cos \fIθ\fP/2, \fIA\fPsin \fIθ\fP/2).
111 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.
112 The quaternion \fIq\fP transforms points by
113 (0,\fIx',y',z'\fP) = \%\fIq\fP\u\s-2-1\s+2\d(0,\fIx,y,z\fP)\fIq\fP.
114 Quaternion multiplication composes rotations.
115 The orientation of an object in 3-space can be represented by a quaternion
116 giving its rotation relative to some `standard' orientation.
118 The following routines operate on rotations or orientations represented as unit quaternions:
122 Convert a rotation matrix (see
124 to a unit quaternion.
127 Convert a unit quaternion to a rotation matrix.
130 Spherical lerp. Interpolate between two orientations.
131 The rotation that carries
135 is \%\fIq\fP\u\s-2-1\s+2\d\fIr\fP, so
137 is \fIq\fP(\fIq\fP\u\s-2-1\s+2\d\fIr\fP)\u\s-2\fIt\fP\s+2\d.
145 This is just a rotation about the same axis by half the angle.
148 .B /sys/src/libgeometry/quaternion.c