blob: 224baea7206af6c92d7df6a859f9c8c5be309abe [file] [log] [blame]
rsc058b0112005-01-03 06:40:20 +00001.TH QUATERNION 3
2.SH NAME
3qtom, mtoq, qadd, qsub, qneg, qmul, qdiv, qunit, qinv, qlen, slerp, qmid, qsqrt \- Quaternion arithmetic
4.SH SYNOPSIS
5.PP
6.B
7#include <draw.h>
8.PP
9.B
10#include <geometry.h>
11.PP
12.B
13Quaternion qadd(Quaternion q, Quaternion r)
14.PP
15.B
16Quaternion qsub(Quaternion q, Quaternion r)
17.PP
18.B
19Quaternion qneg(Quaternion q)
20.PP
21.B
22Quaternion qmul(Quaternion q, Quaternion r)
23.PP
24.B
25Quaternion qdiv(Quaternion q, Quaternion r)
26.PP
27.B
28Quaternion qinv(Quaternion q)
29.PP
30.B
31double qlen(Quaternion p)
32.PP
33.B
34Quaternion qunit(Quaternion q)
35.PP
36.B
37void qtom(Matrix m, Quaternion q)
38.PP
39.B
40Quaternion mtoq(Matrix mat)
41.PP
42.B
43Quaternion slerp(Quaternion q, Quaternion r, double a)
44.PP
45.B
46Quaternion qmid(Quaternion q, Quaternion r)
47.PP
48.B
49Quaternion qsqrt(Quaternion q)
50.SH DESCRIPTION
51The Quaternions are a non-commutative extension field of the Real numbers, designed
52to do for rotations in 3-space what the complex numbers do for rotations in 2-space.
53Quaternions have a real component
54.I r
55and an imaginary vector component \fIv\fP=(\fIi\fP,\fIj\fP,\fIk\fP).
56Quaternions 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),
58where \v'-.3m'.\v'.3m' and × are the ordinary vector dot and cross products.
59The multiplicative inverse of a non-zero quaternion (\fIr\fP,\fIv\fP)
60is (\fIr\fP,\fI-v\fP)/(\fIr\^\fP\u\s-22\s+2\d-\fIv\fP\v'-.3m'.\v'.3m'\fIv\fP).
61.PP
62The following routines do arithmetic on quaternions, represented as
63.IP
64.EX
65.ta 6n
66typedef struct Quaternion Quaternion;
67struct Quaternion{
68 double r, i, j, k;
69};
70.EE
71.TF qunit
72.TP
73Name
74Description
75.TP
76.B qadd
77Add two quaternions.
78.TP
79.B qsub
80Subtract two quaternions.
81.TP
82.B qneg
83Negate a quaternion.
84.TP
85.B qmul
86Multiply two quaternions.
87.TP
88.B qdiv
89Divide two quaternions.
90.TP
91.B qinv
92Return the multiplicative inverse of a quaternion.
93.TP
94.B qlen
95Return
96.BR sqrt(q.r*q.r+q.i*q.i+q.j*q.j+q.k*q.k) ,
97the length of a quaternion.
98.TP
99.B qunit
100Return a unit quaternion
101.RI ( length=1 )
102with components proportional to
103.IR q 's.
104.PD
105.PP
106A rotation by angle \fIθ\fP about axis
107.I A
108(where
109.I A
110is a unit vector) can be represented by
111the unit quaternion \fIq\fP=(cos \fIθ\fP/2, \fIA\fPsin \fIθ\fP/2).
112The 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.
113The 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.
115Quaternion multiplication composes rotations.
116The orientation of an object in 3-space can be represented by a quaternion
117giving its rotation relative to some `standard' orientation.
118.PP
119The following routines operate on rotations or orientations represented as unit quaternions:
120.TF slerp
121.TP
122.B mtoq
123Convert a rotation matrix (see
124.IR matrix (3))
125to a unit quaternion.
126.TP
127.B qtom
128Convert a unit quaternion to a rotation matrix.
129.TP
130.B slerp
131Spherical lerp. Interpolate between two orientations.
132The rotation that carries
133.I q
134to
135.I r
136is \%\fIq\fP\u\s-2-1\s+2\d\fIr\fP, so
137.B slerp(q, r, t)
138is \fIq\fP(\fIq\fP\u\s-2-1\s+2\d\fIr\fP)\u\s-2\fIt\fP\s+2\d.
139.TP
140.B qmid
141.B slerp(q, r, .5)
142.TP
143.B qsqrt
144The square root of
145.IR q .
146This is just a rotation about the same axis by half the angle.
147.PD
148.SH SOURCE
rscc3674de2005-01-11 17:37:33 +0000149.B \*9/src/libgeometry/quaternion.c
rsc058b0112005-01-03 06:40:20 +0000150.SH SEE ALSO
151.IR matrix (3),
152.IR qball (3)
rsc5ba33c02005-03-28 15:58:14 +0000153.SH BUGS
154To avoid name conflicts with NetBSD,
155.I qdiv
156is a preprocessor macro defined as
157.IR p9qdiv ;
158see
159.IR intro (3).