1 | Implementation notes |
---|
2 | -------------------- |
---|
3 | |
---|
4 | The following are general points about the implementation of the quaternion |
---|
5 | toolbox. It is intended to expand these notes in due course to give more |
---|
6 | detailed information about the design of the toolbox. |
---|
7 | |
---|
8 | 1. The representation of a quaternion is hidden in a small number of private |
---|
9 | functions. This is to keep the bulk of the functions in the library separate |
---|
10 | from the representation, and to facilitate a later change of representation |
---|
11 | if needed. |
---|
12 | |
---|
13 | 2. Functions which are overloadings of Matlab functions generally take the |
---|
14 | same parameters as the Matlab function, but there are some exceptions where |
---|
15 | the Matlab function seemed to have unnecessary parameter combinations that |
---|
16 | are of little use. |
---|
17 | |
---|
18 | 3. Functions are inherently matrix-oriented as with standard Matlab functions. |
---|
19 | |
---|
20 | 4. Errors are limited to cases where parameters are incorrect or not supported. |
---|
21 | |
---|
22 | 5. Warnings are issued in cases where a result will be incorrect (for example |
---|
23 | a NaN, but the computation is not stopped). Generally the problem should be |
---|
24 | fixed at a higher level than the point where the warning occurs. If this is in |
---|
25 | one of the functions of the toolbox, the problem should be reported, otherwise |
---|
26 | if it is user code it should be fixed there. |
---|
27 | |
---|
28 | 6. Because the toolbox is designed to work with complexified quaternions (that |
---|
29 | is quaternions in which the four components are complex), there are some tricks |
---|
30 | in some of the functions. The modulus of a complex quaternion is complex, and it |
---|
31 | may be zero. This has many ramifications. One example suffices to illustrate the |
---|
32 | tricks needed. In the function unit.m, it is necessary to divide a quaternion by |
---|
33 | its modulus. There is an error check in the function to give a warning if any |
---|
34 | element of the quaternion array has zero modulus (in fact less than epsilon), |
---|
35 | but since the modulus may be complex, it is abs(m) that is compared with eps and |
---|
36 | not m itself. Note that if the modulus is real, abs(m) == m, and the abs |
---|
37 | function has no effect, whereas, if the modulus is complex, abs(m) is real, and |
---|
38 | it can only be zero if the modulus is zero. |
---|
39 | |
---|
40 | 7. The overloading of the Matlab functions real, imag and conj is important. |
---|
41 | real and imag operate exactly as their complex counterparts. Applied to a |
---|
42 | complex quaternion they return a real quaternion which is the real or imaginary |
---|
43 | part of the complex quaternion, exactly analogous to the complex case. conj, |
---|
44 | however, is different since it returns the quaternion conjugate by default - the |
---|
45 | vector part is negated not the complex part of the components. To obtain the |
---|
46 | complex conjugate a second parameter is needed. There is also a total conjugate, |
---|
47 | which means both the quaternion and complex conjugates are applied. The reason |
---|
48 | for making the default the quaternion conjugate is subtle: conj is used in |
---|
49 | ctranspose and in inverse, and in both of these cases it must be the quaternion |
---|
50 | conjugate. Therefore for consistency, conj is the quaternion conjugate. The use |
---|
51 | of a different name (e.g. qconj) was considered but the problem of the ' |
---|
52 | operator (conjugate transpose) would remain. It is clear that this operator |
---|
53 | should implement the quaternion conjugate transpose because it is this transpose |
---|
54 | that is needed most often and not the complex conjugate transpose. We can't |
---|
55 | introduce a new operator into Matlab. If we want a complex conjugate transpose |
---|
56 | we have to write conj(A.', 'complex'). |
---|
57 | |
---|
58 | Steve Sangwine |
---|
59 | Nicolas Le Bihan |
---|
60 | |
---|
61 | Email: S.Sangwine@IEEE.org, nicolas.le-bihan@lis.inpg.fr |
---|
62 | |
---|
63 | LIS, Grenoble |
---|
64 | July 2005 |
---|
65 | Amended March 2006 |
---|