rsspice 0.1.0

Pure Rust port of the SPICE Toolkit for space geometry
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
//! #  Rotation
//!
//!  Last revised on 2017 MAR 09 by N. J. Bachman.
//!
//!  
//!
//!
//!  
//! ##  Abstract
//!
//!  The SPICE rotation routines manipulate and convert between different
//!    representations of rotation transformations: matrices, quaternions,
//!    Euler angles, and axis-angle pairs.
//!
//!  
//!
//!
//!  
//! ##  Introduction
//!
//!  This document covers the SPICELIB routines that deal with rotations and
//!    the mathematical ideas behind the routines.
//!
//!  There are three chapters:
//!
//!  
//!
//! * SPICELIB routines
//!
//!  *  The "SPICELIB routines" chapter tells you what routines are available,
//! what they do, and how to call them.
//!
//!  * Tutorial introduction to rotations
//!
//!  *  If rotations are new to you, you'll profit most by reading the "tutorial"
//! chapter first. This chapter lists most of the facts about rotations used in
//! the SPICELIB code. The emphasis is on building intuition about rotations;
//! proofs of any noticeable difficulty or length are deferred to the
//! "Mathematical Road Map" chapter.
//!
//!  * Mathematical road map
//!
//!  *  This chapter contains detailed explanations of a number of the mathematical
//! ideas used in the SPICELIB rotation routines. And as we've said, proofs of
//! some of assertions made in the tutorial chapter are stowed here.
//!
//!     
//! ###  Using this document
//!
//!  For many readers, the first chapter will be the only one of interest.
//!    The mechanics of using the rotation routines in your code are covered
//!    here.
//!
//!  The rest of the document covers the ideas behind the code. This material
//!    is meant to be used as a reference rather than to be read from start to
//!    finish; the topics are ordered loosely according to logical dependence,
//!    but there is no narrative progression from section to section.
//!
//!  The purpose of the tutorial and "road map" chapters is to make it
//!    easier to be certain that you're using the code correctly. In our
//!    experience, thinking about this category of code only in terms of
//!    "inputs" and "outputs" is a tricky and error-prone approach; really
//!    understanding the mathematics helps you to verify that you're putting
//!    the pieces together in ways that make sense.
//!
//!  Because some of the ideas required to understand the code seem to exist
//!    as lore and are rarely written down, we've collected them here for your
//!    convenience.
//!
//!  
//!
//!
//!  
//! ###  References
//!
//!  
//!
//! *  1. For SPICELIB routines dealing with inertial reference frames: SPK
//! "required reading." ([spk.req](crate::required_reading::spk))
//!
//!  *  2. For SPICELIB routines dealing with body-fixed reference frames: KERNEL
//! "required reading." ([kernel.req](crate::required_reading::kernel))
//!
//!  *  3. For linear algebra: "Calculus, Vol. II." Tom M. Apostol. Wiley and Sons,
//! 1969.
//!
//!  *  Also, "Elementary Linear Algebra." Howard Anton. Wiley and Sons, 1977.
//!
//!  *  4. NAIF document number 179.0, "Rotations and Their Habits," by Dr. William
//! Taber.
//!
//!  *  5. NAIF document number 192.0, "Memo to: Quaternion Seekers," by Allen
//! Klumpp.
//!
//!     
//! ###  Notation
//!
//!  Here are the symbols used in this document, and their definitions:
//!
//!  
//!
//! ```text
//!     Symbol                      Meaning
//!    ---------          ----------------------------------
//!  
//!       E3              Three-dimensional Euclidean space.
//!  
//!       E2              Two-dimensional Euclidean space.
//!  
//!    < u, v >           Inner product of vectors u and v.
//!  
//!         T
//!       M               Transpose of the matrix M.
//!  
//!        -1
//!       M               Inverse of the matrix M.
//!  
//!        -1
//!       f               Inverse of the function f.
//!  
//!     u x v             Cross product of vectors u and v.
//!  
//!      M v              Product of matrix M and vector v.
//!  
//!      M N              Product of matrix M and matrix N.
//!  
//!    Trace(M)           Sum of elements on the main diagonal of M.
//!  
//!      [w]              Matrix that rotates a coordinate system by
//!         i             w radians about the ith coordinate axis
//!                       (and rotates vectors by -w radians about the
//!                       same axis).  We also use this notation to refer
//!                       to the linear transformation corresponding to
//!                       this matrix.
//! ```
//!
//!  There are only three types of rotation matrices representing rotations
//!    about coordinate axes:
//!
//!  
//!
//! ```text
//!             +-                        -+
//!             |     1       0        0   |
//!    [w]   =  |     0    cos(w)   sin(w) |
//!       1     |     0   -sin(w)   cos(w) |
//!             +-                        -+
//!  
//!             +-                        -+
//!             |  cos(w)     0    -sin(w) |
//!    [w]   =  |     0       1        0   |
//!       2     |  sin(w)     0     cos(w) |
//!             +-                        -+
//!  
//!             +-                        -+
//!             |  cos(w)  sin(w)      0   |
//!    [w]   =  | -sin(w)  cos(w)      0   |
//!       3     |     0       0        1   |
//!             +-                        -+
//! ```
//!
//!  The composition of rotations
//!
//!  
//!
//! ```text
//!    [w1]   [w2]   [w3]
//!        a      b      c
//! ```
//!
//!  is sometimes referred to as a "a-b-c" rotation. For example, we may
//!    talk about a "3-1-3" rotation.
//!
//!  About angles: all angles in this document are measured in radians.
//!
//!  About directions: the "right hand rule" is in effect at all times in
//!    this document, so counterclockwise rotations about an axis have positive
//!    measure.
//!
//!  
//!
//!
//!  
//! #  SPICELIB Routines
//!
//!  This chapter describes the SPICELIB routines that deal with rotations.
//!    The chapter lists the SPICELIB rotation routines and discusses each
//!    routine.
//!
//!  The SPICELIB routines that deal with general rotations are:
//!
//!  
//!
//! *  [AXISAR](crate::raw::axisar)
//!
//!
//!  ( Axis and angle to rotation )
//!
//!  *  [DROTAT](crate::raw::drotat)
//!
//!
//!  ( Derivative of a rotation matrix )
//!
//!  *  [EUL2M](crate::raw::eul2m)
//!
//!
//!  ( Euler angles to matrix )
//!
//!  *  [EUL2XF](crate::raw::eul2xf)
//!
//!
//!  ( Euler angles and derivative to transformation )
//!
//!  *  [INVSTM](crate::raw::invstm)
//!
//!
//!  ( Inverse of state transformation matrix )
//!
//!  *  [ISROT](crate::raw::isrot)
//!
//!
//!  ( Is it a rotation matrix? )
//!
//!  *  [M2EUL](crate::raw::m2eul)
//!
//!
//!  ( Matrix to Euler angles )
//!
//!  *  [M2Q](crate::raw::m2q)
//!
//!
//!  ( Matrix to quaternion )
//!
//!  *  [PXFORM](crate::raw::pxform)
//!
//!
//!  ( Position transformation matrix )
//!
//!  *  [Q2M](crate::raw::q2m)
//!
//!
//!  ( Quaternion to matrix )
//!
//!  *  [QDQ2AV](crate::raw::qdq2av)
//!
//!
//!  ( Quaternion and derivative to angular velocity )
//!
//!  *  [QXQ](crate::raw::qxq)
//!
//!
//!  ( Quaternion times quaternion )
//!
//!  *  [RAXISA](crate::raw::raxisa)
//!
//!
//!  ( Rotation axis and angle )
//!
//!  *  [RAV2XF](crate::raw::rav2xf)
//!
//!
//!  ( Rotation and angular velocity to transform )
//!
//!  *  ROTATE
//!
//!
//!  ( Generate a rotation matrix )
//!
//!  *  [ROTMAT](crate::raw::rotmat)
//!
//!
//!  ( Rotate a matrix about a coordinate axis )
//!
//!  *  [ROTVEC](crate::raw::rotvec)
//!
//!
//!  ( Rotate a vector about a coordinate axis )
//!
//!  *  [SXFORM](crate::raw::sxform)
//!
//!
//!  ( State transformation matrix )
//!
//!  *  [TIPBOD](crate::raw::tipbod)
//!
//!
//!  ( Transformation, inertial position to bodyfixed )
//!
//!  *  [TISBOD](crate::raw::tisbod)
//!
//!
//!  ( Transformation, inertial state to bodyfixed )
//!
//!  *  [VROTV](crate::raw::vrotv)
//!
//!
//!  ( Rotate a vector about an arbitrary axis )
//!
//!  *  [XF2EUL](crate::raw::xf2eul)
//!
//!
//!  ( State transformation to Euler angles )
//!
//!  *  [XF2RAV](crate::raw::xf2rav)
//!
//!
//!  ( Transform to rotation and angular velocity)
//!
//!  Additional SPICELIB routines that deal with rotations between specific
//!    coordinate systems are documented in the FRAMES required reading and in
//!    the header of the SPICELIB routine [SXFORM](crate::raw::sxform).
//!
//!  
//!
//!
//!  
//! ###  Categories of routines
//!
//!  The discussions of the routines are categorized according to the type of
//!    problem that the routines solve. This chapter contains one section for
//!    each category. The categories are:
//!
//!  
//!
//! * Euler angles
//!
//!  * Quaternions
//!
//!  * Rotating vectors and matrices
//!
//!  * Rotation axis and angle
//!
//!  * Rotation derivatives
//!
//!  * Validating rotation matrices
//!
//!  The rotation routines constitute a "family" of routines insofar as
//!    they deal with related problems, but they do not constitute a
//!    "system." So, there is no logical interdependence between the
//!    discussions of routines in different categories.
//!
//!  
//!
//!
//!  
//! ##  Euler angle routines
//!
//!  The SPICELIB Euler angle routines are:
//!
//!  
//!
//! *  [EUL2M](crate::raw::eul2m)
//!
//!
//!  ( Euler angles to matrix )
//!
//!  *  [M2EUL](crate::raw::m2eul)
//!
//!
//!  ( Matrix to Euler angles )
//!
//!  [EUL2M](crate::raw::eul2m) and [M2EUL](crate::raw::m2eul) provide a convenient way to solve problems such as
//!    converting between C-matrices and RA, Dec, and Twist. These routines are
//!    inverses of each other, roughly speaking.
//!
//!  
//!
//!
//!  
//! ###  Constructing a matrix from Euler angles
//!
//!  The routine [EUL2M](crate::raw::eul2m) constructs the rotation matrix defined by three Euler
//!    angles ANG(3), ANG(2), ANG(1), and three coordinate axes indexed by the
//!    integers I(3), I(2), I(1).
//!
//!  The call
//!
//!  
//!
//! ```text
//!     CALL EUL2M ( ANG(3),   ANG(2),   ANG(1),
//!    .             I(3),     I(2),     I(1),     M )
//! ```
//!
//!  returns the matrix M, where
//!
//!  
//!
//! ```text
//!    M   =   [ANG(3)]       [ANG(2)]        [ANG(1)]    .
//!                    I(3)           I(2)            I(1)
//! ```
//!
//!  The indices I(3), I(2), I(1) must belong to the set
//!
//!  
//!
//! ```text
//!    {1, 2, 3}.
//! ```
//!
//!     
//! ###  Finding Euler angles that represent a matrix
//!
//!  Given a rotation matrix M and three coordinate axes indexed by the
//!    integers I(3), I(2), I(1), the routine [M2EUL](crate::raw::m2eul) finds angles ANG(3),
//!    ANG(2), ANG(1) such that
//!
//!  
//!
//! ```text
//!    M  =   [ANG(3)]       [ANG(2)]        [ANG(1)]    .
//!                   I(3)           I(2)            I(1)
//! ```
//!
//!  The call
//!
//!  
//!
//! ```text
//!     CALL M2EUL ( M,  I(3),    I(2),     I(1),
//!    .                 ANG(3),  ANG(2),   ANG(1) )
//! ```
//!
//!  returns the desired angles. [M2EUL](crate::raw::m2eul) restricts the ranges of the output
//!    angles so as to guarantee that the Euler angle representation is unique.
//!    The output angles ANG(3) and ANG(1) are always in the range (-pi,pi].
//!    The range of ANG(2) is determined by the set of rotation axes. When I(3)
//!    equals I(1), ANG(2) is in the range \[0, pi]. Otherwise, ANG(2) is in the
//!    range \[-pi/2, pi/2]. These ranges make unique determinations of Euler
//!    angles possible, except in degenerate cases.
//!
//!  In cases where the Euler angles are not uniquely determined, [EUL2M](crate::raw::eul2m) sets
//!    the first angle (called ANG(3) above) to zero. The other two angles are
//!    then uniquely determined.
//!
//!  Again, the indices I(3), I(2), I(1) are members of
//!
//!  
//!
//! ```text
//!    {1, 2, 3}.
//! ```
//!
//!  There is a restriction on the allowed set of coordinate axes: I(2) must
//!    not equal I(3) or I(1). If this constraint is not met, the desired
//!    representation of M by Euler angles may not exist; [M2EUL](crate::raw::m2eul) signals an
//!    error in this case.
//!
//!  
//!
//!
//!  
//! ###  Programming hazards
//!
//!  There are several pitfalls associated with converting matrices to Euler
//!    angles. First, any mapping from matrices to Euler angles has
//!    singularities. These come in two flavors: some matrices don't map to a
//!    unique set of Euler angles, and some matrices have the property that a
//!    small change in the matrix can result in a large change in the
//!    corresponding Euler angles.
//!
//!  The first category of singularity occurs with matrices that represent
//!    rotations about the first or third axis in the sequence of rotation axes
//!    (for example, axis 3 for a 2-1-3 rotation). In practical terms, if [EUL2M](crate::raw::eul2m)
//!    encounters one of these special matrices, [EUL2M](crate::raw::eul2m) must choose the Euler
//!    angles. Immediately the possibility arises that [EUL2M](crate::raw::eul2m) will disagree with
//!    any other code performing the same task.
//!
//!  The second kind of singularity occurs when any of the Euler angles
//!    corresponding to a matrix is at one of the endpoints of its range, for
//!    example, when the first angle has the value pi. If the matrix is
//!    perturbed slightly, the first angle may jump from pi to a value close to
//!    -pi. Again, two different pieces of code may give different results in
//!    such a case, merely because of round-off error. Euler angles near the
//!    limits of their ranges should be regarded with suspicion.
//!
//!  The existence of singularities in the matrix-to-Euler angle mapping
//!    prevents [EUL2M](crate::raw::eul2m) and [M2EUL](crate::raw::m2eul) from being exact inverses: most of the time,
//!    the code fragment
//!
//!  
//!
//! ```text
//!     CALL EUL2M (     ANG(3),   ANG(2),   ANG(1),
//!    .                 AXIS(1),  AXIS(2),  AXIS(3),  M  )
//!  
//!     CALL M2EUL ( M,  AXIS(1),  AXIS(2),  AXIS(3),
//!    .                 ANG(3),   ANG(2),   ANG(1)       )
//! ```
//!
//!  leaves the angles ANG(3), ANG(2), ANG(1) unchanged, except for round-off
//!    error, but in some cases, the angles may change drastically.
//!
//!  If we reverse the order of the routine calls in the last code fragment,
//!    the matrix M should be preserved, except for errors due to loss of
//!    precision. The loss of precision can be considerable, though, for
//!    matrices whose entries are nearly those of any degenerate case matrix.
//!
//!  For more details on this topic, consult the "Mathematical road map"
//!    section.
//!
//!  
//!
//!
//!  
//! ###  Working with RA, Dec and Twist
//!
//!  The Euler angle routines could be used for conversion between "RA, Dec,
//!    and Twist" and a "C-matrix." Most projects, including Voyager and
//!    Cassini define the relationship as:
//!
//!  
//!
//! ```text
//!    C  =  [ Twist ]   [ pi/2 - Dec ]   [ pi/2 + RA ]
//!                   3                1               3
//! ```
//!
//!  so the code fragments
//!
//!  
//!
//! ```text
//!     CALL EUL2M ( TWIST,    HALFPI() - DEC,   HALFPI() + RA
//!    .             3,        1,                3,              C  )
//! ```
//!
//!  and
//!
//!  
//!
//! ```text
//!     CALL M2EUL ( C,    3,        1,        3,
//!    .                   ANG(3),   ANG(2),   ANG(1)  )
//!  
//!     TWIST = ANG(3)
//!     DEC   = HALFPI() - ANG(2)
//!     RA    = ANG(1)   - HALFPI()
//! ```
//!
//!  carry out the conversion from RA, Dec, and Twist to a C matrix, and
//!    back.
//!
//!  Note that definitions of "RA, Dec, and Twist" vary: on the Galileo
//!    project, the C matrix is related to the angles "RA, Dec, and Twist" by
//!    the equation
//!
//!  
//!
//! ```text
//!    C  =  [ Twist ]   [ pi/2 - Dec ]    [ RA ] .
//!                   3                2         3
//! ```
//!
//!     
//! ##  Quaternions
//!
//!  The SPICELIB quaternion routines are:
//!
//!  
//!
//! *  [M2Q](crate::raw::m2q)
//!
//!
//!  ( Matrix to quaternion )
//!
//!  *  [Q2M](crate::raw::q2m)
//!
//!
//!  ( Quaternion to matrix )
//!
//!  *  [QDQ2AV](crate::raw::qdq2av)
//!
//!
//!  ( Quaternion and derivative to angular velocity )
//!
//!  *  [QXQ](crate::raw::qxq)
//!
//!
//!  ( Quaternion times quaternion )
//!
//!  Quaternions are used in SPICELIB as a compact representation for
//!    rotations. They may be used to compose rotations more efficiently than
//!    can be done with matrix multiplication.
//!
//!  
//!
//!
//!  
//! ###  Finding a quaternion that represents a matrix
//!
//!  The routine [M2Q](crate::raw::m2q) produces a quaternion that represents a specified
//!    rotation matrix.
//!
//!  The code fragment
//!
//!  
//!
//! ```text
//!    CALL M2Q ( M, Q )
//! ```
//!
//!  returns a unit quaternion Q that represents the rotation matrix M.
//!
//!  If you really want to know about it, the elements of the quaternion are
//!    defined as follows:
//!
//!  Let the unit vector A be a choice of rotation axis for M, and let ANGLE
//!    be the rotation angle, where ANGLE is in the interval
//!
//!  
//!
//! ```text
//!    [0, pi]
//! ```
//!
//!  Then the elements of the unit quaternion Q returned by [M2Q](crate::raw::m2q) are
//!
//!  
//!
//! ```text
//!    Q(0) = cos( ANGLE/2 )
//!  
//!    Q(1) = sin( ANGLE/2 ) * A(1)
//!    Q(2) = sin( ANGLE/2 ) * A(2)
//!    Q(3) = sin( ANGLE/2 ) * A(3)
//! ```
//!
//!  [M2Q](crate::raw::m2q) considers the rotation angle of M to lie in \[0, pi]. Therefore, half
//!    the rotation angle lies in \[0, pi/2], so Q(0) is always in \[0, 1]. For a
//!    given rotation matrix M, the corresponding quaternion is uniquely
//!    determined except if the rotation angle is pi.
//!
//!  
//!
//!
//!  
//! ###  Finding the matrix represented by a quaternion
//!
//!  The routine [Q2M](crate::raw::q2m) inverts the transformation performed by [M2Q](crate::raw::m2q). The
//!    following call finds the rotation matrix M represented by the unit
//!    quaternion Q:
//!
//!  
//!
//! ```text
//!    CALL Q2M ( Q, M )
//! ```
//!
//!     
//! ###  [Q2M](crate::raw::q2m) and [M2Q](crate::raw::m2q) are approximate inverses of each other
//!
//!  The calls
//!
//!  
//!
//! ```text
//!    CALL M2Q ( M, Q )
//!    CALL Q2M ( Q, M )
//! ```
//!
//!  always preserve M, except for round-off error.
//!
//!  However, since there are two quaternions that represent each rotation,
//!    the sequence of calls
//!
//!  
//!
//! ```text
//!    CALL Q2M ( Q, M )
//!    CALL M2Q ( M, Q )
//! ```
//!
//!  do not necessarily preserve Q.
//!
//!  
//!
//!
//!  
//! ###  Multiplying quaternions
//!
//!  Two quaternions Q1, Q2 may be multiplied by calling [QXQ](crate::raw::qxq):
//!
//!  
//!
//! ```text
//!    CALL QXQ ( Q1, Q2, QOUT )
//! ```
//!
//!  The resulting product QOUT is computed using the multiplication formula
//!    given in the section "Quaternion Arithmetic" below. QOUT represents
//!    the rotation formed by composing the rotations represented by Q1 and Q2.
//!
//!  
//!
//!
//!  
//! ###  Obtaining angular velocity from quaternions
//!
//!  Given a quaternion Q and its derivative with respect to time DQ, the
//!    angular velocity of the reference frame represented by Q may be found by
//!    calling [QDQ2AV](crate::raw::qdq2av):
//!
//!  
//!
//! ```text
//!    CALL QDQ2AV ( Q, DQ, AV )
//! ```
//!
//!  The resulting angular velocity vector AV has units of radians/T, where
//!    1/T is the time unit associated with DQ.
//!
//!  
//!
//!
//!  
//! ##  Rotating vectors and matrices
//!
//!  The SPICELIB routines that "rotate" vectors and matrices are:
//!
//!  
//!
//! *  [ROTVEC](crate::raw::rotvec)
//!
//!
//!  ( Rotate vector )
//!
//!  *  [ROTMAT](crate::raw::rotmat)
//!
//!
//!  ( Rotate matrix )
//!
//!  *  [VROTV](crate::raw::vrotv)
//!
//!
//!  ( Rotate a vector about an axis )
//!
//!  This set of routines are frequently used as utilities from which more
//!    complicated routines may be constructed. For example, the routine [EUL2M](crate::raw::eul2m) constructs a rotation matrix from a sequence of three rotations about
//!    specified coordinate axis, so there is no need to call [ROTMAT](crate::raw::rotmat) directly
//!    to accomplish this.
//!
//!  
//!
//!
//!  
//! ###  A word of warning
//!
//!  Some care is needed when dealing with signs of rotation angles: a
//!    rotation of a vector by an angle THETA can be viewed as rotating the
//!    coordinate system by -THETA. We try to avoid confusion here by referring
//!    to routines as "coordinate system rotations" or "vector rotations,"
//!    depending on whether a positive rotation angle corresponds to rotating
//!    the coordinate system by a positive angle, or to rotating a vector by a
//!    positive angle. The same criterion applies to matrix rotations.
//!    According to this classification, [ROTVEC](crate::raw::rotvec) and [ROTMAT](crate::raw::rotmat) perform coordinate
//!    rotations, and [VROTV](crate::raw::vrotv) performs a vector rotation.
//!
//!  
//!
//!
//!  
//! ###  Rotating a vector about a coordinate axis
//!
//!  To apply the rotation
//!
//!  
//!
//! ```text
//!    [angle]
//!           i
//! ```
//!
//!  to a vector, use [ROTVEC](crate::raw::rotvec). The following code fragment applies
//!
//!  
//!
//! ```text
//!    [ ANGLE ]
//!             3
//! ```
//!
//!  to the vector V, yielding VOUT.
//!
//!  
//!
//! ```text
//!    CALL ROTVEC ( V, ANGLE, 3, VOUT )
//! ```
//!
//!  The components of VOUT are the coordinates of the vector V in a system
//!    rotated by ANGLE radians about the third coordinate axis. We can also
//!    regard VOUT as V, rotated by
//!
//!  
//!
//! ```text
//!    -ANGLE
//! ```
//!
//!  radians about the third coordinate axis.
//!
//!  
//!
//!
//!  
//! ###  Rotating a matrix about a coordinate axis
//!
//!  We can apply the same rotation
//!
//!  
//!
//! ```text
//!    [angle]
//!           i
//! ```
//!
//!  to a matrix using [ROTMAT](crate::raw::rotmat), as follows:
//!
//!  
//!
//! ```text
//!    CALL ROTMAT ( M, ANGLE, 3, MOUT )
//! ```
//!
//!  After this routine call, MOUT is equal to
//!
//!  
//!
//! ```text
//!    [ANGLE]  * M
//!           3
//! ```
//!
//!     
//! ###  Rotating a vector about an arbitrary axis
//!
//!  We can rotate a vector about an arbitrary axis using [VROTV](crate::raw::vrotv). The code
//!    fragment
//!
//!  
//!
//! ```text
//!    CALL VROTV ( V, AXIS, ANGLE, VOUT )
//! ```
//!
//!  rotates the vector V about the vector AXIS by ANGLE radians, yielding
//!    VOUT.
//!
//!  
//!
//!
//!  
//! ##  Rotation axis and angle
//!
//!  There are three SPICELIB routines that deal with rotation axes and
//!    angles:
//!
//!  
//!
//! *  [AXISAR](crate::raw::axisar)
//!
//!
//!  ( Axis and angle to rotation )
//!
//!  *  [RAXISA](crate::raw::raxisa)
//!
//!
//!  ( Rotation axis and angle )
//!
//!  *  ROTATE
//!
//!
//!  ( Generate a rotation matrix )
//!
//!  Like the routines that rotate vectors and matrices, these routines are
//!    frequently used as building blocks for more sophisticated routines.
//!
//!  
//!
//!
//!  
//! ###  Constructing a matrix from a rotation axis and angle
//!
//!  To generate a matrix that rotates vectors by a specified angle about an
//!    arbitrary axis, use [AXISAR](crate::raw::axisar). If AXIS is the axis vector and ANGLE is the
//!    rotation angle, the code fragment
//!
//!  
//!
//! ```text
//!    CALL AXISAR ( AXIS, ANGLE, M )
//! ```
//!
//!  produces M, the desired rotation matrix.
//!
//!  What if we want generate a coordinate system rotation about an arbitrary
//!    axis, as opposed to a coordinate axis? We can use [AXISAR](crate::raw::axisar) for this. Let
//!    AXIS be the coordinate system rotation axis and ANGLE be the rotation
//!    angle; then the code fragment
//!
//!  
//!
//! ```text
//!    CALL AXISAR ( AXIS, -ANGLE, M )
//! ```
//!
//!  produces the desired coordinate system rotation matrix. Note that the
//!    input angle is the NEGATIVE of that associated with a vector rotation. [AXISAR](crate::raw::axisar) is designed this way for compatibility with [RAXISA](crate::raw::raxisa), which is an
//!    inverse routine for [AXISAR](crate::raw::axisar).
//!
//!  
//!
//!
//!  
//! ###  Finding the axis and angle of a rotation matrix
//!
//!  To find the rotation axis and angle of a rotation matrix M, use [RAXISA](crate::raw::raxisa):
//!
//!  
//!
//! ```text
//!    CALL RAXISA ( M,  AXIS,  ANGLE )
//! ```
//!
//!  AXIS and ANGLE have the property that for any vector V,
//!
//!  
//!
//! ```text
//!    M V
//! ```
//!
//!  yields V, rotated by ANGLE radians about the vector AXIS. If M is viewed
//!    as a coordinate transformation, we can say that M rotates the initial
//!    coordinate system by
//!
//!  
//!
//! ```text
//!    - ANGLE
//! ```
//!
//!  radians about AXIS.
//!
//!  
//!
//!
//!  
//! ###  [AXISAR](crate::raw::axisar) and [RAXISA](crate::raw::raxisa) are approximate inverses
//!
//!  The code fragment
//!
//!  
//!
//! ```text
//!    CALL RAXISA ( M,    AXIS,  ANGLE )
//!    CALL AXISAR ( AXIS, ANGLE, M     )
//! ```
//!
//!  leaves M unchanged, except for round-off error.
//!
//!  The code fragment
//!
//!  
//!
//! ```text
//!    CALL AXISAR ( AXIS, ANGLE, M     )
//!    CALL RAXISA ( M,    AXIS,  ANGLE )
//! ```
//!
//!  usually leaves AXIS and ANGLE unchanged, except for round-off error,
//!    provided that two conditions are met:
//!
//!  
//!
//! * ANGLE is in the range (0,pi)
//!
//!  * AXIS is a unit vector.
//!
//!  If ANGLE is near zero or pi, loss of precision may preclude recovery of
//!    AXIS.
//!
//!  
//!
//!
//!  
//! ###  Using [RAXISA](crate::raw::raxisa) and [AXISAR](crate::raw::axisar)
//!
//!  [RAXISA](crate::raw::raxisa) and [AXISAR](crate::raw::axisar) can be used to perform linear interpolation between
//!    two rotation matrices. Here's a code fragment illustrating the
//!    procedure:
//!
//!  
//!
//! ```text
//!    C
//!    C     Let R(t) be a time-varying rotation matrix; R could be
//!    C     a C-matrix describing the orientation of a spacecraft
//!    C     structure.  Given two points in time t1 and t2 at which
//!    C     R(t) is known, and given a third time t3, where
//!    C
//!    C        t1  <  t3  <  t2,
//!    C
//!    C     we can estimate R(t3) by linear interpolation.  In other
//!    C     words, we approximate the motion of R by pretending that
//!    C     R rotates about a fixed axis at a uniform angular rate
//!    C     during the time interval [t1, t2].  More specifically, we
//!    C     assume that each column vector of R rotates in this
//!    C     fashion.  This procedure will not work if R rotates through
//!    C     an angle of pi radians or more during the time interval
//!    C     [t1, t2]; an aliasing effect would occur in that case.
//!    C
//!    C     If we let
//!    C
//!    C        R1 = R(t1)
//!    C        R2 = R(t2), and
//!    C
//!    C                    -1
//!    C        Q  = R2 * R1  ,
//!    C
//!    C     then the rotation axis and angle of Q define the rotation
//!    C     that each column of R(t) undergoes from time t1 to time
//!    C     t2.  Since R(t) is orthogonal, we can find Q using the
//!    C     transpose of R1.  We find the rotation axis and angle via
//!    C     RAXISA.
//!    C
//!          CALL MXMT   ( R2,   R1,    Q      )
//!          CALL RAXISA ( Q,    AXIS,  ANGLE  )
//!  
//!    C
//!    C     Find the fraction of the total rotation angle that R
//!    C     rotates through in the time interval [t1, t3].
//!    C
//!          FRAC = ( T3 - T1 )  /  ( T2 - T1 )
//!  
//!    C
//!    C     Finally, find the rotation DELTA that R(t) undergoes
//!    C     during the time interval [t1, t3], and apply that rotation
//!    C     to R1, yielding R(t3), which we'll call R3.
//!    C
//!             CALL AXISAR ( AXIS,   FRAC * ANGLE,  DELTA  )
//!             CALL MXM    ( DELTA,  R1,            R3     )
//! ```
//!
//!     
//! ###  Constructing a coordinate axis rotation matrix
//!
//!  The routine ROTATE generates the rotation matrix
//!
//!  
//!
//! ```text
//!    [ANGLE] ,
//!           I
//! ```
//!
//!  which corresponds to a rotation about a coordinate axis. This is a
//!    special case of the problem solved by [AXISAR](crate::raw::axisar). Note however that the
//!    matrix produced by ROTATE is the inverse of that produced by [AXISAR](crate::raw::axisar), if
//!    both routines are provided with the same input angle, and [AXISAR](crate::raw::axisar) is
//!    given the Ith coordinate basis vector as the rotation axis.
//!
//!  The call
//!
//!  
//!
//! ```text
//!    CALL ROTATE ( ANGLE, I, M )
//! ```
//!
//!  produces M, the desired matrix.
//!
//!  
//!
//!
//!  
//! ##  Rotation derivatives
//!
//!  The SPICELIB routines that deal with derivatives of rotations are:
//!
//!  
//!
//! *  [DROTAT](crate::raw::drotat)
//!
//!
//!  ( Derivative of a rotation matrix )
//!
//!  *  [INVSTM](crate::raw::invstm)
//!
//!
//!  ( Inverse of state transformation matrix )
//!
//!  *  [TISBOD](crate::raw::tisbod)
//!
//!
//!  ( Transformation, inertial state to bodyfixed )
//!
//!  The rotation derivative routines are utilities that simplify finding
//!    derivatives of time-varying coordinate transformations. In particular,
//!    these routines are used to transform state vectors between non-inertial
//!    reference frames.
//!
//!  
//!
//!
//!  
//! ###  Differentiating rotations
//!
//!  The routine [DROTAT](crate::raw::drotat) gives the derivative of a coordinate axis rotation
//!    with respect to the rotation angle. For example, the transformation
//!
//!  
//!
//! ```text
//!    [ANGLE]
//!           1
//! ```
//!
//!  which has the matrix representation
//!
//!  
//!
//! ```text
//!    +-                             -+
//!    |  1         0           0      |
//!    |  0    cos(ANGLE)  sin(ANGLE)  |
//!    |  0   -sin(ANGLE)  cos(ANGLE)  |
//!    +-                             -+
//! ```
//!
//!  yields, when differentiated with respect to ANGLE, the matrix
//!
//!  
//!
//! ```text
//!    +-                             -+
//!    |  0         0           0      |
//!    |  0   -sin(ANGLE)  cos(ANGLE)  |
//!    |  0   -cos(ANGLE) -sin(ANGLE)  |
//!    +-                             -+
//! ```
//!
//!  The routine [DROTAT](crate::raw::drotat) is useful for differentiating rotations that are
//!    defined by time-varying Euler angles. For example, if the rotation R is
//!    defined by
//!
//!  
//!
//! ```text
//!    R = [ Twist ]    [ pi/2 - Dec ]    [ pi/2 + RA ]
//!                 3                 1                3
//! ```
//!
//!  where RA, Dec, and Twist are time-dependent, then if we make the
//!    abbreviations
//!
//!  
//!
//! ```text
//!    A(Twist) = [ Twist ]
//!                        3
//!  
//!    B(Dec)   = [ pi/2 - Dec ]
//!                             1
//!  
//!    C(RA)    = [ pi/2 + RA ]
//!                            3
//! ```
//!
//!  we can write
//!
//!  
//!
//! ```text
//!    d(R)            d(A)     d(Twist)
//!    ----  =       -------- * --------       *     B     *      C
//!     dt           d(Twist)      dt
//!  
//!                                      d(B)    - d(Dec)
//!              +       A    *         ------ * --------  *      C
//!                                     d(Dec)      dt
//!  
//!                                                  d(C)     d(RA)
//!              +       A    *        B       *     ----- * -------
//!                                                  d(RA)      dt
//! ```
//!
//!  The derivatives of A, B, and C can be found using [DROTAT](crate::raw::drotat).
//!
//!  
//!
//!
//!  
//! ###  State transformations
//!
//!  Transforming state vectors between inertial and non-inertial coordinates
//!    requires the derivative of the rotation that relates the two frames: Let
//!
//!  
//!
//! ```text
//!    P (t)
//!     I
//! ```
//!
//!  be a position vector referenced to an inertial frame "I," and let
//!
//!  
//!
//! ```text
//!    P (t)
//!     N
//! ```
//!
//!  be the equivalent position vector referenced to a non-inertial frame
//!    "N." If R(t) is the transformation from frame I to N at time t, then
//!    the two vectors are related as follows:
//!
//!  
//!
//! ```text
//!    P (t)  =  R(t) P (t)
//!     N              I
//! ```
//!
//!  Therefore, the derivatives of the position vectors satisfy
//!
//!  
//!
//! ```text
//!    d [ P (t) ]               d [ P (t) ]
//!         N                         I              d [ R(t) ]
//!    -----------   =   R(t) *  -----------    +    ----------  *  P (t)
//!        dt                        dt                  dt          I
//! ```
//!
//!  It's well to note that although R(t) may vary slowly, the second term in
//!    the above equation is not necessarily insignificant. For example, if
//!    R(t) describes a transformation between an inertial frame and a
//!    body-centered frame that uses a body-center-to-Sun vector to define one
//!    of its coordinate axes, then for any point that is fixed on this axis,
//!    the two addends above have equal and opposite magnitude. In particular,
//!    if the fixed point is the location of the Sun, the magnitude of the
//!    second addend is (ignoring the velocity of the Sun with respect to the
//!    inertial frame) that of the inertially referenced velocity of the body
//!    used to define the body-centered frame.
//!
//!  SPICELIB provides routines to transform states between inertial frames
//!    and body-fixed planetocentric frames. The routine [TISBOD](crate::raw::tisbod) returns the 6x6
//!    transformation matrix required to transform inertially referenced state
//!    vectors to body-fixed planetocentric coordinates. If REF is the name of
//!    the inertial frame of interest, BODY is the NAIF integer code of a body
//!    defining a body-fixed planetocentric frame, and ET is ephemeris time
//!    used to define the body-fixed frame, then the call
//!
//!  
//!
//! ```text
//!    CALL TISBOD ( REF, BODY, ET, TSIPM )
//! ```
//!
//!  returns TSIPM, the desired 6x6 state transformation matrix. A state
//!    vector S can be transformed to the body-fixed state vector SBFIXD by the
//!    routine call
//!
//!  
//!
//! ```text
//!    CALL MXVG ( TSIPM, S, 6, 6, SBFIXD )
//! ```
//!
//!  Since the inverse of a state transformation matrix is not simply its
//!    transpose, SPICELIB provides the utility routine [INVSTM](crate::raw::invstm) to perform the
//!    inversion. If M is a state transformation matrix, the inverse matrix
//!    MINV can be obtained via the routine call
//!
//!  
//!
//! ```text
//!    CALL INVSTM ( M, MINV )
//! ```
//!
//!     
//! ##  Validating a rotation matrix
//!
//!  [ISROT](crate::raw::isrot) is a logical function that indicates whether a matrix is a valid
//!    rotation matrix. The criteria for validity are:
//!
//!  
//!
//! * The columns of the matrix are unit vectors, within a specified tolerance.
//!
//!  * The determinant of the matrix formed by unitizing the columns of the input
//! matrix is 1, within a specified tolerance. This criterion ensures that the
//! columns of the matrix are nearly orthogonal, and that they form a
//! right-handed basis.
//!
//!  We might use [ISROT](crate::raw::isrot) as follows:
//!
//!  
//!
//! ```text
//!    C
//!    C     Set values for the column norm and determinant tolerances
//!    C     NTOL and DTOL:
//!    C
//!          NTOL = 1.D-7
//!          DTOL = 1.D-7
//!  
//!          IF (  .NOT.  ISROT ( M, NTOL, DTOL )   ) THEN
//!  
//!             [perform error handling]
//!  
//!          ELSE
//!  
//!             CALL M2Q ( M, Q )
//!                  .
//!                  .
//!                  .
//!          END IF
//! ```
//!
//!     
//! #  Tutorial introduction to rotations
//!
//!  This tutorial is intended to bridge the gap between knowing linear
//!    algebra and understanding rotations. If you haven't reached the gap yet,
//!    consult reference \[2], or any reasonable textbook on the subject.
//!
//!  In this section, we make some assertions that we don't prove. Our goal
//!    is to supply you with the most important information first, and fill in
//!    the details later. Proofs are supplied only when they're instructive and
//!    not too distracting. The longer or more difficult proofs are deferred to
//!    the "Mathematical road map" chapter.
//!
//!  
//!
//!
//!  
//! ##  A comment of the heuristic variety
//!
//!  If you're going to read the rest of this tutorial, you're going to see a
//!    lot of definitions, symbol manipulation, and proofs. This information
//!    may be more accessible if you have some kind of reasonable mental model
//!    of rotations; then you can test our claims against your model.
//!
//!  We offer the following model: Take a soccer ball, put two fingers on
//!    diametrically opposed points on the ball, and rotate the ball through
//!    some angle, keeping your fingers in place. What you use to rotate the
//!    ball is up to you.
//!
//!  Well, that's it. That's the effect of a rotation on a soccer ball. Now
//!    you're equipped to answer some questions about rotations. Do rotations
//!    preserve inner products of vectors? That is, is it true that for vectors
//!    u and v, and a rotation R,
//!
//!  
//!
//! ```text
//!    < R u,  R v >  =  < u, v > ?
//! ```
//!
//!  Well, presume that your soccer ball is centered at the origin, and mark
//!    the ball where u and v, or extensions of them, intercept the surface
//!    (perhaps you could hold a marker pen between your teeth). Does rotating
//!    the ball change the angular separation of the marks? No. So rotations
//!    preserve angular separation. Does rotating the ball change the norm of u
//!    or of v? No. So rotations preserve both angular separation and norms,
//!    and hence inner products.
//!
//!  Do rotations preserve cross products? For vectors u and v, is it true
//!    that
//!
//!  
//!
//! ```text
//!    ( R u )  x  ( R v )  =  R ( u x v )?
//! ```
//!
//!  Mark the intercepts of u, v, and u x v on the soccer ball. After you
//!    rotate the ball, does the intercept mark of u x v still lie at the right
//!    place, relative to the u and v intercept marks? Yes. Since we already
//!    know that rotations preserve norms, we can conclude that they preserve
//!    cross products as well.
//!
//!  The soccer ball model shows that rotations preserve geometrical
//!    relationships between vectors.
//!
//!  
//!
//!
//!  
//! ##  Definition of "rotation"
//!
//!  Actually, we present three definitions of the term "rotation." What
//!    for? Having more than one way of knowing that a mapping is a rotation
//!    makes it easier to check whether any particular mapping is a rotation or
//!    not. Some properties of rotations are easier to derive from one
//!    definition than from another.
//!
//!  
//!
//!
//!  
//! ###  Definition 1
//!
//!  A "rotation" R is a linear transformation defined on E3 that has the
//!    following properties:
//!
//!  
//!
//! * R preserves norms: if v is a vector, then
//!
//!  ```text
//!    || R(v) ||  =  ||v||
//! ```
//!  * R preserves cross products: if a and b are vectors, then
//!
//!  ```text
//!    R ( a x b )  =  ( R a )  x  ( R b ).
//! ```
//!     
//! ###  Definition 2
//!
//!  A "rotation' R is a mapping defined on E3 that satisfies definition
//!    (1), and also has the property:
//!
//!  
//!
//! * R keeps some vector (called the rotation axis) fixed. That is, if n is the
//! rotation axis, then
//!
//!  ```text
//!    R(n) = n.
//! ```
//!  *  Since R is linear, the entire line containing n is fixed.
//!
//!     
//! ###  Definition 3
//!
//!  A rotation R is a linear mapping defined on E3 that has the following
//!    properties:
//!
//!  
//!
//! * R preserves distances on the unit sphere.
//!
//!  * R keeps exactly two points on the unit sphere fixed, or else R is the
//! identity.
//!
//!  *  This property rules out the possibility that R is a "reflection."
//!
//!     
//! ###  Uses of the definitions
//!
//!  Definition (1) is useful for checking that a mapping is a rotation,
//!    because there's not much to check.
//!
//!  Definition (2) obviously implies definition (1). Less obviously,
//!    definition (1) implies definition (2). This had better be true if
//!    definition (1) is valid, since we expect rotations to have rotation
//!    axes. In the "Mathematical road map" chapter, we prove that the two
//!    definitions are equivalent.
//!
//!  Definition (3) is a mathematical paraphrase of our soccer ball model of
//!    rotations.
//!
//!  
//!
//!
//!  
//! ##  Definition of "rotation" and "orthogonal" matrix
//!
//!  A "rotation matrix" M is a 3 by 3 matrix whose columns form an
//!    orthonormal set, and whose third column is the cross product of the
//!    first two. Given a rotation R and an orthonormal basis B, the matrix
//!    representation of R relative to B is a rotation matrix.
//!
//!  Any matrix whose columns form an orthonormal set is called an
//!    "orthogonal" matrix.
//!
//!  
//!
//!
//!  
//! ##  Rotations preserve inner products
//!
//!  This section is for those who do not feel comfortable with soccer ball
//!    arguments.
//!
//!  Our definition of "rotation" says that rotations preserve norms of
//!    vectors. That is, if R is a rotation and v is a vector, then
//!
//!  
//!
//! ```text
//!    || R(v) ||  =  || v ||.
//! ```
//!
//!  Preserving norms also implies the seemingly stronger property of
//!    preserving inner products: if R preserves norms and u, v are vectors,
//!    then
//!
//!  
//!
//! ```text
//!                       2               2
//!    ||  R ( u - v )  ||  =  || u - v ||
//!  
//!  
//!                         =  < u - v,  u - v >
//!  
//!                                   2                        2
//!                         =  || u ||  - 2 < u, v >  + || v ||,
//! ```
//!
//!  and also
//!
//!  
//!
//! ```text
//!                       2
//!    ||  R ( u - v )  ||  =  < R ( u - v ),  R ( u - v ) >
//!  
//!  
//!                         =  < R(u) - R(v),  R(u) - R(v) >
//!  
//!                                      2               2
//!                         =  || R(u) ||   +  || R(v) ||
//!  
//!                                        -  2 < R u, R v >
//!  
//!                                   2             2
//!                         =  || u ||   +   || v ||
//!  
//!                                        -  2 < R u, R v >
//! ```
//!
//!  so
//!
//!  
//!
//! ```text
//!    < R(u), R(v) >       =   < u, v >.
//! ```
//!
//!  So rotations really do preserve inner products. In particular, for any
//!    orthonormal basis, the images of the basis vectors under a rotation are
//!    also an orthonormal set. Then rotation matrices, expressed relative to
//!    an orthonormal basis, are in fact orthogonal, as claimed.
//!
//!  
//!
//!
//!  
//! ##  Inverses of rotation matrices
//!
//!  We've seen that the columns of a rotation matrix R form an orthonormal
//!    set. Since the (i,j) entry of
//!
//!  
//!
//! ```text
//!     T
//!    R  R
//! ```
//!
//!  is the inner product of the ith column of R and the jth column of R, all
//!    entries of the product are zero except for those on the main diagonal,
//!    and the entries on the main diagonal are all 1. So
//!
//!  
//!
//! ```text
//!     T
//!    R  R  =  I.
//! ```
//!
//!  If A and B are square matrices with real or complex entries, it's a fact
//!    that if
//!
//!  
//!
//! ```text
//!    A B = I
//! ```
//!
//!  then
//!
//!  
//!
//! ```text
//!    B A = I.
//! ```
//!
//!  We won't prove this (the "Nullity and Rank" theorem is useful, if you
//!    wish to do so). But this result implies that
//!
//!  
//!
//! ```text
//!       T
//!    R R  = I,
//! ```
//!
//!  given the previous result.
//!
//!  This shows that the rows of R form an orthonormal set as well, and that
//!    the transpose of R is also a rotation matrix.
//!
//!  
//!
//!
//!  
//! ##  Composition of rotations
//!
//!  If we multiply a sequence of rotation matrices, is the result a rotation
//!    matrix? Equivalently, if we compose a sequence of rotations, is the
//!    resulting mapping a rotation?
//!
//!  What does our soccer ball model say? We can rotate the ball as many
//!    times as we like, changing the rotation axis each time, without changing
//!    the distance of any surface point from the center, so norms are
//!    preserved. Similarly, after marking the intercepts of u, v, and u x v on
//!    the surface, we can perform any sequence of rotations without changing
//!    the position of the u x v intercept mark relative to those of u and v.
//!    So cross products are preserved. That's all we need to verify that the
//!    composition of a sequence of rotations is a rotation. It follows that
//!    the product of a sequence of rotation matrices is a rotation matrix.
//!
//!  If you don't agree that that's all we need, we can present the same
//!    argument using the usual symbols:
//!
//!  Suppose R1 and R2 are rotation mappings, and for any vector v,
//!
//!  
//!
//! ```text
//!    R3(v) = R2 ( R1(v) ).
//! ```
//!
//!  Then for any vector v, we have
//!
//!  
//!
//! ```text
//!    || R3(v) ||  =  || R2 ( R1 v ) ||
//!  
//!                 =  || R1( v ) ||
//!  
//!                 =  || v ||.
//! ```
//!
//!  So R3 preserves norms.
//!
//!  If u and v are vectors, then
//!
//!  
//!
//! ```text
//!    R3 ( u x v ) =  R2 ( R1 ( u x v )  )
//!  
//!                 =  R2 ( R1(u)  x  R1(v) )
//!  
//!                 =  (  R2 ( R1(u) )   x   R2 ( R1(v) )  )
//!  
//!                 =  R3(u)  x  R3(v),
//! ```
//!
//!  so R3 preserves cross products. We've used only the definition of R3 and
//!    the fact that R2 and R1 preserve cross products in this proof.
//!
//!  We conclude that R3 is a rotation. We can extend the result to the
//!    product of a finite number of rotations by mathematical induction; the
//!    argument we've made is almost identical to the induction step.
//!
//!  
//!
//!
//!  
//! ##  Coordinate transformations
//!
//!  Change-of-basis transformations between right-handed, orthonormal bases
//!    are rotations. You can verify this using our first definition of
//!    rotations. In particular, the inertial coordinate system transformations
//!    available in SPICELIB are all rotations.
//!
//!  How do we transform a vector v from one coordinate system to another?
//!    This result really belongs to linear algebra, but we'll state it here
//!    because it seems to come up a lot.
//!
//!  Given two vector space bases,
//!
//!  
//!
//! ```text
//!    B1 = { e1, e2, e3 },   B2 = { u1, u2, u3 },
//! ```
//!
//!  and a vector v that has components ( v1, v2, v3 ) relative to B1, we
//!    wish to express v relative to B2. We can say that
//!
//!  
//!
//! ```text
//!    v  =  x1 u1 +  x2 u2  +  x3 u3,
//! ```
//!
//!  where the x's are unknowns. Let M be the matrix whose columns are u1,
//!    u2, and u3, represented relative to basis B1. M represents the linear
//!    transformation T defined by
//!
//!  
//!
//! ```text
//!    T  (e1) = u1, T(e2) = u2, T(e3) = u3.
//! ```
//!
//!  Then since
//!
//!  
//!
//! ```text
//!     -1         -1
//!    T  (v)  =  T  ( x1 u1 +  x2 u2  +  x3 u3 )
//!  
//!            =     ( x1 e1 +  x2 e2  +  x3 e3 ),
//! ```
//!
//!  we see that
//!
//!  
//!
//! ```text
//!     -1
//!    M  v  = ( x1, x2, x3 ).
//! ```
//!
//!  So we've found the components of v, relative to basis B2.
//!
//!  In the case where B1 and B2 are orthonormal bases, the matrix M is
//!    orthogonal. So we have
//!
//!  
//!
//! ```text
//!     T
//!    M  v  = ( x1, x2, x3 ).
//! ```
//!
//!  Conversely, if M is the matrix that transforms vectors from orthonormal
//!    basis B1 to orthonormal basis B2, then the rows of M are the basis
//!    vectors of B2.
//!
//!  For example, if M is the matrix that transforms vectors from J2000
//!    coordinates to body equator and prime meridian coordinates, then the
//!    first row is the vector, expressed in J2000 coordinates, that points
//!    from the body center to the intersection of the prime meridian and body
//!    equator. The third row is the vector, expressed in J2000 coordinates,
//!    that points from the body center toward the body's north pole.
//!
//!  
//!
//!
//!  
//! ##  Rotation of vectors in the plane
//!
//!  How do we rotate a two-dimensional vector v by theta radians? Trivial as
//!    this problem may seem, it's probably worth your while to get a firm grip
//!    on its solution. When you've understood it, you've almost understood
//!    three-dimensional rotations.
//!
//!  We can assume that v is a unit vector; since rotations are linear, it's
//!    easy to extend the result to vectors of any length.
//!
//!  Now, if v is (1,0), the result of the rotation will be
//!
//!  
//!
//! ```text
//!    ( cos(theta),  sin(theta) ).
//! ```
//!
//!  How does this help us if v is an arbitrary unit vector? Given a unit
//!    vector v, let v' be the vector perpendicular to v, obtained by rotating
//!    v by pi/2. Now v and v' form an orthonormal basis, and relative to this
//!    basis, v has coordinates (1,0). But we've already found out what we get
//!    by rotating v by theta radians: relative to our new basis, the result
//!    must be
//!
//!  
//!
//! ```text
//!    ( cos(theta), sin(theta) ).
//! ```
//!
//!  Relative to our original basis, this vector is
//!
//!  
//!
//! ```text
//!    cos(theta) v  +  sin(theta) v'
//! ```
//!
//!  This is the result we're looking for: "If you rotate a vector v by
//!    theta radians, you end up with cos(theta) v plus sin(theta) v'," where
//!    v' is v, rotated by pi/2.
//!
//!  Scaling v does not affect this result.
//!
//!  A consequence of this result is that the mapping R that rotates vectors
//!    by theta radians is represented by the matrix
//!
//!  
//!
//! ```text
//!    +-                        -+
//!    |  cos(theta)  -sin(theta) |
//!    |                          |.
//!    |  sin(theta)   cos(theta) |
//!    +-                        -+
//! ```
//!
//!  It is useful to note that R has this exact representation relative to
//!    any orthonormal basis where the second vector is obtained from the first
//!    by a rotation of pi/2.
//!
//!  
//!
//!
//!  
//! ##  A canonical representation for rotations
//!
//!  Suppose we have a rotation R, defined in three-dimensional space, that
//!    rotates vectors by angle theta about unit vector n. For an arbitrary
//!    vector r, we can break r up into two orthogonal components: one parallel
//!    to n and one perpendicular to n. We can call these components rParallel
//!    and rPerp.
//!
//!  The two-dimensional diagram below shows this decomposition. All of the
//!    vectors lie in the plane containing r and n.
//!
//!  
//!
//! ```text
//!                 \           . rParallel
//!                  \          .
//!                   \         .
//!                 r  \        .
//!                     \       .
//!                      \      .
//!                       \     .
//!                        \    ^
//!                         \   |
//!                          \  |  n
//!                           \ |
//!                  ..........\|
//!                 rPerp
//! ```
//!
//!  Now, what does R do to vectors that are perpendicular to n? Since R
//!    rotates each vector about n, if a vector v is perpendicular to n, then
//!    R(v) is perpendicular to n as well (remember that rotations preserve
//!    inner products, and orthogonality in particular). So rPerp just gets
//!    rotated in the plane perpendicular to n. We know from the last section
//!    how to find R(rPerp): if we let rPerp' be the vector obtained by
//!    rotating rPerp by pi/2 about n, then
//!
//!  
//!
//! ```text
//!    R(rPerp) = cos(theta) rPerp  +  sin(theta) rPerp'
//! ```
//!
//!  We will also want to know what R(rPerp') is. Since rotating rPerp' by
//!    pi/2 about n yields -rPerp, applying our familiar formula to rPerp'
//!    gives us
//!
//!  
//!
//! ```text
//!    R(rPerp') = cos(theta) rPerp'  -  sin(theta) rPerp.
//! ```
//!
//!  Now, since n, rPerp, and rPerp' are mutually orthogonal, these vectors
//!    form a basis. Since we can scale r so that rPerp has norm 1, and since
//!    rPerp' has the same norm as rPerp, we may assume that the basis is
//!    actually orthonormal.
//!
//!  The matrix of R relative to this basis is
//!
//!  
//!
//! ```text
//!    +-                              -+
//!    |  1         0            0      |
//!    |                                |
//!    |  0     cos(theta)  -sin(theta) |.
//!    |                                |
//!    |  0     sin(theta)   cos(theta) |
//!    +-                              -+
//! ```
//!
//!  Since the rotation we're representing is arbitrary, we've shown that
//!    every rotation can be represented by a matrix of the above form.
//!    Equivalently, every rotation matrix is similar to one of the above form.
//!    This fact justifies the use of the term "canonical form."
//!
//!  The canonical form we've found shows why three-dimensional rotations are
//!    very much like two-dimensional rotations: The effect of a
//!    three-dimensional rotation on any vector is to rotate the component of
//!    that vector that is normal to the rotation axis, and leave the component
//!    parallel to the rotation axis fixed.
//!
//!  This rotation matrix is a useful "model" to keep in mind when dealing
//!    with rotations because of its particularly simple form. It's easy to
//!    read off some types of information directly from this matrix.
//!
//!  Some examples:
//!
//!  
//!
//! * The trace of the above matrix is 1 + 2 cos(theta). Since the trace of a
//! matrix is invariant under similarity transformations, every rotation matrix
//! has trace equal to 1 + 2 cos(theta). So we can easily find the rotation
//! angle of any rotation matrix.
//!
//!  * Every rotation has 1 as one of its eigenvalues. We already knew that, but
//! there it is, sitting alone in its one-dimensional diagonal block. The other
//! eigenvalues are complex unless the rotation angle is a multiple of pi.
//!
//!  * Every rotation is an orthogonal mapping, that is, orthogonal vectors map to
//! orthogonal vectors. This has to be true because the canonical form is an
//! orthogonal matrix, represented relative to an orthonormal basis.
//!
//!     
//! ##  Rotation axis and angle
//!
//!  Our soccer ball model shows that a rotation has a fixed vector, called
//!    the "axis." Now if the vector n is fixed by R, then -n is fixed as
//!    well, so the direction of the rotation axis is not unique.
//!
//!  Given a rotation R and a vector v, normal to the rotation axis n of R,
//!    the angle between v and R(v), measured counterclockwise around n, is the
//!    rotation angle of R. We see that the rotation angle depends on the
//!    direction of the axis: if we pick -n as the axis, we change the sign of
//!    the angle.
//!
//!  Note that while the rotation axis and angle of a rotation are not
//!    uniquely defined, a choice of axis and angle do determine a unique
//!    rotation.
//!
//!  How do we find the rotation matrix R that rotates vectors by angle theta
//!    about the unit vector n? If n is
//!
//!  
//!
//! ```text
//!    n = (n1, n2, n3),
//! ```
//!
//!  then
//!
//!  
//!
//! ```text
//!                                       2
//!    R  =   I   +   ( 1 - cos(theta) ) N   +   sin(theta) N,
//! ```
//!
//!  where
//!
//!  
//!
//! ```text
//!        +-             -+
//!        |  0   -n3   n2 |
//!        |               |
//!    N = |  n3   0   -n1 |.
//!        |               |
//!        | -n2   n1   0  |
//!        +-             -+
//! ```
//!
//!  How do we recover the rotation angle and axis of a rotation R from a
//!    corresponding rotation matrix, M?
//!
//!  We've already seen in the "canonical form" section that the rotation
//!    angle is
//!
//!  
//!
//! ```text
//!    ACOS (  ( Trace(M) - 1 ) / 2  ).
//! ```
//!
//!  If the rotation angle is not zero or pi, then the relation
//!
//!  
//!
//! ```text
//!         T
//!    M - M  = 2 sin(theta) N
//! ```
//!
//!  allows us to recover the rotation axis n from M, while if the rotation
//!    angle is pi, we have
//!
//!  
//!
//! ```text
//!               2
//!    M = I + 2 N,
//! ```
//!
//!  again determining n.
//!
//!  In the "Mathematical road map" chapter, we'll verify these assertions.
//!
//!  
//!
//!
//!  
//! ##  Time-dependent coordinate transformations
//!
//!  Suppose we have two bases, B1 and B2, where the elements of B2,
//!    expressed relative to B1, are time dependent:
//!
//!  
//!
//! ```text
//!    B2 = { v1(t), v2(t), v3(t) }.
//! ```
//!
//!  An example of a time-dependent coordinate transformation is the
//!    transformation from J2000 to body equator and prime meridian
//!    coordinates.
//!
//!  If R(t) transforms vectors from basis B1 to basis B2, the basis vectors
//!    of B2 are the rows of the matrix R(t).
//!
//!  Let p(t) and p'(t) be position and velocity vectors expressed relative
//!    to B1. What is the corresponding velocity, expressed relative to B2? We
//!    know that p(t) has coordinates
//!
//!  
//!
//! ```text
//!    R(t) p(t)
//! ```
//!
//!  relative to B2, so the time derivative of R(p(t)) is
//!
//!  
//!
//! ```text
//!    R(t) p'(t)  +  R'(t) p(t),
//! ```
//!
//!  relative to B2.
//!
//!  If R(t) is expressed as a product of the form
//!
//!  
//!
//! ```text
//!    R(t) = [ w1(t) ]   [ w2(t) ]   [ w3(t) ] ,
//!                    i           j           k
//! ```
//!
//!  then
//!
//!  
//!
//! ```text
//!    R'(t)  =     [ w1(t) ]'  [ w2(t) ]   [ w3(t) ]
//!                          i           j           k
//!  
//!              +  [ w1(t) ]   [ w2(t) ]'  [ w3(t) ]
//!                          i           j           k
//!  
//!              +  [ w1(t) ]   [ w2(t) ]   [ w3(t) ]'
//!                          i           j           k
//! ```
//!
//!  Since we know the explicit form of the factors (given in the
//!    "Notation" section), we can compute R'(t).
//!
//!  We must take care when converting velocity vectors between systems whose
//!    bases are related in a time-dependent way. If R(t) varies extremely
//!    slowly, it is tempting to ignore the R' term, and in fact this is a
//!    valid approximation in some cases. However, since the magnitude of this
//!    term is proportional to the magnitude of p, the term can be large when R
//!    is quite slowly varying. An example:
//!
//!  Let B1 be the basis vectors of the J2000 system, and let
//!
//!  
//!
//! ```text
//!    B2  =  { v1(t), v2(t), v3(t) }
//! ```
//!
//!  be defined as follows: v1(t) is the geometric Jupiter-Sun vector at
//!    ephemeris time t, v3(t) is orthogonal to v1(t) and lies in the plane
//!    containing v1(t) and Jupiter's pole at time t, and v2(t) is the cross
//!    product of v3(t) and v1(t).
//!
//!  Let R(t) be the transformation matrix from basis B1 to B2. Then the
//!    period of R(t) is 1 Jovian year (we're ignoring movement of Jupiter's
//!    pole). Now if p(t) is the Jupiter-Sun vector in J2000 coordinates, then
//!    p'(t) is the negative of Jupiter's velocity in J2000 coordinates. But in
//!    B2 coordinates, R(t) ( p(t) ) always lies along the x-axis, and if we
//!    approximate Jupiter's motion as a circle, then R(p(t))' is the zero
//!    vector. So we have the equation
//!
//!  
//!
//! ```text
//!    R(t) p'(t)  +  R'(t) p(t)  =  [ R(t)( p(t) ) ]'  =  0,
//! ```
//!
//!  which implies
//!
//!  
//!
//! ```text
//!    R'(t)p(t)   =   - R(t) p'(t).
//! ```
//!
//!  So in this case, the term involving R' has the same magnitude as the
//!    term involving R, even though R is slowly varying.
//!
//!  
//!
//!
//!  
//! ##  Euler angles
//!
//!  Given a rotation matrix M (usually representing a coordinate
//!    transformation), we occasionally have the need to express it as the
//!    product
//!
//!  
//!
//! ```text
//!    M  =  [w1]    [w2]    [w3]  .
//!              i1      i2      i3
//! ```
//!
//!  The angles w1, w2, and w3 are called "Euler angles."
//!
//!  It is not necessarily obvious that this "factorization" is possible.
//!    It turns out that as long as i2 does not equal i1 or i3, it is possible,
//!    for any rotation matrix M. In the "Mathematical road map" chapter, we
//!    exhibit the formulas for calculating w1, w2, and w3, given M and i1, i2,
//!    and i3.
//!
//!  
//!
//!
//!  
//! ##  Quaternions
//!
//!  Quaternions are four dimensional vectors, on which a particular kind of
//!    arithmetic is defined. The quaternions that have norm equal to 1 are
//!    called "unit quaternions."
//!
//!  Unit quaternions may be associated with rotations in the following way:
//!    if a rotation R has unit vector n = (n1, n2, n3) as an axis and w as a
//!    rotation angle, then we represent R by
//!
//!  
//!
//! ```text
//!    Q = ( cos(w/2),  sin(w/2) n1,  sin(w/2) n2,  sin(w/2) n3 ).
//! ```
//!
//!  As you might suspect, this association is not unique: substituting (w +
//!    2*pi) for w, we see that -Q is also a representation for R.
//!
//!  If we choose the rotation axis and angle of R so that the angle lies in
//!    \[0, pi], then there is a unique quaternion representing R, except in the
//!    case where R is a rotation by pi radians.
//!
//!  
//!
//!
//!  
//! ##  Quaternion arithmetic
//!
//!  SPICELIB does not currently contain any routines that make use of
//!    quaternion arithmetic. Eventually, SPICELIB may use quaternion
//!    multiplication to compose rotations, since quaternion arithmetic is more
//!    efficient than matrix multiplication. At present, this section is merely
//!    for the curious.
//!
//!  
//!
//!
//!  
//! ###  Definitions
//!
//!  There are two binary operations defined on quaternions: addition and
//!    multiplication.
//!
//!  The main interest of quaternion multiplication is that we can actually
//!    carry out composition of rotations using the multiplication defined on
//!    the quaternions. If quaternions Q1 and Q2 represent rotations R1 and R2,
//!    then Q2*Q1 represents R2(R1). So the mapping from unit quaternions to
//!    rotations is a group homomorphism, where the "multiplication"
//!    operation on the rotations is functional composition.
//!
//!  Quaternion addition is simple vector addition. Multiplication is a
//!    little more complicated. Before defining it, we're going to introduce a
//!    new notation for quaternions that makes it easier to deal with products.
//!
//!  The quaternion
//!
//!  
//!
//! ```text
//!    Q = ( Q0, Q1, Q2, Q3 )
//! ```
//!
//!  can be represented as
//!
//!  
//!
//! ```text
//!    Q0 + ( Q1, Q2, Q3 ),
//! ```
//!
//!  or
//!
//!  
//!
//! ```text
//!    s + v,
//! ```
//!
//!  where s represents the "scalar" Q0 and v represents the "vector"
//!
//!  
//!
//! ```text
//!    ( Q1, Q2, Q3 ).
//! ```
//!
//!  We define the "conjugate" of the quaternion
//!
//!  
//!
//! ```text
//!    q = s + v
//! ```
//!
//!  as
//!
//!  
//!
//! ```text
//!     *
//!    q  = s - v.
//! ```
//!
//!  Given two quaternions,
//!
//!  
//!
//! ```text
//!    q1 = s1 + v1,  q2 = s2 + v2,
//! ```
//!
//!  we define the product q1 * q2 as
//!
//!  
//!
//! ```text
//!    ( s1 * s2 - < v1, v2 > )  +  ( s1 * v2  +  s2 * v1  +  v1 x v2 ).
//! ```
//!
//!  We've grouped the "scalar" and "vector" portions of the product.
//!
//!  
//!
//!
//!  
//! ###  Basic properties of multiplication
//!
//!  Let's check out a few of the properties of the multiplication formula.
//!
//!  Is multiplication commutative? No; if s1 and s2 above are zero, then the
//!    product is
//!
//!  
//!
//! ```text
//!    - < v1, v2 >   +   v1 x v2,
//! ```
//!
//!  which is not commutative. However, multiplication is associative: given
//!    three quaternions q1, q2, and q3, we have
//!
//!  
//!
//! ```text
//!    q3 * ( q2 * q1 ) = ( q3 * q2 ) * q1.
//! ```
//!
//!  We'll forgo checking this; it's messy but straightforward. If you do
//!    check it, the vector identities
//!
//!  
//!
//! ```text
//!     A x ( B x C ) =  < A, C > B  -  < A, B > C
//!  
//!    ( A x B ) x C  =  < C, A > B  -  < C, B > A
//! ```
//!
//!  will be useful.
//!
//!  What's the product of q and its conjugate? It comes out to
//!
//!  
//!
//! ```text
//!           2
//!    || q ||.
//! ```
//!
//!  What's the conjugate of the product
//!
//!  
//!
//! ```text
//!    q1 * q2,
//! ```
//!
//!  where q1 and q2 are as defined above? The product formula allows us to
//!    verify that the answer is
//!
//!  
//!
//! ```text
//!      *     *
//!    q2  * q1.
//! ```
//!
//!     
//! ###  Deducing the multiplication formula
//!
//!  One really interesting fact about the product formula is that it is a
//!    sum of binary operations, each of which is linear (where the
//!    coefficients are scalars, not quaternions) in both operands. This
//!    implies that the product formula itself is linear in q1 and q2.
//!
//!  You can check this: if we scale q1 by x, the product gets scaled by x.
//!    The same thing happens if we scale q2. If we replace q1 by the sum of
//!    two quaternions, say
//!
//!  
//!
//! ```text
//!    q1 = q + q' =  ( s + s' )  +  ( v + v' ),
//! ```
//!
//!  the product is
//!
//!  
//!
//! ```text
//!    q * q2   +   q' * q2.
//! ```
//!
//!  The analogous result occurs when we replace q2 by a sum of two
//!    quaternions.
//!
//!  Because of this linearity property, we can define multiplication on a
//!    small set of quaternions, and then define multiplication on the whole
//!    set of quaternions by insisting that the multiplication operator is
//!    linear in both operands. This gives us an equivalent definition of
//!    multiplication.
//!
//!  To carry out this definition, we first define multiplication on the four
//!    quaternions
//!
//!  
//!
//! ```text
//!    1 + ( 0, 0, 0 ), which we call ``1,''
//!    0 + ( 1, 0, 0 ), which we call ``i,''
//!    0 + ( 0, 1, 0 ), which we call ``j,''
//!    0 + ( 0, 0, 1 ), which we call ``k.''
//! ```
//!
//!  We treat "1" as a scalar and i, j, and k as vectors, and define the
//!    products
//!
//!  
//!
//! ```text
//!    1 * v   = v,  for v = i, j, k;
//!  
//!    v * v   = -1,  for v = i, j, k;
//!  
//!    v1 * v2 = - v2 * v1, for v1, v2 = i, j, k;
//!  
//!    i * j   = k;
//!    j * k   = i;
//!    k * i   = j.
//! ```
//!
//!  Multiplication of i, j, and k works just like taking cross products.
//!
//!  If we now proclaim that multiplication is linear in both operands, then
//!    since all quaternions can be expressed as linear combinations of "1,"
//!    i, j, and k, we've defined multiplication on the entire set of
//!    quaternions. You can check that this definition of multiplication is
//!    consistent with our formula above.
//!
//!  
//!
//!
//!  
//! ###  Composing rotations using quaternions
//!
//!  There is one last assertion to check: we've said that you can carry out
//!    composition of rotations using quaternion multiplication. Let's examine
//!    what that means:
//!
//!  We've defined a mapping from quaternions to rotations, since the
//!    relation
//!
//!  
//!
//! ```text
//!    Q = ( cos(w/2),  sin(w/2) n1,  sin(w/2) n2,  sin(w/2) n3 )
//! ```
//!
//!  allows us to recover w and the axis ( n1, n2, n3 ), hence the
//!    corresponding rotation. Now suppose we have two quaternions Q1 and Q2
//!    that represent rotations R1 and R2, respectively. We're claiming that
//!    the product Q2 * Q1 represents R2(R1). So, we should be able to recover
//!    the rotation axis and angle of R2(R1) from the quaternion Q2 * Q1. In
//!    the "Mathematical road map' chapter, we will verify this claim.
//!
//!  
//!
//!
//!  
//! #  Mathematical road map
//!
//!  The purpose of this chapter is to familiarize you with the mathematical
//!    ideas essential to dealing with rotations. If you understand the
//!    relevant mathematics, you are in a position to judge the merits of
//!    alternative software designs based on SPICELIB routines. If you don't
//!    understand the mathematics, you can still build programs that work by
//!    paying careful attention to routine interface specifications, but the
//!    design process is more error-prone, and you're unlikely to hit upon
//!    efficient and elegant solutions.
//!
//!  The difference between the two perspectives is a bit like the difference
//!    between having a set of directions to get from point A to point B, and
//!    having a road map of the entire area.
//!
//!  This chapter is not organized sequentially, since there is little
//!    logical dependence of one section on another. It is simply a collection
//!    of discussions.
//!
//!  
//!
//!
//!  
//! ##  Rotation of a vector about an axis
//!
//!  Suppose we have a unit vector n, and we wish to rotate a vector r about
//!    n by an angle of theta radians. What's the resulting vector?
//!
//!  As in the tutorial discussion of the canonical form for rotations, we
//!    can express r as the sum of two orthogonal components:
//!
//!  
//!
//! ```text
//!    r  =  rParallel + rPerp.
//! ```
//!
//!  Let's give the name rPerp' to the vector obtained by rotating rPerp by
//!    pi/2 radians about n.
//!
//!  We know, from the results of the "canonical form" section, that
//!    applying our rotation to r will yield
//!
//!  
//!
//! ```text
//!    rParallel  +  cos(theta) rPerp  +  sin(theta) rPerp'
//! ```
//!
//!  So all we have to do is find rPerp and rPerp' in terms of r, n, and
//!    theta.
//!
//!  It turns out that rPerp' is precisely n x r, since n x r is parallel to
//!    rPerp' and has the same magnitude as rPerp, namely
//!
//!  
//!
//! ```text
//!    |r| sin(phi),
//! ```
//!
//!  where phi is the angle between r and n. Rotating rPerp' by another pi/2
//!    radians yields -rPerp, so
//!
//!  
//!
//! ```text
//!    rPerp = -n x ( n x r ).
//! ```
//!
//!  In the picture below,
//!
//!  
//!
//! * The diagonal, dashed line segment represents r.
//!
//!  * The short, vertical, dashed line segment represents n.
//!
//!  * The dotted, vertical extension of n represents the projection of r onto n.
//!
//!  * The dotted, horizontal segments represent
//!
//!  ```text
//!    n x ( n x r)
//! ```
//!  *  on the right, and
//!
//!  ```text
//!    - n x ( n x r)
//! ```
//!  *  on the left.
//!
//!  * The dotted, diagonal segment represents n x r.
//!
//!  * The little boxes at the intersection of the segments are supposed to
//! indicate orthogonality.
//!
//!  * The ugly, little segments with the label "phi" between them are supposed
//! to indicate the angle phi.
//!
//!  ```text
//!                       \           .  rParallel
//!                        \    phi --.
//!                         \ /       .
//!                       r  \        .
//!                           \       .
//!                            \      .
//!                             \     .
//!                              \    ^
//!                               \   |
//!                                \  |    n
//!                                 \ |_
//!      - n x ( n x r )   ...........|_|.........   n  x  ( n x r )
//!                                  /_/
//!          = rPerp                .                     =  - rPerp
//!                                .
//!                               .
//!                              .  n x r
//!  
//!                                      = rPerp'
//! ```
//!  Now we're ready to compute the image of r under the rotation. It is:
//!
//!  
//!
//! ```text
//!          rParallel     +   cos(theta) rPerp
//!                        +   sin(theta) rPerp'
//!  
//!    =   ( r - rPerp )   +   cos(theta) rPerp
//!                        +   sin(theta) rPerp'
//!  
//!    =        r          +   ( cos(theta) - 1 )   rPerp
//!                        +     sin(theta)         rPerp'
//!  
//!    =        r          +   ( 1 - cos(theta) )  ( n x ( n x r ) )
//!                        +      sin(theta)       (     n x r     ).
//! ```
//!
//!  This is what we were after: an expression for the image of r under the
//!    rotation, given in terms of r, theta, and n.
//!
//!  
//!
//!
//!  
//! ##  Formation of a rotation matrix from axis and angle
//!
//!  In this section, we derive an expression for a rotation matrix that
//!    explicitly relates the matrix to the rotation axis and angle. This
//!    expression is valuable for understanding how to find the rotation axis
//!    and angle of a rotation matrix, as well as how to build a rotation
//!    matrix having a given rotation axis and angle. The problem of finding a
//!    quaternion corresponding to a specified rotation matrix is also solved
//!    by the expression derived here.
//!
//!  What's the rotation matrix R that rotates vectors by theta radians about
//!    the vector n? If n is a unit vector, then the result of the last section
//!    implies that
//!
//!  
//!
//! ```text
//!    R * r  =  r     +   ( 1 - cos(theta) )  ( n x ( n x r ) )
//!                    +      sin(theta)       (     n x r     ),
//! ```
//!
//!  for any vector r. Now, let
//!
//!  
//!
//! ```text
//!    n = (n1, n2, n3),
//! ```
//!
//!  and define the matrix N by
//!
//!  
//!
//! ```text
//!        +-             -+
//!        |  0   -n3   n2 |
//!        |               |
//!    N = |  n3   0   -n1 |;
//!        |               |
//!        | -n2   n1   0  |
//!        +-             -+
//! ```
//!
//!  this definition implies that
//!
//!  
//!
//! ```text
//!    N * r = n x r
//! ```
//!
//!  for all r. So we can rewrite the above expression as
//!
//!  
//!
//! ```text
//!    R * r  =  r     +   ( 1 - cos(theta) )  ( N * ( N * r ) )
//!                    +      sin(theta)       (     N * r     ),
//! ```
//!
//!  or
//!
//!  
//!
//! ```text
//!                                           2
//!    R * r  =  [  I  +  ( 1 - cos(theta) ) N  +  sin(theta) N  ]  r.
//! ```
//!
//!  Since r is arbitrary, we must have
//!
//!  
//!
//! ```text
//!                                       2
//!    R  =   I   +   ( 1 - cos(theta) ) N   +   sin(theta) N.
//! ```
//!
//!  R is the desired matrix.
//!
//!  
//!
//!
//!  
//! ##  Finding the axis and angle of a rotation matrix
//!
//!  The topic is covered in reference \[1], so we'll just make a few notes.
//!
//!  There are many ways to recover the rotation axis. The most elegant
//!    method we know of is presented in \[1]. The idea is based on the
//!    observation that any rotation matrix R can be expressed by
//!
//!  
//!
//! ```text
//!                                       2
//!    R  =   I   +   ( 1 - cos(theta) ) N   +   sin(theta) N,
//! ```
//!
//!  where N is derived from the rotation axis, as in the last section. Now N
//!    is skew-symmetric and N squared is symmetric, so
//!
//!  
//!
//! ```text
//!         T
//!    R - R   =  2 sin(theta) N.
//! ```
//!
//!  As long as sin(theta) is non-zero, we've found N and hence the axis
//!    itself. If theta is pi, we have
//!
//!  
//!
//! ```text
//!                    2
//!    R  =   I  +  2 N,
//! ```
//!
//!  which still allows us to recover the axis.
//!
//!  In the tutorial section, we showed that the rotation angle can be
//!    recovered from the trace of a rotation matrix:
//!
//!  
//!
//! ```text
//!    angle = ACOS (  ( trace - 1 ) / 2  ).
//! ```
//!
//!  If the angle is very small, we will determine it more accurately from
//!    the relation
//!
//!  
//!
//! ```text
//!         T
//!    R - R   =  2 sin(theta) N.
//! ```
//!
//!     
//! ##  Formation of a rotation matrix from a quaternion
//!
//!  Since the quaternion gives us a rotation's axis and angle, an earlier
//!    discussion in this chapter gives us one way of recovering the rotation
//!    matrix: twice the arccosine of the first component of the quaternion
//!    gives us the rotation angle, and the rest of the quaternion is the
//!    rotation axis, so [AXISAR](crate::raw::axisar) can be used to form the matrix. In this
//!    approach, we may want to treat small rotation angles as a special case,
//!    since the arccosine function is very inaccurate when the argument is
//!    close to 1. We would use the norm of the "vector" portion of the
//!    quaternion to give us the sine of half the rotation angle instead, and
//!    recover the rotation angle from this.
//!
//!  There is a fast, accurate solution available. It depends on the formula
//!    relating a rotation matrix to its axis and angle, which we derived
//!    earlier in the chapter. In this approach, we compute the matrix
//!    corresponding to a quaternion, component by component.
//!
//!  Define
//!
//!  
//!
//! ```text
//!    c = cos(theta/2),
//!  
//!    s = sin(theta/2),
//! ```
//!
//!  and let the quaternion
//!
//!  
//!
//! ```text
//!    q  =   c   +  s n
//!       =   q0  +  s ( q1, q2, q3 )
//! ```
//!
//!  represent a rotation R having unit axis vector n and rotation angle
//!    theta.
//!
//!  If n = ( n1, n2, n3 ), and we define the matrix N by
//!
//!  
//!
//! ```text
//!        +-             -+
//!        |  0   -n3   n2 |
//!        |               |
//!    N = |  n3   0   -n1 |,
//!        |               |
//!        | -n2   n1   0  |
//!        +-             -+
//! ```
//!
//!  then the matrix M representing R is
//!
//!  
//!
//! ```text
//!                                       2
//!    M  =   I   +   ( 1 - cos(theta) ) N   +   sin(theta) N.
//! ```
//!
//!  Now we can make the substitutions
//!
//!  
//!
//! ```text
//!    sin(theta) = 2 c s,
//!  
//!                            2
//!    ( 1 - cos(theta) ) = 2 s
//! ```
//!
//!  to obtain
//!
//!  
//!
//! ```text
//!                            2
//!    M  =   I   +   2 ( s N )   +   2 c ( s N ).
//! ```
//!
//!  Substituting the elements of our quaternion into s N, we find
//!
//!  
//!
//! ```text
//!                             +-                                     -+
//!                             |     2    2                            |
//!            +-       -+      | -(q2 + q3 )     q1 q2        q1 q3    |
//!            | 1  0  0 |      |                                       |
//!            |         |      |                  2    2               |
//!    M  =    | 0  1  0 | + 2  |    q1 q2     -(q1 + q3 )     q2 q3    |
//!            |         |      |                                       |
//!            | 0  0  1 |      |                               2    2  |
//!            +-       -+      |    q1 q3        q2 q3     -(q1 + q2 ) |
//!                             +-                                     -+
//!  
//!                             +-                                     -+
//!                             |                                       |
//!                             |      0         -q0 q3       q0 q2     |
//!                             |                                       |
//!                             |                                       |
//!                        + 2  |     q0 q3         0        -q0 q1     |,
//!                             |                                       |
//!                             |                                       |
//!                             |    -q0 q2       q0 q1         0       |
//!                             +-                                     -+
//! ```
//!
//!  so
//!
//!  
//!
//! ```text
//!        +-                                                          -+
//!        |           2    2                                           |
//!        | 1 - 2 ( q2 + q3 )    2 (q1 q2 - q0 q3)   2 (q1 q3 + q0 q2) |
//!        |                                                            |
//!        |                                                            |
//!        |                               2    2                       |
//!    M = | 2 (q1 q2 + q0 q3)    1 - 2 ( q1 + q3 )   2 (q2 q3 - q0 q1) |.
//!        |                                                            |
//!        |                                                            |
//!        |                                                    2    2  |
//!        | 2 (q1 q3 - q0 q2)    2 (q2 q3 + q0 q1)   1 - 2 ( q1 + q2 ) |
//!        |                                                            |
//!        +-                                                          -+
//! ```
//!
//!     
//! ##  Equivalence of rotation definitions
//!
//!  The idea discussed here is used implicitly throughout the SPICELIB
//!    rotation routines.
//!
//!  We wish to prove that definitions (1) and (2) from the "Definition of
//!    rotations" section of the tutorial are equivalent. To do this, we need
//!    to show that a mapping R that satisfies definition (1) also satisfies
//!    definition (2). This amounts to showing that R has a fixed subspace of
//!    dimension 1, or equivalently, that R has 1 as one of its eigenvalues.
//!
//!  
//!
//!
//!  
//! ###  An algebraic approach
//!
//!  We observe that the characteristic polynomial of a rotation is of degree
//!    three, and so has either zero or two complex roots, hence at least one
//!    real root. Because rotations preserve norms, the magnitudes of all of
//!    the roots (eigenvalues), real or complex, are equal to one. So the real
//!    roots are 1 or -1. The determinant of any rotation matrix is 1, since
//!    the determinant of any 3 by 3 matrix is the dot product of the third
//!    column with the cross product of the first and second columns, and for
//!    rotations, this cross product is the third column. But the determinant
//!    is also the product of the eigenvalues. In the case where all three
//!    roots are 1 or -1, we cannot get a product of 1 unless at least one
//!    eigenvalue is equal to 1. If there are complex roots, they are complex
//!    conjugates, so their product is 1, which implies that the real root must
//!    be 1 as well, if the product of all three roots is 1.
//!
//!  
//!
//!
//!  
//! ###  A geometric approach
//!
//!  Again, we assume that our rotation R satisfies definition (1), and we
//!    prove that R has a fixed axis.
//!
//!  We're going to look at the effect of R on the unit sphere, and
//!    demonstrate that two points on the sphere are fixed. We'll assume that
//!    the rotation is not the identity and does not map any vector v to -v.
//!    This last case corresponds to a rotation of pi radians.
//!
//!  Our first observation is that R maps great circles to great circles.
//!    This follows from the fact that a great circle is a set of unit vectors,
//!    all orthogonal to some particular vector v. Since R preserves inner
//!    products, the image of the great circle is a set of unit vectors, all
//!    orthogonal to R(v).
//!
//!  Now, consider the distances that vectors on the unit sphere move when
//!    the rotation R is applied; there is some vector v, not necessarily
//!    unique, that moves the maximum distance. Let C1 be a great circle
//!    passing through v and R(v), and let C2 be a great circle that passes
//!    through v and intersects C1 at right angles. Now R(C2) passes through
//!    R(v), and if we can show that it passes through at right angles to C1,
//!    then C2 and R(C2) intersect at vectors p and -p, both of which are
//!    normal to v and R(v). So R(p) is either p or -p. But we've assumed that
//!    R does not map any vector to its inverse, so R(p) = p, and we have a
//!    fixed vector.
//!
//!  So, we must show that R(C2) passes through R(v) at right angles to C1.
//!    If it did not, there would be some point w on C2, close to v, such that
//!
//!  
//!
//! ```text
//!    || R(w) - w ||  >  || R(v) - v ||,
//! ```
//!
//!  contradicting our hypothesis that no vector moves farther that v. We
//!    will leave the rigorous proof of this last assertion to the energetic
//!    reader.
//!
//!  
//!
//!
//!  
//! ##  Quaternion multiplication
//!
//!  In this section, we verify some claims made in the tutorial on
//!    rotations.
//!
//!  There are two assertions that we need to prove:
//!
//!  
//!
//! *  1. If the unit quaternion q represents the rotation R, then for any vector v,
//!
//!  ```text
//!                      *
//!    R(v)  =  q * v * q,
//! ```
//!  *  where v is treated as a quaternion.
//!
//!  *  2. If the unit quaternions q1 and q2 represent the rotations R1 and R2, then
//! the rotation R2(R1) is represented by the quaternion
//!
//!  ```text
//!    q2 * q1.
//! ```
//!     
//! ###  Assertion 1
//!
//!  To prove the first assertion, we express R(v) in the form
//!
//!  
//!
//! ```text
//!    R(v) =  v + sin(theta) n x v  + ( 1 - cos(theta) ) n x ( n x v ),
//! ```
//!
//!  where n is a unit axis vector and theta is the corresponding rotation
//!    angle. We also define the constants C and S by
//!
//!  
//!
//! ```text
//!    C = cos(theta/2),
//!    S = sin(theta/2).
//! ```
//!
//!  The quaternion
//!
//!  
//!
//! ```text
//!    q = C  +  S n
//! ```
//!
//!  represents R. To check the assertion, we compute
//!
//!  
//!
//! ```text
//!         ( C  +  S n ) * v * ( C  -  S n )
//!  
//!  
//!    =    ( C  +  S n ) * [ ( S  <v,n> )  +  ( C v  -  S v x n ) ]
//!  
//!                                            2
//!    =    [ C S <v, n>  -  S C < n, v >  +  S  < n,  v x n > ]
//!  
//!            2                    2
//!      +  [ C v  - C S v x n  +  S <v, n> n  +  S C n x v
//!  
//!          2
//!      -  S n x ( v x n ) ].
//! ```
//!
//!  Since n is normal to v x n, the scalar part of the last line is zero,
//!    which leaves us with
//!
//!  
//!
//! ```text
//!  
//!     2       2                              2
//!    C v  +  S <v, n> n  +  2 S C n x v  -  S n x ( v x n ).
//! ```
//!
//!  We can re-write this again as
//!
//!  
//!
//! ```text
//!     2       2                               2
//!    C v  +  S <v, n> n  +  2 S C n x v  + 2 S n x ( n x v )
//!  
//!                                             2
//!                                        -   S n x ( n x v ),
//! ```
//!
//!  and using the vector identity
//!
//!  
//!
//! ```text
//!    A x ( B x C ) =  < A, C > B  -  < A, B > C,
//! ```
//!
//!  we can modify the final term to arrive at
//!
//!  
//!
//! ```text
//!     2       2                               2
//!    C v  +  S <v, n> n  +  2 S C n x v  + 2 S n x ( n x v )
//!  
//!                                             2
//!                                        -   S ( <n, v> n - <n, n> v ).
//! ```
//!
//!  Since n is a unit vector, the entire expression reduces to
//!
//!  
//!
//! ```text
//!                                  2
//!         v  +  2 S C n x v  +  2 S  n x ( n x v )
//!  
//!    =    v  +  2 sin(theta/2) cos(theta/2) n x v
//!  
//!                    2
//!            +  2 sin (theta/2) n x ( n x v)
//!  
//!    =    v  +  sin(theta) n x v  +  ( 1 - cos(theta) ) n x ( n x v )
//!  
//!    =    R(v).
//! ```
//!
//!     
//! ###  Assertion 2
//!
//!  The second assertion follows rather more quickly from the first. Given
//!    that R1(v) is
//!
//!  
//!
//! ```text
//!               *
//!    q1 * v * q1 ,
//! ```
//!
//!  we can express R2(R1(v)) by
//!
//!  
//!
//! ```text
//!                         *      *
//!       q2 * ( q1 * v * q1 ) * q2
//!                                    *
//!    =  ( q2 * q1 ) * v * ( q2 * q1 ).
//! ```
//!
//!  Now let q be a quaternion that represents R2(R1); then
//!
//!  
//!
//! ```text
//!             *
//!    q * v * q   =  R2(R1(v))
//! ```
//!
//!  for all v. We'll be done if we can show that, in general, for unit
//!    quaternions x and y, if
//!
//!  
//!
//! ```text
//!             *             *
//!    x * v * x  =  y * v * y
//! ```
//!
//!  for all vectors v, then x equals y or -y. But this equation implies that
//!
//!  
//!
//! ```text
//!     *                 *
//!    y * x * v  =  v * y * x,
//! ```
//!
//!  for all v, which in turn implies that
//!
//!  
//!
//! ```text
//!     *
//!    y * x
//! ```
//!
//!  is a scalar, since only scalar quaternions commute with every vector
//!    quaternion (due to the cross product term in the product formula). Since
//!    y and x are unit quaternions, either
//!
//!  
//!
//! ```text
//!     *
//!    y * x = 1
//! ```
//!
//!  or
//!
//!  
//!
//! ```text
//!     *
//!    y * x = -1,
//! ```
//!
//!  so x = y or -y.
//!
//!  We conclude that q2 * q1 = q or -q, so q2 * q1 does represent R2(R1).
//!
//!  
//!
//!
//!  
//! ##  Recovery of Euler angles from a rotation matrix
//!
//!  Here's the problem: Given a rotation matrix M, and a set of coordinate
//!    axes indexed by i1, i2, i3, find angles w1, w2, w3 such that
//!
//!  
//!
//! ```text
//!    M = [w1]     [w2]      [w3]  .                       (1)
//!            i1       i2        i3
//! ```
//!
//!  There are a couple of reasons why we might want to solve this problem:
//!    first, the representation of a rotation by three Euler angles is a
//!    common one, so it is convenient to be able to convert the matrix
//!    representation to this form. Also, the three angles on the right hand
//!    side of equation (1) often allow you to visualize a rotation more
//!    readily than does the matrix representation M.
//!
//!  This "factorization" is possible if i2 does not equal i1 or i3. For
//!    each valid sequence (i1-i2-i3) of axes, there is a set of functions that
//!    give us w1, w2, and w3 as a function of M:
//!
//!  
//!
//! ```text
//!    w1 = f1         ( M ),
//!           i1-i2-i3
//!  
//!    w2 = f2         ( M ),
//!           i1-i2-i3
//!  
//!    w3 = f3         ( M ).
//!           i1-i2-i3
//! ```
//!
//!  How can we derive the functions
//!
//!  
//!
//! ```text
//!    f1        ,  f2        ,  f3        ?
//!      i1-i2-i3     i1-i2-i3     i1-i2-i3
//! ```
//!
//!  One approach is to multiply the matrices on the right hand side of
//!    equation (1); this yields a matrix whose entries are sums of products of
//!    sines and cosines of w1, w2, and w3. We can then equate the entries of
//!    this matrix to those of M, and find formulas for w1, w2, and w3 that
//!    arise from the component-wise correspondence. In subsequent sections, we
//!    actually carry out this procedure for 3-1-3 and 1-2-3 factorizations.
//!
//!  There are twelve sets of axes to consider, so there are potentially
//!    twelve sets of functions to compute. However, the procedure we've just
//!    described is not enjoyable enough to justify doing it twelve times. We'd
//!    like to find a slicker way of solving the problem. One approach is to
//!    find a way of "recycling" the formulas we derived for one particular
//!    axis sequence. Here's an example of how we might do this:
//!
//!  Suppose that we already have functions
//!
//!  
//!
//! ```text
//!    f1     ,  f2     ,  f3
//!      3-1-3     3-1-3     3-1-3
//! ```
//!
//!  that allow us to factor rotation matrix M as a 3-1-3 product:
//!
//!  If
//!
//!  
//!
//! ```text
//!    M = [w1]   [w2]    [w3] .                            (2)
//!            3      1       3
//! ```
//!
//!  then
//!
//!  
//!
//! ```text
//!    w1 = f1      ( M ),
//!           3-1-3
//!  
//!    w2 = f2      ( M ),
//!           3-1-3
//!  
//!    w3 = f3      ( M ).
//!           3-1-3
//! ```
//!
//!  We'd like to somehow use the functions we've already got to factor M as
//!    a 2-3-2 product: we want to find functions
//!
//!  
//!
//! ```text
//!    f1     ,   f2     ,   f3
//!      2-3-2      2-3-2      2-3-2
//! ```
//!
//!  such that
//!
//!  
//!
//! ```text
//!    M = [y1]   [y2]   [y3] ,                             (3)
//!            2      3      2
//! ```
//!
//!  and
//!
//!  
//!
//! ```text
//!    y1 = f1      ( M ),
//!           2-3-2
//!  
//!    y2 = f2      ( M ),
//!           2-3-2
//!  
//!    y3 = f3      ( M )
//!           2-3-2
//! ```
//!
//!  without having to derive
//!
//!  
//!
//! ```text
//!    f1     ,   f2     ,   f3
//!      2-3-2      2-3-2      2-3-2
//! ```
//!
//!  from scratch.
//!
//!  We'll start out by using a new basis, relative to which the right hand
//!    side of (3) is not a 2-3-2, but rather a 3-1-3 rotation. It is important
//!    to note here that bases are ordered sets of vectors; changing the order
//!    changes the basis.
//!
//!  Let the basis B1 be the ordered set of vectors
//!
//!  
//!
//! ```text
//!    {e(1), e(2), e(3)},
//! ```
//!
//!  and let the basis B2 be the ordered set of vectors
//!
//!  
//!
//! ```text
//!    {e(3), e(1), e(2)}.
//! ```
//!
//!  Now the rotation matrix
//!
//!  
//!
//! ```text
//!    [y]
//!       2
//! ```
//!
//!  expressed relative to B1 represents the same rotation as the matrix
//!
//!  
//!
//! ```text
//!    [y]
//!       3
//! ```
//!
//!  expressed relative to B2. Both matrices represent a rotation of y
//!    radians about the vector e(2). Similarly, the matrix
//!
//!  
//!
//! ```text
//!    M  =  [y1]  [y2]  [y3]
//!              2     3     2
//! ```
//!
//!  expressed relative to B1 represents the same rotation as the matrix
//!
//!  
//!
//! ```text
//!    M' =  [y1]  [y2]  [y3]
//!              3     1     3
//! ```
//!
//!  expressed relative to B2. So if C is the matrix whose columns are the
//!    elements of B2, expressed relative to B1, namely
//!
//!  
//!
//! ```text
//!         +-       -+
//!         | 0  1  0 |
//!    C =  | 0  0  1 |,
//!         | 1  0  0 |
//!         +-       -+
//! ```
//!
//!  then
//!
//!  
//!
//! ```text
//!     -1
//!    C   M  C   =  M'                                     (4)
//! ```
//!
//!  We can use the functions
//!
//!  
//!
//! ```text
//!    f1     ,  f2     ,  f3
//!      3-1-3     3-1-3     3-1-3
//! ```
//!
//!  to factor M' as a 3-1-3 product: applying (4), we have
//!
//!  
//!
//! ```text
//!               -1
//!    y1 = f1 ( C   M  C ),                                (5)
//!  
//!               -1
//!    y2 = f2 ( C   M  C ),                                (6)
//!  
//!               -1
//!    y3 = f3 ( C   M  C ),                                (7)
//! ```
//!
//!  so we've found functions that yield the angles y1, y2 and y3 that we
//!    sought. "No muss, no fuss."
//!
//!  How much mileage can we get out of our 3-1-3 factorization functions?
//!    Looking at our example, we see that the main "trick" is to find a
//!    basis so that the factorization we want is a 3-1-3 factorization with
//!    respect to that basis. It is important the new basis be right-handed;
//!    otherwise the form of the matrices
//!
//!  
//!
//! ```text
//!    [w]
//!       i
//! ```
//!
//!  is not preserved. It turns out that for any axis sequence of the form
//!    a-b-a, we can find a right-handed basis such that the factorization we
//!    want is a 3-1-3 factorization with respect to that basis. There are two
//!    cases: if we define a successor function s on the integers 1, 2, 3 such
//!    that
//!
//!  
//!
//! ```text
//!    s(1) = 2,
//!    s(2) = 3,
//!    s(3) = 1,
//! ```
//!
//!  we either have b = s(a) or a = s(b).
//!
//!  In the first case, b = s(a), and if our original ordered basis is
//!
//!  
//!
//! ```text
//!    B1 = { e(1), e(2), e(3) },
//! ```
//!
//!  then
//!
//!  
//!
//! ```text
//!    B2 = { e(b), e( s(b) ), e(a) }
//! ```
//!
//!  is the right-handed basis we're looking for. You can check that
//!
//!  
//!
//! ```text
//!    e(a) = e(b) x e( s(b) ).
//! ```
//!
//!  We recall that the transformation matrix C we require has the elements
//!    of B2 as columns.
//!
//!  For example, if a is 2 and b is 3, then B2 is
//!
//!  
//!
//! ```text
//!    { e(3), e(1), e(2) },
//! ```
//!
//!  and the matrix C is
//!
//!  
//!
//! ```text
//!         +-       -+
//!         | 0  1  0 |
//!    C =  | 0  0  1 |,
//!         | 1  0  0 |
//!         +-       -+
//! ```
//!
//!  as we have seen previously.
//!
//!  The axis sequences that can be handled by the above procedure are 1-2-1,
//!    2-3-2, and 3-1-3.
//!
//!  In the second case, a = s(b), and if our original ordered basis is
//!
//!  
//!
//! ```text
//!    B1 = { e(1), e(2), e(3) },
//! ```
//!
//!  then
//!
//!  
//!
//! ```text
//!    B2 = { e(b), -e( s(a) ), e(a) }
//! ```
//!
//!  is the right-handed basis we're looking for. Again, you can verify this
//!    by taking cross products. The transformation matrix C we require has the
//!    elements of B2 as columns.
//!
//!  For example, if a = 2 and b = 1, then B2 is
//!
//!  
//!
//! ```text
//!    { e(1), -e(3), e(2)) }
//! ```
//!
//!  and the matrix C is
//!
//!  
//!
//! ```text
//!         +-       -+
//!         | 1  0  0 |
//!    C =  | 0  0  1 |.
//!         | 0 -1  0 |
//!         +-       -+
//! ```
//!
//!  The axis sequences that can be handled by the above procedure are 1-3-1,
//!    2-1-2, and 3-2-3. So we can use our 3-1-3 formula to handle all of the
//!    a-b-a factorizations, just by computing the correct transformation
//!    matrix C.
//!
//!  What about a-b-c factorizations? As you might guess, the procedure we've
//!    described also applies to these, with very little modification.
//!
//!  Suppose we have the formulas we need to carry out a 1-2-3 factorization.
//!    We'd like to find a basis that allows us to represent the a-b-c product
//!
//!  
//!
//! ```text
//!    [w1]   [w2]   [w3]
//!        a      b      c
//! ```
//!
//!  as the product
//!
//!  
//!
//! ```text
//!    [w1]   [w2]   [w3] .
//!        1      2      3
//! ```
//!
//!  Again, there are two cases, depending on whether b is the successor of a
//!    or a is the successor of b, according to our cyclic ordering.
//!
//!  In the case where b is the successor of a, the right-handed basis we
//!    want is
//!
//!  
//!
//! ```text
//!    B2 = { e(a), e(b), e(c) }.
//! ```
//!
//!  With respect to the basis B2, our a-b-c factorization is a 1-2-3
//!    factorization. Again, we can form the transformation matrix C by letting
//!    its columns be the elements of B2.
//!
//!  In the second case, a is the successor of b. Our new basis is
//!
//!  
//!
//! ```text
//!    B2 = { e(a), e(b), -e(c)}.
//! ```
//!
//!  In this case, there is a slight twist: the change of basis we use
//!    negates the third rotation angle. This is not a serious problem; the
//!    change of basis converts the product
//!
//!  
//!
//! ```text
//!    [w1]   [w2]   [w3]
//!        a      b      c
//! ```
//!
//!  to
//!
//!  
//!
//! ```text
//!    [w1]   [w2]   [-w3] ,
//!        1      2       3
//! ```
//!
//!  so we can still recover the angles w1, w2, and w3 easily. So our 1-2-3
//!    factorization formula allows us to handle all the a-b-c factorizations.
//!
//!  Having shown that we can perform all of the a-b-a and a-b-c
//!    factorizations using just one formula for each type of factorization, we
//!    now proceed to derive those formulas. This is not a particularly
//!    instructive procedure, but the derivations ought to be written down
//!    somewhere, and this is as good a place as any.
//!
//!  
//!
//!
//!  
//! ###  Euler angle recovery: a-b-a case
//!
//!  We'll derive the formulas for a 3-1-3 factorization.
//!
//!  In this case, the right hand side of (1) is
//!
//!  
//!
//! ```text
//!    +-                     -+     +-                      -+
//!    |  cos(w1)  sin(w1)  0  |     | 1       0        0     |
//!    | -sin(w1)  cos(w1)  0  |  *  | 0    cos(w2)  sin(w2)  |  *
//!    |      0       0     1  |     | 0   -sin(w2)  cos(w2)  |
//!    +-                     -+     +-                      -+
//!  
//!    +-                     -+
//!    |  cos(w3)  sin(w3)  0  |
//!    | -sin(w3)  cos(w3)  0  |
//!    |     0        0     1  |
//!    +-                     -+
//! ```
//!
//!  which equals
//!
//!  
//!
//! ```text
//!    +-                     -+
//!    |  cos(w1)  sin(w1)  0  |
//!    | -sin(w1)  cos(w1)  0  |   *
//!    |      0       0     1  |
//!    +-                     -+
//!    +-                                            -+
//!    |          cos(w3)       sin(w3)         0     |
//!    |  -cos(w2)sin(w3)   cos(w2)cos(w3)   sin(w2)  |
//!    |   sin(w2)sin(w3)  -sin(w2)cos(w3)   cos(w2)  |
//!    +-                                            -+
//! ```
//!
//!  which comes out to
//!
//!  
//!
//! ```text
//!    +-                                                              -+
//!    |         cos(w1)cos(w3)          cos(w1)sin(w3)  sin(w1)sin(w2) |
//!    | -sin(w1)cos(w2)sin(w3)  +sin(w1)cos(w2)cos(w3)                 |
//!    |                                                                |
//!    |        -sin(w1)cos(w3)         -sin(w1)sin(w3)  cos(w1)sin(w2) |.
//!    | -cos(w1)cos(w2)sin(w3)  +cos(w1)cos(w2)cos(w3)                 |
//!    |                                                                |
//!    |         sin(w2)sin(w3)         -sin(w2)cos(w3)         cos(w2) |
//!    +-                                                              -+
//! ```
//!
//!  At this point, we can recover w1, w2, and w3 from the elements of M. The
//!    inverse trigonometric functions used below are borrowed from Fortran. We
//!    find w2 from the relation
//!
//!  
//!
//! ```text
//!    w2 = ACOS( M(3,3) ).
//! ```
//!
//!  (So w2 is in \[0, pi].)
//!
//!  If w2 is not equal to 0 or pi, then we can recover w1 as follows:
//!
//!  
//!
//! ```text
//!    M(1,3)       sin(w1)sin(w2)
//!    ------   =   --------------  =  tan(w1),
//!    M(2,3)       cos(w1)sin(w2)
//!  
//!    w1 = ATAN2 ( M(1,3), M(2,3) ).
//! ```
//!
//!  We find w3 in an analogous fashion, again assuming w2 is not equal to 0
//!    or pi. We find
//!
//!  
//!
//! ```text
//!     M(3,1)       sin(w2)sin(w3)
//!    -------   =   --------------  =  tan(w3),
//!    -M(3,2)       sin(w2)cos(w3)
//!  
//!    w3 = ATAN2 ( M(3,1), -M(3,2) ).
//! ```
//!
//!  Note the minus sign used in the second ATAN2 argument. For ATAN2 to
//!    determine the correct value, it is necessary that the first and second
//!    arguments have the same signs as sin(w3) and cos(w3), respectively.
//!
//!  Now if w2 is equal to zero or pi, we have a degenerate case: M is the
//!    product of two rotations about the third coordinate axis. The angles of
//!    the rotations are not determined uniquely, only the sum of the angles
//!    is. One way of finding a factorization is to set w3 to zero, and solve
//!    for w1. The matrix M then is equal to
//!
//!  
//!
//! ```text
//!    +-                                 -+
//!    |  cos(w1)  cos(w2)sin(w1)     0    |
//!    | -sin(w1)  cos(w2)cos(w1)     0    |,
//!    |    0            0         cos(w2) |
//!    +-                                 -+
//! ```
//!
//!  so we can recover w1 by computing
//!
//!  
//!
//! ```text
//!    w1 = ATAN2( -M(2,1), M(1,1) ).
//! ```
//!
//!     
//! ###  Euler angle recovery: a-b-c case
//!
//!  We'll derive the formulas for a 1-2-3 factorization.
//!
//!  In this case, the right hand side of (1) is
//!
//!  
//!
//! ```text
//!    +-                      -+     +-                      -+
//!    | 1       0        0     |     | cos(w2)   0  -sin(w2)  |
//!    | 0    cos(w1)  sin(w1)  |  *  |    0      1      0     |  *
//!    | 0   -sin(w1)  cos(w1)  |     | sin(w2)   0   cos(w2)  |
//!    +-                      -+     +-                      -+
//!  
//!    +-                      -+
//!    |  cos(w3)  sin(w3)  0   |
//!    | -sin(w3)  cos(w3)  0   |
//!    |     0        0     1   |
//!    +-                      -+
//! ```
//!
//!  which equals
//!
//!  
//!
//! ```text
//!    +-                      -+
//!    | 1       0        0     |
//!    | 0    cos(w1)  sin(w1)  |  *
//!    | 0   -sin(w1)  cos(w1)  |
//!    +-                      -+
//!  
//!    +-                                              -+
//!    | cos(w2)cos(w3)   cos(w2)sin(w3)      -sin(w2)  |
//!    |                                                |
//!    |       -sin(w3)          cos(w3)          0     |
//!    |                                                |
//!    | sin(w2)cos(w3)   sin(w2)sin(w3)       cos(w2)  |
//!    +-                                              -+
//! ```
//!
//!  which comes out to
//!
//!  
//!
//! ```text
//!    +-                                                              -+
//!    |         cos(w2)cos(w3)          cos(w2)sin(w3)        -sin(w2) |
//!    |                                                                |
//!    |        -cos(w1)sin(w3)          cos(w1)cos(w3)  sin(w1)cos(w2) |
//!    | +sin(w1)sin(w2)cos(w3)  +sin(w1)sin(w2)sin(w3)                 |.
//!    |                                                                |
//!    |         sin(w1)sin(w3)         -sin(w1)cos(w3)  cos(w1)cos(w2) |
//!    | +cos(w1)sin(w2)cos(w3)  +cos(w1)sin(w2)sin(w3)                 |
//!    +-                                                              -+
//! ```
//!
//!  We recover w2 by
//!
//!  
//!
//! ```text
//!    w2 = ASIN ( -M(1,3) ),
//! ```
//!
//!  so w2 is in the interval \[-pi/2, pi/2].
//!
//!  As long as w2 does not equal pi/2 or -pi/2, we can find w1 by the
//!    formula
//!
//!  
//!
//! ```text
//!    w1 = ATAN2 ( M(2,3), M(3,3) ),
//! ```
//!
//!  and w3 from the formula
//!
//!  
//!
//! ```text
//!    w3 = ATAN2 ( M(1,2), M(1,1) ).
//! ```
//!
//!  If w2 is -pi/2 or pi/2, we have a degenerate case. The sum of w1 and w3
//!    is determined, but w1 and w3 are not determined individually. We can set
//!    w3 to zero, which reduces our right hand side to
//!
//!  
//!
//! ```text
//!    +-                                       -+
//!    |         0            0        -sin(w2)  |
//!    |  sin(w1)sin(w2)    cos(w1)       0      |,
//!    |  cos(w1)sin(w2)   -sin(w1)       0      |
//!    +-                                       -+
//! ```
//!
//!  so we can recover w1 from the formula
//!
//!  
//!
//! ```text
//!    w1 = ATAN2 ( -M(3,2), M(2,2) ).
//! ```
//!
//!     
//! #  Appendix A: Document Revision History
//!
//!  
//!
//!
//!  
//! ###  March 9, 2017
//!
//!  Minor edits to eliminate typos.
//!
//!  
//!
//!
//!  
//! ###  May 27, 2010
//!
//!  Minor edit to eliminate typo.
//!
//!  
//!
//!
//!  
//! ###  November 17, 2005
//!
//!  Documentation of the routines [QXQ](crate::raw::qxq), [QDQ2AV](crate::raw::qdq2av) was added.
//!
//!  
//!
//!
//!  
//! ###  January 10, 2005
//!
//!  A few corrections were made to environment tags in the .ftm source for
//!    this document.
//!
//!  
//!
//!
//!  
//! ###  February 2, 2004
//!
//!  Performed a spell-check on text.
//!
//!  
//!
//!
//!  
//! ###  December 2, 2002
//!
//!  
//!
//! *  The relationship between Euler angles and the C-matrix is defined
//! differently by different projects. Modifications have been made to clarify
//! the definitions used by Cassini, Voyager and Galileo.
//!
//!     
//! ###  April 26, 1999
//!
//!  
//!
//! *  An equation involving quaternion multiplication was corrected: the
//! expression v*v = 0 was replaced by v*v = -1.
//!
//!  *  Quotation style was changed from British to American.
//!
//!  *  Some variable names were changed to remove underscores.
//!
//!  *  Some minor re-wording was done to simplify creation of the CSPICE version
//! of this document.
//!
//!