1 058b0118 2005-01-03 devnull .TH QUATERNION 3
3 058b0118 2005-01-03 devnull qtom, mtoq, qadd, qsub, qneg, qmul, qdiv, qunit, qinv, qlen, slerp, qmid, qsqrt \- Quaternion arithmetic
4 058b0118 2005-01-03 devnull .SH SYNOPSIS
7 058b0118 2005-01-03 devnull #include <draw.h>
10 058b0118 2005-01-03 devnull #include <geometry.h>
13 058b0118 2005-01-03 devnull Quaternion qadd(Quaternion q, Quaternion r)
16 058b0118 2005-01-03 devnull Quaternion qsub(Quaternion q, Quaternion r)
19 058b0118 2005-01-03 devnull Quaternion qneg(Quaternion q)
22 058b0118 2005-01-03 devnull Quaternion qmul(Quaternion q, Quaternion r)
25 058b0118 2005-01-03 devnull Quaternion qdiv(Quaternion q, Quaternion r)
28 058b0118 2005-01-03 devnull Quaternion qinv(Quaternion q)
31 058b0118 2005-01-03 devnull double qlen(Quaternion p)
34 058b0118 2005-01-03 devnull Quaternion qunit(Quaternion q)
37 058b0118 2005-01-03 devnull void qtom(Matrix m, Quaternion q)
40 058b0118 2005-01-03 devnull Quaternion mtoq(Matrix mat)
43 058b0118 2005-01-03 devnull Quaternion slerp(Quaternion q, Quaternion r, double a)
46 058b0118 2005-01-03 devnull Quaternion qmid(Quaternion q, Quaternion r)
49 058b0118 2005-01-03 devnull Quaternion qsqrt(Quaternion q)
50 058b0118 2005-01-03 devnull .SH DESCRIPTION
51 058b0118 2005-01-03 devnull The Quaternions are a non-commutative extension field of the Real numbers, designed
52 058b0118 2005-01-03 devnull to do for rotations in 3-space what the complex numbers do for rotations in 2-space.
53 058b0118 2005-01-03 devnull Quaternions have a real component
55 058b0118 2005-01-03 devnull and an imaginary vector component \fIv\fP=(\fIi\fP,\fIj\fP,\fIk\fP).
56 058b0118 2005-01-03 devnull Quaternions add componentwise and multiply according to the rule
57 058b0118 2005-01-03 devnull (\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 058b0118 2005-01-03 devnull where \v'-.3m'.\v'.3m' and × are the ordinary vector dot and cross products.
59 058b0118 2005-01-03 devnull The multiplicative inverse of a non-zero quaternion (\fIr\fP,\fIv\fP)
60 058b0118 2005-01-03 devnull is (\fIr\fP,\fI-v\fP)/(\fIr\^\fP\u\s-22\s+2\d-\fIv\fP\v'-.3m'.\v'.3m'\fIv\fP).
62 058b0118 2005-01-03 devnull The following routines do arithmetic on quaternions, represented as
66 058b0118 2005-01-03 devnull typedef struct Quaternion Quaternion;
67 058b0118 2005-01-03 devnull struct Quaternion{
68 058b0118 2005-01-03 devnull double r, i, j, k;
71 058b0118 2005-01-03 devnull .TF qunit
74 058b0118 2005-01-03 devnull Description
77 058b0118 2005-01-03 devnull Add two quaternions.
80 058b0118 2005-01-03 devnull Subtract two quaternions.
83 058b0118 2005-01-03 devnull Negate a quaternion.
86 058b0118 2005-01-03 devnull Multiply two quaternions.
89 058b0118 2005-01-03 devnull Divide two quaternions.
92 058b0118 2005-01-03 devnull Return the multiplicative inverse of a quaternion.
96 058b0118 2005-01-03 devnull .BR sqrt(q.r*q.r+q.i*q.i+q.j*q.j+q.k*q.k) ,
97 058b0118 2005-01-03 devnull the length of a quaternion.
100 058b0118 2005-01-03 devnull Return a unit quaternion
101 058b0118 2005-01-03 devnull .RI ( length=1 )
102 058b0118 2005-01-03 devnull with components proportional to
103 058b0118 2005-01-03 devnull .IR q 's.
106 058b0118 2005-01-03 devnull A rotation by angle \fIθ\fP about axis
110 058b0118 2005-01-03 devnull is a unit vector) can be represented by
111 058b0118 2005-01-03 devnull the unit quaternion \fIq\fP=(cos \fIθ\fP/2, \fIA\fPsin \fIθ\fP/2).
112 058b0118 2005-01-03 devnull 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 058b0118 2005-01-03 devnull The quaternion \fIq\fP transforms points by
114 058b0118 2005-01-03 devnull (0,\fIx',y',z'\fP) = \%\fIq\fP\u\s-2-1\s+2\d(0,\fIx,y,z\fP)\fIq\fP.
115 058b0118 2005-01-03 devnull Quaternion multiplication composes rotations.
116 058b0118 2005-01-03 devnull The orientation of an object in 3-space can be represented by a quaternion
117 058b0118 2005-01-03 devnull giving its rotation relative to some `standard' orientation.
119 058b0118 2005-01-03 devnull The following routines operate on rotations or orientations represented as unit quaternions:
120 058b0118 2005-01-03 devnull .TF slerp
123 058b0118 2005-01-03 devnull Convert a rotation matrix (see
124 058b0118 2005-01-03 devnull .IR matrix (3))
125 058b0118 2005-01-03 devnull to a unit quaternion.
128 058b0118 2005-01-03 devnull Convert a unit quaternion to a rotation matrix.
130 058b0118 2005-01-03 devnull .B slerp
131 058b0118 2005-01-03 devnull Spherical lerp. Interpolate between two orientations.
132 058b0118 2005-01-03 devnull The rotation that carries
136 058b0118 2005-01-03 devnull is \%\fIq\fP\u\s-2-1\s+2\d\fIr\fP, so
137 058b0118 2005-01-03 devnull .B slerp(q, r, t)
138 058b0118 2005-01-03 devnull is \fIq\fP(\fIq\fP\u\s-2-1\s+2\d\fIr\fP)\u\s-2\fIt\fP\s+2\d.
141 058b0118 2005-01-03 devnull .B slerp(q, r, .5)
143 058b0118 2005-01-03 devnull .B qsqrt
144 058b0118 2005-01-03 devnull The square root of
146 058b0118 2005-01-03 devnull This is just a rotation about the same axis by half the angle.
148 058b0118 2005-01-03 devnull .SH SOURCE
149 c3674de4 2005-01-11 devnull .B \*9/src/libgeometry/quaternion.c
150 058b0118 2005-01-03 devnull .SH SEE ALSO
151 058b0118 2005-01-03 devnull .IR matrix (3),
152 058b0118 2005-01-03 devnull .IR qball (3)
153 5ba33c04 2005-03-28 devnull .SH BUGS
154 5ba33c04 2005-03-28 devnull To avoid name conflicts with NetBSD,
156 5ba33c04 2005-03-28 devnull is a preprocessor macro defined as
157 5ba33c04 2005-03-28 devnull .IR p9qdiv ;
159 5ba33c04 2005-03-28 devnull .IR intro (3).