summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/bez123/bez123.dtx
blob: fb6622d50c7ded123746fc94f8028956f72b85a9 (plain)
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
% \iffalse meta-comment
% bez123.dtx
% Author: Peter Wilson, Herries Press
% Maintainer: Will Robertson (will dot robertson at latex-project dot org)
% Copyright 1998--2004 Peter R. Wilson
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any 
% later version: <http://www.latex-project.org/lppl.txt>
%
% This work has the LPPL maintenance status "maintained".
% The Current Maintainer of this work is Will Robertson.
%
% This work consists of the files listed in the README file.
%
%
% 
%<*driver>
\documentclass{ltxdoc}
\usepackage{bez123}
\EnableCrossrefs
\CodelineIndex
\setcounter{StandardModuleDepth}{1}
\begin{document}
  \DocInput{bez123.dtx}
\end{document}
%</driver>
%
% \fi
%
% \CheckSum{988}
%
% \DoNotIndex{\',\.,\@M,\@@input,\@addtoreset,\@arabic,\@badmath}
% \DoNotIndex{\@centercr,\@cite}
% \DoNotIndex{\@dotsep,\@empty,\@float,\@gobble,\@gobbletwo,\@ignoretrue}
% \DoNotIndex{\@input,\@ixpt,\@m}
% \DoNotIndex{\@minus,\@mkboth,\@ne,\@nil,\@nomath,\@plus,\@set@topoint}
% \DoNotIndex{\@tempboxa,\@tempcnta,\@tempdima,\@tempdimb}
% \DoNotIndex{\@tempswafalse,\@tempswatrue,\@viipt,\@viiipt,\@vipt}
% \DoNotIndex{\@vpt,\@warning,\@xiipt,\@xipt,\@xivpt,\@xpt,\@xviipt}
% \DoNotIndex{\@xxpt,\@xxvpt,\\,\ ,\addpenalty,\addtolength,\addvspace}
% \DoNotIndex{\advance,\Alph,\alph}
% \DoNotIndex{\arabic,\ast,\begin,\begingroup,\bfseries,\bgroup,\box}
% \DoNotIndex{\bullet}
% \DoNotIndex{\cdot,\cite,\CodelineIndex,\cr,\day,\DeclareOption}
% \DoNotIndex{\def,\DisableCrossrefs,\divide,\DocInput,\documentclass}
% \DoNotIndex{\DoNotIndex,\egroup,\ifdim,\else,\fi,\em,\endtrivlist}
% \DoNotIndex{\EnableCrossrefs,\end,\end@dblfloat,\end@float,\endgroup}
% \DoNotIndex{\endlist,\everycr,\everypar,\ExecuteOptions,\expandafter}
% \DoNotIndex{\fbox}
% \DoNotIndex{\filedate,\filename,\fileversion,\fontsize,\framebox,\gdef}
% \DoNotIndex{\global,\halign,\hangindent,\hbox,\hfil,\hfill,\hrule}
% \DoNotIndex{\hsize,\hskip,\hspace,\hss,\if@tempswa,\ifcase,\or,\fi,\fi}
% \DoNotIndex{\ifhmode,\ifvmode,\ifnum,\iftrue,\ifx,\fi,\fi,\fi,\fi,\fi}
% \DoNotIndex{\input}
% \DoNotIndex{\jobname,\kern,\leavevmode,\let,\leftmark}
% \DoNotIndex{\list,\llap,\long,\m@ne,\m@th,\mark,\markboth,\markright}
% \DoNotIndex{\month,\newcommand,\newcounter,\newenvironment}
% \DoNotIndex{\NeedsTeXFormat,\newdimen}
% \DoNotIndex{\newlength,\newpage,\nobreak,\noindent,\null,\number}
% \DoNotIndex{\numberline,\OldMakeindex,\OnlyDescription,\p@}
% \DoNotIndex{\pagestyle,\par,\paragraph,\paragraphmark,\parfillskip}
% \DoNotIndex{\penalty,\PrintChanges,\PrintIndex,\ProcessOptions}
% \DoNotIndex{\protect,\ProvidesClass,\raggedbottom,\raggedright}
% \DoNotIndex{\refstepcounter,\relax,\renewcommand,\reset@font}
% \DoNotIndex{\rightmargin,\rightmark,\rightskip,\rlap,\rmfamily,\roman}
% \DoNotIndex{\roman,\secdef,\selectfont,\setbox,\setcounter,\setlength}
% \DoNotIndex{\settowidth,\sfcode,\skip,\sloppy,\slshape,\space}
% \DoNotIndex{\symbol,\the,\trivlist,\typeout,\tw@,\undefined,\uppercase}
% \DoNotIndex{\usecounter,\usefont,\usepackage,\vfil,\vfill,\viiipt}
% \DoNotIndex{\viipt,\vipt,\vskip,\vspace}
% \DoNotIndex{\wd,\xiipt,\year,\z@}
%
% \def\dtxfile{bez123.dtx}
% \def\fileversion{v1.1}
% \def\filedate{1998/10/14}
% \def\fileversion{v1.1a}
% \def\filedate{2004/04/16}
% \def\fileversion{v1.1b}
% \def\filedate{2009/09/02}
% \newcommand*{\Lpack}[1]{\textsf {#1}}        ^^A typest a package
% \newcommand*{\Lopt}[1]{\textsf {#1}}         ^^A typeset an option
% \newcommand*{\file}[1]{\texttt {#1}}         ^^A typeset a file
% \newcommand*{\Lcount}[1]{\textsl {\small#1}} ^^A typeset a counter
% \newcommand*{\pstyle}[1]{\textsl {#1}}       ^^A typeset a pagestyle
% \newcommand*{\Lenv}[1]{\texttt {#1}}         ^^A typeset an environment
% \newcommand{\eqref}[1]{equation~(\ref{#1})}  ^^A typeset ref to an equation
%
% \title{The \Lpack{bez123} and \Lpack{multiply} packages\thanks{This
%        file (\texttt{\dtxfile}) has version number \fileversion, 
%        last revised \filedate.}}
%
% \author{%
% Author: Peter Wilson, Herries Press\\
% Maintainer: Will Robertson\\
% \texttt{will dot robertson at latex-project dot org}
% }
% \date{\filedate}
% \maketitle
% \begin{abstract}
%    The \Lpack{bez123} package provides for the drawing of linear, cubic,
% and rational quadratic Bezier curves. The \Lpack{multiply} package
% provides a command to multiply a length without numerical overflow.
% \end{abstract}
% \tableofcontents
% \listoftables
% \listoffigures
%
% \StopEventually{}
%
% 
%
% \section{Introduction}
%
% This document provides the commented source for a \LaTeX{}
% package file that extends the \LaTeX{} facilities for drawing
% Bezier curves. The package was originally developed as part of 
% a suite designed for the typesetting of
% documents according to the rules for ISO international 
% standards~\cite{PRW96i}.
% This manual is typeset according to the conventions of the
% \LaTeX{} \textsc{docstrip} utility which enables the automatic
% extraction of the \LaTeX{} macro source files~\cite{GOOSSENS94}.
%
%    Drawing a non-rational quadratic Bezier curve is provided as part 
% of the standard \LaTeX{} system.
%    Section~\ref{sec:usage} provides the user manual for the new commands
% supplied by this package for drawing a variety of Bezier curves.
% These include commands for drawing linear and cubic non-rational Bezier 
% curves and rational quadratic curves.
%
%    Section~\ref{sec:bez} describes the implementation of the package.
% As a side-effect of the implementation, a facility is also provided
% for performing multiplication in \TeX{} without overflow. This is
% described in Section~\ref{sec:mnoflow}.
%
%
%
% \section{Usage} \label{sec:usage}
%
%    Leslie Lamport provided the means of drawing a quadratic Bezier curve
% \emph{via} the \LaTeXe{} |\qbezier|~\cite[pp. 125--126]{LAMPORT94} command.
% This package
% extends the Bezier facility by providing commands to draw linear,
% rational quadratic, and cubic Bezier curves.
%
%    Bezier curves are named after Pierre Bezier who invented them. They
% are widely used within Computer Aided Design (CAD) programs and other
% graphics systems; descriptions can be found in many places, with varying
% degrees of mathematical complexity, such 
% as~\cite{FandP,MORTENSON85,FARIN90}.
%
%    The Bezier curve is a parameterized curve of degree $n$ and can 
% therefore be specified by $(n+1)$ points 
% (i.e., point $p_{0}$ through $p_{n}$).
% Among its other properties, a Bezier curve of degree $n$ passes through 
% through the points $p_{0}$ and $p_{n}$ and passes close to the other 
% defining points. The general equation for a Bezier curve of degree $n$ with
% parameter $t$ is
% \begin{equation}
%  p(t) = a_{0} + a_{1}t + a_{2}t^{2} + \cdots + a_{n}t^{n} \label{eq:gen}
% \end{equation}
% where the coefficients $a_{i}$ depend on the defining points, and 
% traditionally $0 \leq t \leq 1$.
%
%    For a linear (degree $1$) curve, the equation is
% \begin{equation}
%  p(t) = p_{0} + (p_{1} - p_{0})t  \label{eq:lin}
% \end{equation}
% By inspection, $p(0) = p_{0}$ and $p(1) = p_{1}$.
%
%    Rearranging \eqref{eq:gen} slightly we get
% \begin{equation}
%  p(t) - p_{0} = (p_{1} - p_{0})t  \label{eq:lin2}
% \end{equation}
% In other words, we can march along the curve from the starting point to
% the ending point by evaluating the right hand side of 
% \eqref{eq:lin2} for increasing values of the parameter $t$.
%
%   In order to shorten the equations slightly, and also make them more
% convenient to work with numerically, we will use the notation
% \begin{displaymath}
% l_{pq} = p_{p} - p_{q}
% \end{displaymath}
% Thus, the final form for the linear Bezier curve is
% \begin{equation}
% p(t) - p_{0} = l_{10}t  \label{eq:lin3}
% \end{equation}
% 
% \DescribeMacro{\lbezier}
% The command |\lbezier[|\meta{N}|](|\meta{p0}|)(|\meta{p1}|)| draws a
% linear Bezier curve with \meta{N} plotted points from the point \meta{p0}
% (with coordinates \meta{x0,y0}) to the point \meta{p1} (with
% coordinates \meta{x1,y1}). \meta{N} is an optional argument. If it is
% either not given or is given with a value of zero, 
% then the command will calculate the number of points to be 
% plotted, subject to a maximum number. 
% There must be no spaces between the arguments to the 
% |\lbezier| command; this restriction also applies to the other Bezier
% drawing commands provided by the \Lpack{bez123} package.
%
%    Figure~\ref{fig:beta} shows an example of a dotted line drawn using
% the |\lbezier| command. The actual code used is:
% \begin{verbatim}
% \lbezier[50](15,30)(30,0)
% \end{verbatim}
% thus drawing a straight line consisting of 50 points.
%
% \DescribeMacro{\qbeziermax}
%    The standard \LaTeX{} command |\qbeziermax| sets a maximum limit
% on the number of points used to draw any of the Bezier curves.
%
% \DescribeMacro{\thinlines}
% \DescribeMacro{\thicklines}
% \DescribeMacro{\linethickness}
%    The `points' used in drawing the Bezier curves are small squares. The
% size of these squares are controlled by the standard \LaTeX{}
% |\thinlines|, |\thicklines| and/or |\linethickness| commands.
% Consult Lamport~\cite{LAMPORT94} for descriptions of these, and 
% |\qbeziermax|, commands.
%
%
%   It is convenient to introduce some general properties of Bezier curves
% at this point.
% \begin{itemize}
% \item A degree $n$ Bezier curve is defined by $(n+1)$ points which we
% will label as $p_{0}$ through $p_{n}$. The lines joining the points
% $p_{0}, p_{1}, \ldots , p_{n}$ are called the \emph{control polygon}.
% The Bezier curve is parameterized by a variable we will call $t$, with
% $0 \leq t \leq 1$.
% \item A degree $n$ Bezier curve starts at point $p_{0}$ and ends at
% point $p_{n}$.
% \item At $t=0$ the curve passes through $p_{0}$ and is tangent to the
% line $l_{10} = p_{1}-p_{0}$.
% \item At $t=1$ the curve passes through $p_{n}$ and is tangent to the
% line $l_{(n)(n-1)} = p_{n}-p_{(n-1)}$.
% \item A \emph{non-rational} Bezier curve lies within the \emph{convex 
% hull}\footnote{The convex hull can be thought of as the shape that a rubber
% band will take if it is stretched around pins placed at each point.}
% of the points $p_{0}$ through $p_{n}$. For examples of convex hulls see
% figure~\ref{fig:ch}. Note that the shape of a convex hull is independant
% of the ordering of the points.
% \end{itemize}
%
% \begin{figure}
% \centering
% \setlength{\unitlength}{1mm}
% \begin{picture}(70,80)
%  ^^A degree 3
% \put(0,5){\begin{picture}(30,30)
%   \thinlines
%   \put(0,0){\circle{2}}
%   \put(-2,0){\makebox(0,0)[br]{0}}
%   \put(10,30){\circle{2}}
%   \put(8,30){\makebox(0,0)[br]{1}}
%   \put(20,0){\circle{2}}
%   \put(22,0){\makebox(0,0)[bl]{2}}
%   \put(30,30){\circle{2}}
%   \put(32,30){\makebox(0,0)[bl]{3}}
%   ^^A convex hull
%   \put(0,0){\line(1,0){20}}
%   \put(20,0){\line(1,3){10}}
%   \put(30,30){\line(-1,0){20}}
%   \put(10,30){\line(-1,-3){10}}
%   ^^A control polygon
%   ^^A \put(0,0){\vector(1,3){10}}
%   ^^A \put(10,30){\vector(1,-3){10}}
%   ^^A \put(20,0){\vector(1,3){10}}
%   \thicklines
%  ^^A   \cbezier[30](0,0)(10,30)(20,0)(30,30)
%   \thinlines
%   \end{picture}}
%  ^^A degree 3
% \put(0,45){\begin{picture}(30,30)
%   \thinlines
%   \put(0,0){\circle{2}}
%   \put(-2,0){\makebox(0,0)[br]{0, 3}}
%   \put(30,0){\circle{2}}
%   \put(32,0){\makebox(0,0)[bl]{1}}
%   \put(0,30){\circle{2}}
%   \put(2,30){\makebox(0,0)[bl]{2}}
%   ^^A convex hull
%   \put(0,0){\line(1,0){30}}
%   \put(30,0){\line(-1,1){30}}
%   \put(0,30){\line(0,-1){30}}
%   ^^A control polygon
%   ^^A \put(0,0){\vector(1,0){30}}
%   ^^A \put(30,0){\vector(-1,1){30}}
%   ^^A \put(0,30){\vector(0,-1){30}}
%   \thicklines
%  ^^A \cbezier[30](0,0)(30,0)(0,30)(0,0)
%   \thinlines
%   \end{picture}}
%  ^^A degree 3
% \put(45,0){\begin{picture}(30,30)
%   \thinlines
%   \put(0,0){\circle{2}}
%   \put(-2,0){\makebox(0,0)[br]{0}}
%   \put(10,30){\circle{2}}
%   \put(8,30){\makebox(0,0)[br]{2}}
%   \put(20,0){\circle{2}}
%   \put(22,0){\makebox(0,0)[bl]{3}}
%   \put(30,30){\circle{2}}
%   \put(32,30){\makebox(0,0)[bl]{1}}
%   ^^A convex hull
%   \put(0,0){\line(1,0){20}}
%   \put(20,0){\line(1,3){10}}
%   \put(30,30){\line(-1,0){20}}
%   \put(10,30){\line(-1,-3){10}}
%   ^^A control polygon
%   ^^A \put(0,0){\vector(1,1){30}}
%   ^^A \put(30,30){\vector(-1,0){20}}
%   ^^A \put(10,30){\vector(1,-3){10}}
%   \thicklines
%   ^^A \cbezier(0,0)(30,30)(10,30)(20,0)
%   \thinlines
%   \end{picture}}
% \put(45,45){\begin{picture}(30,30)
%   \thinlines
%   \put(0,0){\circle{2}}
%   \put(-2,0){\makebox(0,0)[br]{0}}
%   \put(30,0){\circle{2}}
%   \put(32,0){\makebox(0,0)[bl]{1}}
%   \put(0,30){\circle{2}}
%   \put(2,30){\makebox(0,0)[bl]{2}}
%   \put(10,10){\circle{2}}
%   \put(8,10){\makebox(0,0)[br]{3}}
%   ^^A convex hull
%   \put(0,0){\line(1,0){30}}
%   \put(30,0){\line(-1,1){30}}
%   \put(0,30){\line(0,-1){30}}
%   ^^A control polygon
%   ^^A \put(0,0){\vector(1,0){30}}
%   ^^A \put(30,0){\vector(-1,1){30}}
%   ^^A \put(0,30){\vector(1,-2){10}}
%   \thicklines
%   ^^A \cbezier(0,0)(30,0)(0,30)(10,10)
%   \thinlines
%   \end{picture}}
% \end{picture}
% \setlength{\unitlength}{1pt}
% \caption{Four sets of points and their convex hulls} \label{fig:ch} 
% \end{figure}
%
%    The equation for cubic Bezier curves is
% \begin{equation}
% p(t) - p_{0} = 3l_{10}t + 3(l_{21} - l_{10})t^{2} + (l_{30} - 3l_{21})t^{3}
%  \label{eq:cubic}
% \end{equation}
%
% \DescribeMacro{\cbezier}
%    The command
% |\cbezier[|\meta{N}|](|\meta{p0}|)(|\meta{p1}|)(|\meta{p2}|)(|\meta{p3}|)|
% draws a cubic Bezier curve, as defined by \eqref{eq:cubic},
% from point \meta{p0} to point \meta{p3}, where \meta{p1} and \meta{p2}
% are the intermediate points defining the control polygon.
% 
% \begin{figure}
% \centering
% \setlength{\unitlength}{1mm}
% \begin{picture}(70,80)
%  ^^A degree 3
% \put(0,5){\begin{picture}(30,30)
%   \thinlines
%   \put(0,0){\circle{2}}
%   \put(-2,0){\makebox(0,0)[br]{0}}
%   \put(10,30){\circle{2}}
%   \put(8,30){\makebox(0,0)[br]{1}}
%   \put(20,0){\circle{2}}
%   \put(22,0){\makebox(0,0)[bl]{2}}
%   \put(30,30){\circle{2}}
%   \put(32,30){\makebox(0,0)[bl]{3}}
%   ^^A convex hull
%   ^^A \put(0,0){\line(1,0){20}}
%   ^^A \put(20,0){\line(1,3){10}}
%   ^^A \put(30,30){\line(-1,0){20}}
%   ^^A \put(10,30){\line(-1,-3){10}}
%   ^^A control polygon
%   \put(0,0){\vector(1,3){10}}
%   \put(10,30){\vector(1,-3){10}}
%   \put(20,0){\vector(1,3){10}}
%   \thicklines
%   \cbezier[30](0,0)(10,30)(20,0)(30,30)
%   \thinlines
%   \end{picture}}
%  ^^A degree 3
% \put(0,45){\begin{picture}(30,30)
%   \thinlines
%   \put(0,0){\circle{2}}
%   \put(-2,0){\makebox(0,0)[br]{0, 3}}
%   \put(30,0){\circle{2}}
%   \put(32,0){\makebox(0,0)[bl]{1}}
%   \put(0,30){\circle{2}}
%   \put(2,30){\makebox(0,0)[bl]{2}}
%   ^^A convex hull
%   ^^A \put(0,0){\line(1,0){30}}
%   ^^A \put(30,0){\line(-1,1){30}}
%   ^^A \put(0,30){\line(0,-1){30}}
%   ^^A control polygon
%   \put(0,0){\vector(1,0){30}}
%   \put(30,0){\vector(-1,1){30}}
%   \put(0,30){\vector(0,-1){30}}
%   \thicklines
%   \cbezier[30](0,0)(30,0)(0,30)(0,0)
%   \thinlines
%   \end{picture}}
%  ^^A degree 3
% \put(45,0){\begin{picture}(30,30)
%   \thinlines
%   \put(0,0){\circle{2}}
%   \put(-2,0){\makebox(0,0)[br]{0}}
%   \put(10,30){\circle{2}}
%   \put(8,30){\makebox(0,0)[br]{2}}
%   \put(20,0){\circle{2}}
%   \put(22,0){\makebox(0,0)[bl]{3}}
%   \put(30,30){\circle{2}}
%   \put(32,30){\makebox(0,0)[bl]{1}}
%   ^^A convex hull
%   ^^A \put(0,0){\line(1,0){20}}
%   ^^A \put(20,0){\line(1,3){10}}
%   ^^A \put(30,30){\line(-1,0){20}}
%   ^^A \put(10,30){\line(-1,-3){10}}
%   ^^A control polygon
%   \put(0,0){\vector(1,1){30}}
%   \put(30,30){\vector(-1,0){20}}
%   \put(10,30){\vector(1,-3){10}}
%   \thicklines
%   \cbezier(0,0)(30,30)(10,30)(20,0)
%   \thinlines
%   \end{picture}}
% \put(45,45){\begin{picture}(30,30)
%   \thinlines
%   \put(0,0){\circle{2}}
%   \put(-2,0){\makebox(0,0)[br]{0}}
%   \put(30,0){\circle{2}}
%   \put(32,0){\makebox(0,0)[bl]{1}}
%   \put(0,30){\circle{2}}
%   \put(2,30){\makebox(0,0)[bl]{2}}
%   \put(10,10){\circle{2}}
%   \put(8,10){\makebox(0,0)[br]{3}}
%   ^^A convex hull
%   ^^A \put(0,0){\line(1,0){30}}
%   ^^A \put(30,0){\line(-1,1){30}}
%   ^^A \put(0,30){\line(0,-1){30}}
%   ^^A control polygon
%   \put(0,0){\vector(1,0){30}}
%   \put(30,0){\vector(-1,1){30}}
%   \put(0,30){\vector(1,-2){10}}
%   \thicklines
%   \cbezier(0,0)(30,0)(0,30)(10,10)
%   \thinlines
%   \end{picture}}
% \end{picture}
% \setlength{\unitlength}{1pt}
% \caption{Four sets of points, the cubic Bezier curves and their control 
%          polygons. Left --- curves plotted with $N=30$; Right ---
%          curves plotted with $N=0$} \label{fig:cp} 
% \end{figure}
% 
%    Figure~\ref{fig:cp} shows four such cubic Bezier curves, their
% defining points and their control polygons. These are the same points
% that were used in figure~\ref{fig:ch} to illustrate convex hulls. It is
% easy to verify that a cubic Bezier curve does indeed lie within the convex
% hull of its defining points. The curves on the left of the figure were
% specified with a value of 30 for the argument \meta{N}, while those
% on the right had no value given for \meta{N} and thus were drawn with
% the number of plotted points calculated by the drawing algorithm.
% The actual drawing commands used were:
% \begin{verbatim}
% \cbezier[30](0,0)(10,30)(20,0)(30,30)
% \cbezier[30](0,0)(30,0)(0,30)(0,0)
% \cbezier(0,0)(30,30)(10,30)(20,0)
% \cbezier(0,0)(30,0)(0,30)(10,10)
% \end{verbatim}
% Note that points are plotted along the curve at equidistant values of the
% of the parameter $t$. However, as the relationship between the actual
% distance in $(x,y)$ coordinate space is a non-linear function of $t$,
% the seperation between the plotted points is non-uniform.
%
% The equation for a \emph{non-rational} quadratic Bezier curve is
% \begin{equation}
% p(t) - p_{0} = 2l_{10}t + (l_{20} - 2l_{10})t^{2} \label{eq:quad}
% \end{equation}
% Using standard \LaTeX{} this can be drawn by the |\qbezier| command.
% There is another form of a quadratic Bezier curve called a \emph{rational}
% quadratic Bezier curve. Its equation is
% \begin{equation}
% p(t) - p_{0} =  \frac^^A
% {2w_{1}l_{10}t + (w_{2}l_{20} - 2w_{1}l_{10})t^{2}}^^A
% {w_{0} + 2\omega_{10}t + (\omega_{20} - \omega_{10})t^{2}}
% \label{eq:rqfull}
% \end{equation}
% where the $w_{i}$ are the \emph{weights} corresponding to the 
% points $p_{i}$ and $\omega_{pq} = w_{p} - w_{q}$. The shape of a 
% non-rational curve can be changed by changing the positions of the defining
% points. The shape of a rational curve can also be modified by changing 
% the values of the weights. A rational curve
% has the same general properties, outlined above, as a non-rational curve
% with the exception that the curve may lie outside the convex hull of the
% control polygon.
%
%    For the purposes at hand, we use a more restricted form of a
% rational quadratic Bezier curve, obtained by putting 
% $W = w_{1}/w_{0}$ and then making
% $w_{0} = w_{2} = 1$ in \eqref{eq:rqfull}. Performing these
% substitutions we end up with
% \begin{equation}
% p(t) - p_{0} =  \frac^^A
% {2Wl_{10}t + (l_{20} - 2Wl_{10})t^{2}}^^A
% {1 + 2(1 - W)t + 2(1 - W)t^{2}}
% \label{eq:rqfinal}
% \end{equation}
% Note that when $W=1$, (\ref{eq:rqfinal}) reduces to \eqref{eq:quad}
% and when $W=0$ it effectively reduces to \eqref{eq:lin3}.
%
%    It turns out that a non-rational quadratic Bezier curve is an arc of
% a parabola, which is one of the conic curves. All the other conic curves
% can be represented by the rational quadratic Bezier curve described
% by \eqref{eq:rqfinal} by suitable choices for the value of $W$.
% From now on, we will call $W$ the \emph{weight} of the rational quadratic
% Bezier curve. Table~\ref{tab:rq} lists the value, or value range,
% of $W$ for the various forms of the conic curve.\footnote{We do not deal
% with the degenerate cases.} For the case of a circle, $\beta$ is the
% angle between the lines $l_{10} = (p_{1} - p_{0})$ and
% $l_{20} = (p_{2} - p_{0})$, as shown in figure~\ref{fig:beta}.
%
% \begin{table}
% \centering
% \caption{Conic forms of the rational quadratic Bezier curve} \label{tab:rq}
% \begin{tabular}{lc} \hline
% Conic form & Weight ($W$) \\ \hline
% Hyperbola & $\|W\| > 1$ \\
% Parabola  & $\|W\| = 1$ \\
% Ellipse   & $0 < \|W\| < 1$ \\
% Circle    & $\|l_{10}\| = \|l_{21}\|$ and $W = \cos \beta$ \\
% Straight line & $W = 0$ \\ \hline
% \end{tabular}
% \end{table}
%
%
% \begin{figure}
% \centering
% \setlength{\unitlength}{1mm}
% \begin{picture}(30,40)
% \put(0,5){\begin{picture}(30,30)
%   \put(0,0){\circle{2}}
%   \put(-2,0){\makebox(0,0)[br]{1}}
%   \put(15,30){\circle{2}}
%   \put(13,30){\makebox(0,0)[br]{0}}
%   \put(30,0){\circle{2}}
%   \put(32,0){\makebox(0,0)[bl]{2}}
%   ^^A polygon
%   \thicklines
%   \put(15,30){\vector(-1,-2){15}}
%   \put(0,0){\vector(1,0){30}}
%   ^^A dashed line from 0 to 2
%   ^^A \lbezier(15,30)(30,0)
%   \lbezier[50](15,30)(30,0)
%   \thinlines
%   \put(15,26){\makebox(0,0){$\beta$}}
%   \end{picture}}
% \end{picture}
% \setlength{\unitlength}{1pt}
% \caption{The angle $\beta$} \label{fig:beta}
% \end{figure}
%
% \DescribeMacro{\rqbezier}
% The command
% |\rqbezier[|\meta{N}|](|\meta{p0}|)(|\meta{p1}|)(|\meta{p2}|)(|\meta{W}|)|
% draws a rational quadratic Bezier curve from \meta{p0} to \meta{p2} with
% weight \meta{W}, according to \eqref{eq:rqfinal}. As in the
% other Bezier commands, \meta{N} is optional and controls the number
% of plotted points along the curve. Figure~\ref{fig:qrb} shows several
% rational quadratic curves, all with the same control polygon but with
% differing values for the weight $W$. The code is:
% \begin{verbatim}
%   \rqbezier[100](15,30)(0,0)(30,0)(4)
%   \rqbezier[100](15,30)(0,0)(30,0)(2)
%   \rqbezier(15,30)(0,0)(30,0)(1)
%   \rqbezier[100](15,30)(0,0)(30,0)(0.75)
%   \rqbezier[100](15,30)(0,0)(30,0)(0.5)
%   \rqbezier[100](15,30)(0,0)(30,0)(0.25)
%   \rqbezier(15,30)(0,0)(30,0)(0)
% \end{verbatim}
% When $W > 1$ the curve is pulled toward the point $p_{1}$. Conversely,
% when $W < 1$ the curve is pushed away from the point $p_{1}$. In all
% cases, though, the curve starts and stops at $p_{0}$ and $p_{2}$
% respectively.
%
% \begin{figure}
% \centering
% \setlength{\unitlength}{1mm}
% \begin{picture}(30,40)
% \put(0,5){\begin{picture}(30,30)
%   \put(0,0){\circle{2}}
%   \put(-2,0){\makebox(0,0)[br]{1}}
%   \put(15,30){\circle{2}}
%   \put(13,30){\makebox(0,0)[br]{0}}
%   \put(30,0){\circle{2}}
%   \put(32,0){\makebox(0,0)[bl]{2}}
%   ^^A polygon
%   \thinlines
%   \put(15,30){\vector(-1,-2){15}}
%   \put(0,0){\vector(1,0){30}}
%   ^^A dashed line from 0 to 2
%   ^^A \lbezier(15,30)(30,0)
%   ^^A \lbezier[50](15,30)(30,0)
%   ^^A \thinlines
%   ^^A \put(15,26){\makebox(0,0){$\beta$}}
%   \thicklines
%   \rqbezier[100](15,30)(0,0)(30,0)(4)
%   \rqbezier[100](15,30)(0,0)(30,0)(2)
%   \rqbezier(15,30)(0,0)(30,0)(1)
%   \rqbezier[100](15,30)(0,0)(30,0)(0.75)
%   \rqbezier[100](15,30)(0,0)(30,0)(0.5)
%   \rqbezier[100](15,30)(0,0)(30,0)(0.25)
%   \rqbezier(15,30)(0,0)(30,0)(0)
%   \end{picture}}
% \end{picture}
% \setlength{\unitlength}{1pt}
% \caption{The effect of weight variation ($W \geq 0$)
%          on rational quadratic Bezier curves
%          (\texttt{weightscale = \theweightscale} (the default)) } 
% \label{fig:qrb}
% \end{figure}
%
% Like the case of the cubic curve, points are plotted at equidistant
% values of the parameter $t$. The relationship between parameter value
% and coordinate positions in the rational case are highly non-linear.
% Thus the distance between the plotted points can vary quite remarkably.
% This is an inherent disadvantage with this type of curve. The user's remedy
% is to increase the number of points to be plotted, but this can lead to
% \TeX{} running out of memory, not to mention the increased time to
% generate the drawing.
%
% \DescribeMacro{\setweightscale}
% \DescribeMacro{\resetweightscale}
%    Because of the way in which \TeX{} performs arithmetic, and especially
% division, it 
% is necessary to perform some scaling operations on the divisor when
% evaluating \eqref{eq:rqfinal}. The optimum value for the
% scaling is a complex function of the weight and the size and orientation
% of the control polygon. The algorithm uses a heuristic approach to
% calculate a `good' value but is not always successful. The 
% |\setweightscale{|\meta{number}|}| command can be used to specify
% a scale factor. \meta{number} must be a positive integer. The
% |\resetweightscale| command resets the scale factor to its default
% value, which is currently 10000 (ten thousand).
%
% \begin{figure}
% \centering
% \setlength{\unitlength}{1mm}
% \begin{picture}(70,80)
% \put(0,5){\begin{picture}(30,30)
%   \put(0,0){\circle{2}}
%   \put(-2,0){\makebox(0,0)[br]{1}}
%   \put(15,30){\circle{2}}
%   \put(13,30){\makebox(0,0)[br]{0}}
%   \put(30,0){\circle{2}}
%   \put(32,0){\makebox(0,0)[bl]{2}}
%   ^^A polygon
%   \thinlines
%   ^^A \put(15,30){\vector(-1,-2){15}}
%   ^^A \put(0,0){\vector(1,0){30}}
%   ^^A dashed line from 0 to 2
%   ^^A \lbezier(15,30)(30,0)
%   ^^A \lbezier[50](15,30)(30,0)
%   ^^A \thinlines
%   ^^A \put(15,26){\makebox(0,0){$\beta$}}
%   \thicklines
%   \setweightscale{100}
%   \rqbezier[100](15,30)(0,0)(30,0)(4)
%   \rqbezier[100](15,30)(0,0)(30,0)(2)
%   \rqbezier(15,30)(0,0)(30,0)(1)
%   \rqbezier[100](15,30)(0,0)(30,0)(0.75)
%   \rqbezier[100](15,30)(0,0)(30,0)(0.5)
%   \rqbezier[100](15,30)(0,0)(30,0)(0.25)
%   \rqbezier(15,30)(0,0)(30,0)(0)
%   \put(15,-5){\makebox(0,0)[b]{\texttt{weightscale = \theweightscale}}}
%   \end{picture}}
% \put(0,45){\begin{picture}(30,30)
%   \put(0,0){\circle{2}}
%   \put(-2,0){\makebox(0,0)[br]{1}}
%   \put(15,30){\circle{2}}
%   \put(13,30){\makebox(0,0)[br]{0}}
%   \put(30,0){\circle{2}}
%   \put(32,0){\makebox(0,0)[bl]{2}}
%   ^^A polygon
%   \thinlines
%   ^^A \put(15,30){\vector(-1,-2){15}}
%   ^^A \put(0,0){\vector(1,0){30}}
%   ^^A dashed line from 0 to 2
%   ^^A \lbezier(15,30)(30,0)
%   ^^A \lbezier[50](15,30)(30,0)
%   ^^A \thinlines
%   ^^A \put(15,26){\makebox(0,0){$\beta$}}
%   \thicklines
%   \setweightscale{1000}
%   \rqbezier[100](15,30)(0,0)(30,0)(4)
%   \rqbezier[100](15,30)(0,0)(30,0)(2)
%   \rqbezier(15,30)(0,0)(30,0)(1)
%   \rqbezier[100](15,30)(0,0)(30,0)(0.75)
%   \rqbezier[100](15,30)(0,0)(30,0)(0.5)
%   \rqbezier[100](15,30)(0,0)(30,0)(0.25)
%   \rqbezier(15,30)(0,0)(30,0)(0)
%   \put(15,-5){\makebox(0,0)[b]{\texttt{weightscale = \theweightscale}}}
%   \end{picture}}
% \put(45,5){\begin{picture}(30,30)
%   \put(0,0){\circle{2}}
%   \put(-2,0){\makebox(0,0)[br]{1}}
%   \put(15,30){\circle{2}}
%   \put(13,30){\makebox(0,0)[br]{0}}
%   \put(30,0){\circle{2}}
%   \put(32,0){\makebox(0,0)[bl]{2}}
%   ^^A polygon
%   \thinlines
%   ^^A \put(15,30){\vector(-1,-2){15}}
%   ^^A \put(0,0){\vector(1,0){30}}
%   ^^A dashed line from 0 to 2
%   ^^A \lbezier(15,30)(30,0)
%   ^^A \lbezier[50](15,30)(30,0)
%   ^^A \thinlines
%   ^^A \put(15,26){\makebox(0,0){$\beta$}}
%   \thicklines
%   \resetweightscale
%   \rqbezier[100](15,30)(0,0)(30,0)(4)
%   \rqbezier[100](15,30)(0,0)(30,0)(2)
%   \rqbezier(15,30)(0,0)(30,0)(1)
%   \rqbezier[100](15,30)(0,0)(30,0)(0.75)
%   \rqbezier[100](15,30)(0,0)(30,0)(0.5)
%   \rqbezier[100](15,30)(0,0)(30,0)(0.25)
%   \rqbezier(15,30)(0,0)(30,0)(0)
%   \put(15,-5){\makebox(0,0)[b]{\texttt{weightscale = \theweightscale}}}
%   \end{picture}}
% \put(45,45){\begin{picture}(30,30)
%   \put(0,0){\circle{2}}
%   \put(-2,0){\makebox(0,0)[br]{1}}
%   \put(15,30){\circle{2}}
%   \put(13,30){\makebox(0,0)[br]{0}}
%   \put(30,0){\circle{2}}
%   \put(32,0){\makebox(0,0)[bl]{2}}
%   ^^A polygon
%   \thinlines
%   ^^A \put(15,30){\vector(-1,-2){15}}
%   ^^A \put(0,0){\vector(1,0){30}}
%   ^^A dashed line from 0 to 2
%   ^^A \lbezier(15,30)(30,0)
%   ^^A \lbezier[50](15,30)(30,0)
%   ^^A \thinlines
%   ^^A \put(15,26){\makebox(0,0){$\beta$}}
%   \thicklines
%   \setweightscale{100000}
%   \rqbezier[100](15,30)(0,0)(30,0)(4)
%   \rqbezier[100](15,30)(0,0)(30,0)(2)
%   \rqbezier(15,30)(0,0)(30,0)(1)
%   \rqbezier[100](15,30)(0,0)(30,0)(0.75)
%   \rqbezier[100](15,30)(0,0)(30,0)(0.5)
%   \rqbezier[100](15,30)(0,0)(30,0)(0.25)
%   \rqbezier(15,30)(0,0)(30,0)(0)
%   \put(15,-5){\makebox(0,0)[b]{\texttt{weightscale = \theweightscale}}}
%   \end{picture}}
% \end{picture}
% \setlength{\unitlength}{1pt}
% \resetweightscale
% \caption{The effect of \texttt{weightscale} on the drawing
%          of rational quadratic Bezier curves}
% \label{fig:qrw}
% \end{figure}
%
%    Figure~\ref{fig:qrw} illustrates the effect on changing the 
% \texttt{weightscale} used for drawing the same curves as shown
% in figure~\ref{fig:qrb}. Note that the \texttt{weightscale}
%  has no effect when
% $W = 1$ or $W = 0$ as in these cases the curves are drawn using the
% algorithms for the |\qbezier| and |\lbezier| commands respectively.
%
%    It is obvious that some choices give very poorly formed curves. In
% other cases the curves may be poorly formed but do result in interesting
% cross-stitch like patterns.
%
%    Table~\ref{tab:rq} indicates that it is possible to draw circular
% arcs using a rational quadratic Bezier curves. The two legs of the
% control polygon define the tangents to the curve at the
% end points.
% Therefore, to draw a circular arc the two legs must be equal in length.
% That is, the convex hull is an isosceles triangle. In the special case
% when the convex hull forms an equilateral triangle, the required
% weight ($\cos \beta$, see figure~\ref{fig:beta}) for drawing a circular 
% arc is $\cos \beta = 0.5$. Further,
% for any given control polygon the the curves drawn with weights of
% $\pm W$ are complementary. That is, the curve with weight $-W$ is
% the `remainder' of the curve drawn with weight $W$. Thus, we have a
% simple means of drawing a complete circle, as shown in figure~\ref{fig:qrc}.
% The plotting commands of interest were:
% \begin{verbatim}
%     \lbezier[25](0,0)(15,26)
%     \lbezier[25](0,0)(30,0)
%     \setweightscale{50000}
%     \rqbezier[100](15,26)(0,0)(30,0)(0.5)
%     \rqbezier[200](15,26)(0,0)(30,0)(-0.5)
%     \resetweightscale
% \end{verbatim}
% where the |\lbezier| drawing commands were used to draw the dotted outline
% of the control polygon.
%
% \begin{figure}
% \centering
% \setlength{\unitlength}{1mm}
% \setweightscale{50000}
% \begin{picture}(60,62)
%   \put(0,5){\begin{picture}(30,30)
%     \thinlines
%     \put(0,0){\circle{2}}
%     \put(-2,0){\makebox(0,0)[br]{1}}
%     \put(15,26){\circle{2}}
%     \put(13,26){\makebox(0,0)[br]{0}}
%     \put(30,0){\circle{2}}
%     \put(32,0){\makebox(0,0)[bl]{2}}
%     ^^A polygon
%     \lbezier[25](0,0)(15,26)
%     \lbezier[25](0,0)(30,0)
%     ^^A RQBEZIER
%     \thicklines
%     \rqbezier[100](15,26)(0,0)(30,0)(0.5)
%     \rqbezier[200](15,26)(0,0)(30,0)(-0.5)
%     \end{picture}}
%   \end{picture}
% \setlength{\unitlength}{1pt}
% \caption{Rational quadratics with weights of $\pm 0.5$ and an equilateral
%          triangular convex hull
%          (\texttt{weightscale = \theweightscale}) } \label{fig:qrc}
% \resetweightscale
% \end{figure}
%
%    A more robust picture of the same circle is shown in 
% figure~\ref{fig:qr3c} where the complete circle is pieced together from
% three non-complementary circular arcs. The drawing commands of interest
% were
% \begin{verbatim}
%     \rqbezier[100](15,26)(0,0)(30,0)(0.5)
%     \rqbezier[100](30,0)(60,0)(45,26)(0.5)
%     \rqbezier[100](45,26)(30,52)(15,26)(0.5)
% \end{verbatim}
%
% \begin{figure}
% \centering
% \setlength{\unitlength}{1mm}
% \begin{picture}(60,62)
%   \put(0,5){\begin{picture}(60,52)
%     \thinlines
%     \put(0,0){\circle{2}}
% ^^A    \put(-2,0){\makebox(0,0)[br]{1}}
%     \put(15,26){\circle{2}}
% ^^A    \put(13,30){\makebox(0,0)[br]{0}}
%     \put(30,0){\circle{2}}
% ^^A    \put(32,0){\makebox(0,0)[bl]{2}}
%     \put(60,0){\circle{2}}
%     \put(45,26){\circle{2}}
%     \put(30,52){\circle{2}}
%     ^^A polygon
%     \lbezier[50](0,0)(30,52)
%     \lbezier[50](30,52)(60,0)
%     \lbezier[50](0,0)(60,0)
%     ^^A RQBEZIER
%     \thicklines
%     \rqbezier[100](15,26)(0,0)(30,0)(0.5)
%     \rqbezier[100](30,0)(60,0)(45,26)(0.5)
%     \rqbezier[100](45,26)(30,52)(15,26)(0.5)
%     \end{picture}}
%   \end{picture}
% \setlength{\unitlength}{1pt}
% \caption{Three rational quadratics with weights of $0.5$ 
%          (\texttt{weightscale = \theweightscale}) }
% \label{fig:qr3c}
% \end{figure}
%
%    The astute reader will have realised that the divisor in 
% \eqref{eq:rqfinal} can go to zero, and can even be negative.
% This has interesting consequences, both when trying to do computer
% arithmetic, and also on the the kind of curve that results. Essentially,
% the curve tends to $\infty$ as $W \rightarrow +0$. At $W = -0$ the curve
% is at $-\infty$ and then it tends to $-0$ as $W \rightarrow -\infty$.
% We will get a curve point at $\infty$ whenever $W = -1$ and a `negative'
% curve for $W < -1$. 
%
% \begin{figure}
% \centering
% \setlength{\unitlength}{1mm}
% \begin{picture}(60,60)
%   \put(30,20){\begin{picture}(30,20)
%     \thinlines
%     \put(0,10){\circle{2}}
%     \put(30,0){\circle{2}}
%     \put(30,20){\circle{2}}
%     ^^A polygon
%     \lbezier[25](30,20)(0,10)
%     \lbezier[25](0,10)(30,0)
%     ^^A RQBEZIER
%     \thicklines
%     \rqbezier[100](30,20)(0,10)(30,0)(2)
%     \rqbezier[100](30,20)(0,10)(30,0)(-2)
%     \end{picture}}
%   \end{picture}
% \setlength{\unitlength}{1pt}
% \caption{A rational quadratic that has gone negative; weights of $\pm 2$ 
%          (\texttt{weightscale = \theweightscale}) }
% \label{fig:neg}
% \end{figure}
%
% This effect is shown in figure~\ref{fig:neg} which draws the two branches
% of a hyperbola. The basic code for the illustration was
% \begin{verbatim}
%     \lbezier[25](30,20)(0,10)
%     \lbezier[25](0,10)(30,0)
%     \rqbezier[100](30,20)(0,10)(30,0)(2)
%     \rqbezier[100](30,20)(0,10)(30,0)(-2)
% \end{verbatim}
% where the control polygon was drawn using the |\lbezier| commands.
%
%
% \section{The \Lpack{bez123} package implementation} \label{sec:bez}
%
%    \LaTeX{} provides a facility for drawing quadratic Bezier curves.
% This package provides additional facilities for drawing linear, 
% rational quadratic, and cubic Bezier curves. 
%
%
% Announce the name and version of the package, which requires \LaTeXe.
%    \begin{macrocode}
%<*bez>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bez123}[2009/09/02 v1.1b Bezier curves]
%    \end{macrocode}
% \changes{v1.1}{1998/10/14}{Added call to include multiply package}
%    The package also requires the \Lpack{multiply} package.
%    \begin{macrocode}
\RequirePackage{multiply}[2009/09/02]
%</bez>
%    \end{macrocode}
%
%
% \subsection{Arithmetic in \TeX}
%
%    All arithmetic in \TeX{} is based on integer arithmetic, with a
% maximum integer value of $M = \number\maxdimen$. For example,
% \setcounter{weightscale}{8}\makeatletter\divide\c@weightscale by 3\makeatother
% $8/3 = \theweightscale$,
% \setcounter{weightscale}{9}\makeatletter\divide\c@weightscale by 3\makeatother
% $9/3 = \theweightscale$, and
% \setcounter{weightscale}{10}\makeatletter\divide\c@weightscale by 3\makeatother
% $10/3 = \theweightscale$.
% In other words, division always reduces the absolute value of the dividend,
% and also possibly truncates the value. One consequence of this is that the
% ordering of multiplication and division is important. For instance,
% \setcounter{weightscale}{8}\makeatletter\multiply\c@weightscale by 3 \divide\c@weightscale by 3\makeatother
% $(8 \times 3)/3 = \theweightscale$ but
% \setcounter{weightscale}{8}\makeatletter\divide\c@weightscale by 3 \multiply\c@weightscale by 3\makeatother
% $(8/3) \times 3 = \theweightscale$!
% Thus, in arithmetic calculations involving both multiplication and
% division, the dividend should be maximised and the divisor minimised,
% with multiplication preceeding division; also remembering that there
% is a limit on the size of an integer. To avoid multiplication overflow
% when calculating say, $a \times b$, we must ensure that 
% $\|a\| \leq \|M/b\|$.
%
%    When calculating polynomials, such as that in \eqref{eq:gen},
% we use a technique called Horner's schema, which is also known as nested
% multiplication. A general cubic equation, for example, can be written as:
% \begin{equation}
% p(t) - a_{0} = t(a_{1} + t(a_{2} + ta_{3})) \label{eq:horn}
% \end{equation}
% The following pseudo-code shows one way to implement Horner's schema for
% plotting $N$ points in the interval $0 \leq t \leq 1$
% of \eqref{eq:horn} using integer arithmetic.
% \begin{verbatim}
% procedure plot_cubic(a0, a1, a2, a3:vector; N:integer);
%   local p:vector; end_local;
%   a3 := a3/N;
%   repeat i := 0 to N by 1;
%     p := a3*i;
%     p := p + a2; p := p/N; p := p*i;
%     p := p + a1; p := p/N; p := p*i;
%     draw(p + a0);
%   end_repeat;
%   return;
% end_procedure;
% \end{verbatim}
% We use the above algorithm, with suitable modifications according to the
% degree of the polynomial, for plotting the points along Bezier curves.
%
% \subsection{Linear Bezier curves}
%
%    \begin{macrocode}
%<*bez>
%    \end{macrocode}
%
%    As a linear curve is simpler than a quadratic curve there is no
% need to declare extra variables from those used in the kernel by the
% |\qbezier| macro.
%
% \begin{macro}{\lbezier}
%    The user command to draw a linear Bezier curve represented by
% \eqref{eq:lin3}. The form of the command is:\\
% |\lbezier[|\meta{N}|]{(|\meta{p0}|)(|\meta{p1}|)| \\
% where \meta{pN} is the comma seperated X and Y coordinate values of
% point \textit{pN}.
%
%    \begin{macrocode}
\newcommand{\lbezier}[2][0]{\@lbez{#1}#2}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@lbez}
%    The drawing macro.
%    \begin{macrocode}
\gdef\@lbez#1(#2,#3)(#4,#5){%
%%%%\def\lbezier#1(#2,#3)(#4,#5){%
  \ifnum #1<\@ne
%    \end{macrocode}
%    When the number of plotting points are not given, then we calculate
% how many are needed. First determine the X distance between the end points.
%    \begin{macrocode}
    \@ovxx = #4\unitlength
      \advance\@ovxx by -#2\unitlength
      \ifdim \@ovxx < \z@
        \@ovxx = -\@ovxx
      \fi
%    \end{macrocode}
% Similarly calculate the Y distance.
%    \begin{macrocode}
    \@ovyy = #5\unitlength
      \advance\@ovyy by -#3\unitlength
      \ifdim \@ovyy < \z@
        \@ovyy = -\@ovyy
      \fi
%    \end{macrocode}
% Temporarily store the maximum distance in |\@multicnt|.
%    \begin{macrocode}
    \ifdim \@ovxx > \@ovyy
      \@multicnt = \@ovxx
    \else
      \@multicnt = \@ovyy
    \fi
%    \end{macrocode}
% We use a small square as the visual representation of a point.
% Calculate the number of points required to give 50\% overlap of adjacent
% squares, making
% sure that it doesn't exceed the limit. Store the result in |\@multicnt|.
%    \begin{macrocode}
    \@ovxx = 0.5\@halfwidth
    \divide\@multicnt by \@ovxx
    \ifnum \qbeziermax < \@multicnt
      \@multicnt = \qbeziermax\relax
    \fi
  \else
%    \end{macrocode}
% The number of points is given.
%    \begin{macrocode}
    \@multicnt = #1\relax
  \fi
%    \end{macrocode}
% 
%    Now we can prepare the constants for the plotting loop.
%    \begin{macrocode}
  \@tempcnta = \@multicnt
  \advance\@tempcnta by \@ne
  \@ovdx = #4\unitlength
    \advance\@ovdx by -#2\unitlength
    \divide\@ovdx by \@multicnt
  \@ovdy = #5\unitlength
    \advance\@ovdy by -#3\unitlength
    \divide\@ovdy by \@multicnt
%    \end{macrocode}
% The next bit of code defines the size of the square representing a point.
%    \begin{macrocode}
  \setbox\@tempboxa\hbox{\vrule \@height\@halfwidth
                                \@depth \@halfwidth
                                \@width \@wholewidth}%
%    \end{macrocode}
% Start the plot at the first point.
%    \begin{macrocode}
  \put(#2,#3){%
    \count@ = \z@
    \@whilenum{\count@ < \@tempcnta}\do
%    \end{macrocode}
% Evaluate the polynomial (simple in this case) using Horner's schema.
%    \begin{macrocode}
      {\@xdim = \count@\@ovdx
       \@ydim = \count@\@ovdy
%    \end{macrocode}
% Plot this point.
%    \begin{macrocode}
       \raise \@ydim
         \hb@xt@\z@{\kern\@xdim
                    \unhcopy\@tempboxa\hss}%
       \advance\count@\@ne}}%
%    \end{macrocode}
%  The end of the definition of |\@lbez|.
%    \begin{macrocode}
}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Cubic Bezier curves}
%
%    As cubic curves are more complex than quadratic curves we need some
% extra variables.
% \begin{macro}{\@wxc}
% \begin{macro}{\@wyc}
%    Lengths.
%    \begin{macrocode}
\newlength{\@wxc}
\newlength{\@wyc}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cbezier}
%    The user command for drawing a cubic Bezier curve as represented
% by \eqref{eq:cubic}. It is called as: \\
% |\cbezier[|\meta{N}|](|\meta{p0}|)(|\meta{p1}|)(|\meta{p2}|)(|\meta{p3}|)|.
%
%    \begin{macrocode}
\newcommand{\cbezier}[2][0]{\@cbez{#1}#2}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@cbez}
%    The drawing macro for cubic Bezier curves.
%    \begin{macrocode}
\gdef\@cbez#1(#2,#3)(#4,#5)(#6,#7)(#8,#9){%
  \ifnum #1<\@ne
%    \end{macrocode}
%    We have to calculate the number of plotting points required. We will
% use the maximum of the box enclosing the convex hull as a measure.
% First do the X value, using |\@ovxx| to store the maximum X coordinate
% and |\@ovdx| the minimum.
%    \begin{macrocode}
    \@ovxx = #2\unitlength
    \@ovdx = \@ovxx
    \@ovdy = #4\unitlength
    \ifdim \@ovdy > \@ovxx
      \@ovxx = \@ovdy
    \fi
    \ifdim \@ovdy < \@ovdx
      \@ovdx = \@ovdy
    \fi
    \@ovdy = #6\unitlength
    \ifdim \@ovdy > \@ovxx
      \@ovxx = \@ovdy
    \fi
    \ifdim \@ovdy < \@ovdx
      \@ovdx = \@ovdy
    \fi
    \@ovdy = #8\unitlength
    \ifdim \@ovdy > \@ovxx
      \@ovxx = \@ovdy
    \fi
    \ifdim \@ovdy < \@ovdx
      \@ovdx = \@ovdy
    \fi
%    \end{macrocode}
% Store the maximum X in |\@ovxx|.
%    \begin{macrocode}
    \advance\@ovxx by -\@ovdx
%    \end{macrocode}
% Repeat the process for the maximum Y value, finally storing 
% this in |\@ovyy|.
%    \begin{macrocode}
    \@ovyy = #3\unitlength
    \@ovdy = \@ovyy
    \@ovdx = #5\unitlength
    \ifdim \@ovdx > \@ovyy
      \@ovyy = \@ovdx
    \fi
    \ifdim \@ovdx < \@ovdy
      \@ovdy = \@ovdx
    \fi
    \@ovdx = #7\unitlength
    \ifdim \@ovdx > \@ovyy
      \@ovyy = \@ovdx
    \fi
    \ifdim \@ovdx < \@ovdy
      \@ovdy = \@ovdx
    \fi
    \@ovdx = #9\unitlength
    \ifdim \@ovdx > \@ovyy
      \@ovyy = \@ovdx
    \fi
    \ifdim \@ovdx < \@ovdy
      \@ovdy = \@ovdx
    \fi
    \advance\@ovyy by -\@ovdy
%    \end{macrocode}
% Temporarily store the max of X and Y in |\@multicnt|.
%    \begin{macrocode}
    \ifdim \@ovxx > \@ovyy
      \@multicnt = \@ovxx
    \else
      \@multicnt = \@ovyy
    \fi
%    \end{macrocode}
% Calculate the number of points required to give 50\% overlap, making
% sure that it doesn't exceed the limit. Store the number of points in
% |\@multicnt|.
%    \begin{macrocode}
    \@ovxx = 0.5\@halfwidth
    \divide\@multicnt by \@ovxx
    \ifnum \qbeziermax < \@multicnt
      \@multicnt = \qbeziermax\relax
    \fi
  \else
%    \end{macrocode}
% The number of points is given.
%    \begin{macrocode}
    \@multicnt = #1\relax
  \fi
%    \end{macrocode}
%
%    Now we can prepare the constants for the plotting loop. First the control
% counts.
%    \begin{macrocode}
  \@tempcnta = \@multicnt
  \advance\@tempcnta by \@ne
%    \end{macrocode}
% Then the cubic coefficients, firstly for X.
%    \begin{macrocode}
  \@ovdx = #4\unitlength  \advance\@ovdx by -#2\unitlength
  \@ovxx = #6\unitlength  \advance\@ovxx by -\@ovdx
  \multiply\@ovdx by \thr@@
  \advance\@ovxx by -#4\unitlength  \multiply\@ovxx by \thr@@
  \@wxc = #4\unitlength  \advance\@wxc by -#6\unitlength
  \multiply\@wxc by \thr@@  \advance\@wxc by #8\unitlength
  \advance\@wxc by -#2\unitlength \divide\@wxc by \@multicnt
%    \end{macrocode}
% And similarly for Y.
%    \begin{macrocode}
  \@ovdy = #5\unitlength  \advance\@ovdy by -#3\unitlength
  \@ovyy = #7\unitlength  \advance\@ovyy by -\@ovdy
  \multiply\@ovdy by \thr@@
  \advance\@ovyy by -#5\unitlength  \multiply\@ovyy by \thr@@
  \@wyc = #5\unitlength  \advance\@wyc by -#7\unitlength
  \multiply\@wyc by \thr@@  \advance\@wyc by #9\unitlength
  \advance\@wyc by -#3\unitlength \divide\@wyc by \@multicnt
%    \end{macrocode}
% Set up the plotting box.
%    \begin{macrocode}
  \setbox\@tempboxa\hbox{\vrule \@height\@halfwidth
                                \@depth \@halfwidth
                                \@width \@wholewidth}%
%    \end{macrocode}
% Start the plot at the first point.
%    \begin{macrocode}
  \put(#2,#3){%
    \count@ = \z@
    \@whilenum{\count@ < \@tempcnta}\do
      {\@xdim = \count@\@wxc
         \advance\@xdim by \@ovxx
         \divide\@xdim by \@multicnt
         \multiply\@xdim by \count@
         \advance\@xdim by \@ovdx
         \divide\@xdim by \@multicnt
         \multiply\@xdim by \count@
       \@ydim = \count@\@wyc
         \advance\@ydim by \@ovyy
         \divide\@ydim by \@multicnt
         \multiply\@ydim by \count@
         \advance\@ydim by \@ovdy
         \divide\@ydim by \@multicnt
         \multiply\@ydim by \count@
%    \end{macrocode}
% Plot the point.
%    \begin{macrocode}
       \raise \@ydim
         \hb@xt@\z@{\kern\@xdim
                    \unhcopy\@tempboxa\hss}%
       \advance\count@\@ne}}% 
%    \end{macrocode}
% The end of the definition of |\@cbez|.
%    \begin{macrocode}
}
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Quadratic rational Bezier curve}
%
%    This is the most complex of the Bezier curves that we deal with. 
% We need yet more variables.
%
% \begin{macro}{\@ww}
% \begin{macro}{\@wwa}
% \begin{macro}{\@wwb}
% \begin{macro}{\@wwo}
% \begin{macro}{\@wwi}
% Variables for the weight calculations.
%    \begin{macrocode}
\newlength{\@ww}
\newlength{\@wwa}
\newlength{\@wwb}
\newlength{\@wwo}
\newlength{\@wwi}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\c@@pntscale}
% Scale factor for points.
%    \begin{macrocode}
\newcounter{@pntscale}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\c@weightscale}
% Scale factor for divisor.
%    \begin{macrocode}
\newcounter{weightscale}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\botscale}
% Scale factor for bottom weights.
%    \begin{macrocode}
\newlength{\botscale}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\setweightscale}
% User level command |\setweightscale{|\meta{number}|}| for setting the
% divisor scaling.
%    \begin{macrocode}
\newcommand{\setweightscale}[1]{\setcounter{weightscale}{#1}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\resetweightscale}
% User level command for setting the divisor scaling to its default
% value ($10^{4}$). We also ensure that the scaling is set to this value.
%    \begin{macrocode}
\newcommand{\resetweightscale}{\setcounter{weightscale}{10000}}
\resetweightscale
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\rqbezier}
%    The user level command for drawing a rational quadratic Bezier curve
% as represented by \eqref{eq:rqfinal}. The form of the command is \\
% |\rqbezier[|\meta{N}|](|\meta{p0}|)(|\meta{p1}|)(|\meta{p2}|)(|\meta{W}|)| \\
% where the arguments are as per the other Bezier drawing commands, but with
% the final argument being the weight.
%
%    \begin{macrocode}
\newcommand{\rqbezier}[2][0]{\@rqbez{#1}#2}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@rqbez}
%    The drawing macro for a rational quadratic Bezier curve. If the weight
% is such that the curve is either rational quadratic ($W = 1$) or 
% linear ($W = 0$), we use the simpler drawing macro.
%    \begin{macrocode}
\gdef\@rqbez#1(#2,#3)(#4,#5)(#6,#7)(#8){%
  \@ovxx = #8\unitlength
  \ifdim\@ovxx = \unitlength
    \PackageWarning{bez123}{Rational quadratic denerates to quadratic}
    \qbezier[#1](#2,#3)(#4,#5)(#6,#7)
  \else
    \ifdim\@ovxx = \z@
      \PackageWarning{bez123}{Rational quadratic degenerates to linear}
      \lbezier[#1](#2,#3)(#6,#7)
    \else
%    \end{macrocode}
% Calculate the maximum length of the control polygon's bounding box.
% Store the result in |\@wwi|.
%    \begin{macrocode}
    \@ovxx = #4\unitlength
      \advance\@ovxx by -#2\unitlength
      \ifdim \@ovxx < \z@
        \@ovxx = -\@ovxx
      \fi
    \@ovdx = #6\unitlength
      \advance\@ovdx by -#4\unitlength
      \ifdim \@ovdx < \z@
        \@ovdx = -\@ovdx
      \fi
    \ifdim \@ovxx < \@ovdx
      \@ovxx = \@ovdx
    \fi
    \@ovyy = #5\unitlength
      \advance\@ovyy by -#3\unitlength
      \ifdim \@ovyy < \z@
        \@ovyy = -\@ovyy
      \fi
    \@ovdy = #7\unitlength
      \advance\@ovdy by -#5\unitlength
      \ifdim \@ovdy < \z@
        \@ovdy = -\@ovdy
      \fi
    \ifdim \@ovyy < \@ovdy
      \@ovyy = \@ovdy
    \fi
    \ifdim \@ovxx > \@ovyy
      \@multicnt = \@ovxx
    \else
      \@multicnt = \@ovyy
    \fi
    \@wwi = \@multicnt sp
%    \end{macrocode}
% Now determine the number of points to be plotted.
%    \begin{macrocode}
  \ifnum #1<\@ne
    \@ovxx = 0.5\@halfwidth
    \divide\@multicnt by \@ovxx
    \ifnum\qbeziermax < \@multicnt
      \@multicnt = \qbeziermax\relax
    \fi
  \else
%    \end{macrocode}
% Number of points is a given.
%    \begin{macrocode}
    \@multicnt = #1\relax
  \fi
%    \end{macrocode}
% We are going to plot the curve in two halves in an attempt to reduce 
% roundoff problems. At
% a minimum this should at least make a symmetrical curve look symmetric
% about its mid point.
%    \begin{macrocode}
  \@tempcnta = \@multicnt
  \advance\@tempcnta by \@ne
  \divide\@tempcnta by \tw@
  \advance\@tempcnta by \@ne
%    \end{macrocode}
% We now have to deal with a possible multiplication overflow problem due
% to multiplication by the weight. In \eqref{eq:rqfinal} the potentially
% largest term is the coefficient of $t^{2}$ (i.e., $(l_{20}-2Wl_{10})$).
% The maximum length likely to be encountered is, say, 10 inches for a
% drawing on either A4 or US letterpaper. This is approximately 
% $4.8\times10^{8}$sp. Doing a little arithmetic, and remembering that the
% maximum length in \TeX{} is $M = \number\maxdimen$sp, it means that we must
% have $\|W\| \leq 1$ to prevent overflow. However, a typical range for
% $W$ is $-10 \leq W \leq 10$. Therefore we might have to do some scaling.
% Being pessimistic, we'll assume that $l_{20} = - l_{10}$ and that $l_{10}$
% is the largest dimension in the drawing. To prevent overflow we then have to
% meet the condition $\|W\| \leq (M - l_{20})/2l_{20}$, where all lengths are
% positive. We will use |\c@@pntscale| as a scale factor on $W$ to meet this
% condition. Earlier we set |\@wwi| to be the positive value of the largest
% dimension in the drawing.
%
% Set the distance scale factor. First evaluating the test condition.
%    \begin{macrocode}
  \@wwo = \maxdimen
    \advance\@wwo by -\@wwi
    \divide\@wwo by \tw@
    \divide\@wwo by \@wwi
%    \end{macrocode}
% Now perform the check and set the scale factor. We have to get a positive
%  integer value for $W$ as it may be a fraction. Actually, we only need to
% be concerned if $\|W\| > 1$.
%    \begin{macrocode}
  \@wwi = 10sp
  \@wwi = #8\@wwi
    \ifdim\@wwi < \z@
      \@wwi = -\@wwi
    \fi
    \divide\@wwi by 10\relax
  \ifdim\@wwi < \@wwo
    \c@@pntscale = \@ne
  \else
    \divide\@wwi by \tw@
    \ifdim\@wwi < \@wwo
      \c@@pntscale = \tw@
    \else
      \divide\@wwi by \tw@
      \ifdim\@wwi < \@wwo
        \c@@pntscale = 4\relax
      \else
        \divide\@wwi by \tw@
        \ifdim\@wwi < \@wwo
          \c@@pntscale = 8\relax
        \else
          \c@@pntscale = 16\relax
        \fi
      \fi
    \fi
  \fi
%    \end{macrocode}
% Calculate the constants for the top line of the function.
%    \begin{macrocode}
  \@ovxx = #4\unitlength \advance\@ovxx by -#2\unitlength
    \multiply\@ovxx by \tw@
    \divide\@ovxx by \c@@pntscale
    \@ovdx = #8\@ovxx
  \@ovxx = #6\unitlength  \advance\@ovxx by -#2\unitlength
    \divide\@ovxx by \c@@pntscale
    \advance\@ovxx by -\@ovdx
    \divide\@ovxx by \@multicnt
  \@ovyy = #5\unitlength \advance\@ovyy by -#3\unitlength
    \multiply\@ovyy by \tw@
    \divide\@ovyy by \c@@pntscale
    \@ovdy = #8\@ovyy
  \@ovyy = #7\unitlength  \advance\@ovyy by -#3\unitlength
    \divide\@ovyy by \c@@pntscale
    \advance\@ovyy by -\@ovdy
    \divide\@ovyy by \@multicnt
%    \end{macrocode}
% Now the constants for the bottom line. We also need to do some scaling
% here. This scaling can be set by the user.
%    \begin{macrocode}
  \setlength{\botscale}{\c@weightscale sp}
  \@wwo = \botscale
  \@wwi = #8\@wwo
  \@wwa = \@wwo  \advance\@wwa by -\@wwi
    \multiply\@wwa by \tw@
  \@wwb = \@wwa
    \divide\@wwb by \@multicnt
%    \end{macrocode}
% Prepare for the drawing.
%    \begin{macrocode}
  \@wwi = \botscale
  \setbox\@tempboxa\hbox{\vrule \@height\@halfwidth
                                \@depth \@halfwidth
                                \@width \@wholewidth}%
%    \end{macrocode}
% Draw the first half of the curve.
%    \begin{macrocode}
  \put(#2,#3){%
    \count@ = \z@
    \@whilenum{\count@ < \@tempcnta}\do
      {\@xdim = \count@\@ovxx
         \advance\@xdim by \@ovdx
         \divide\@xdim by \@multicnt
         \multiply\@xdim by \count@
       \@ydim = \count@\@ovyy
         \advance\@ydim by \@ovdy
         \divide\@ydim by \@multicnt
         \multiply\@ydim by \count@
       \@ww = \count@\@wwb
         \advance\@ww by -\@wwa
         \divide\@ww by \@multicnt
         \multiply\@ww by \count@
         \advance\@ww by \@wwo
         \divide\@ww by \c@@pntscale
         \ifdim\@ww = \z@
%    \end{macrocode}
% We are about to divide by |\@ww| which is zero. Treat |\@ww| as unity.
%    \begin{macrocode}
         \else
           \divide\@xdim by \@ww
           \divide\@ydim by \@ww
         \fi
%    \end{macrocode}
% For reasons I don't understand, the \% signs at the end of the next few
% lines are important!
%    \begin{macrocode}
         \multnooverflow{\@xdim}{\botscale}%
         \multnooverflow{\@ydim}{\botscale}%
       \raise \@ydim
         \hb@xt@\z@{\kern\@xdim
                    \unhcopy\@tempboxa\hss}%
       \advance\count@\@ne}}
%    \end{macrocode}
%
%    We now repeat the above process for plotting the second half of the
% curve, starting at the end point.
%
% Calculate the constants for the top line of the function.
%    \begin{macrocode}
  \@ovxx = #4\unitlength \advance\@ovxx by -#6\unitlength
    \multiply\@ovxx by \tw@
    \divide\@ovxx by \c@@pntscale
    \@ovdx = #8\@ovxx
  \@ovxx = #2\unitlength  \advance\@ovxx by -#6\unitlength
    \divide\@ovxx by \c@@pntscale
    \advance\@ovxx by -\@ovdx
    \divide\@ovxx by \@multicnt
  \@ovyy = #5\unitlength \advance\@ovyy by -#7\unitlength
    \multiply\@ovyy by \tw@
    \divide\@ovyy by \c@@pntscale
    \@ovdy = #8\@ovyy
  \@ovyy = #3\unitlength  \advance\@ovyy by -#7\unitlength
    \divide\@ovyy by \c@@pntscale
    \advance\@ovyy by -\@ovdy
    \divide\@ovyy by \@multicnt
%    \end{macrocode}
% The constants for the bottom line are the same as before as the function
% is symmetric. Similarly we don't need to recalculate the size of the
% rule box.
%
% Draw the second half of the curve.
%    \begin{macrocode}
  \put(#6,#7){%
    \count@ = \z@
    \@whilenum{\count@ < \@tempcnta}\do
      {\@xdim = \count@\@ovxx
         \advance\@xdim by \@ovdx
         \divide\@xdim by \@multicnt
         \multiply\@xdim by \count@
       \@ydim = \count@\@ovyy
         \advance\@ydim by \@ovdy
         \divide\@ydim by \@multicnt
         \multiply\@ydim by \count@
       \@ww = \count@\@wwb
         \advance\@ww by -\@wwa
         \divide\@ww by \@multicnt
         \multiply\@ww by \count@
         \advance\@ww by \@wwo
         \divide\@ww by \c@@pntscale
         \ifnum\@ww = \z@
%    \end{macrocode}
% We are about to divide by |\@ww| which is zero. Treat |\@ww| as unity.
%    \begin{macrocode}
         \else
           \divide\@xdim by \@ww
           \divide\@ydim by \@ww
         \fi
%    \end{macrocode}
% For reasons I don't understand, the \% signs at the end of the next few
% lines are important!
%    \begin{macrocode}
         \multnooverflow{\@xdim}{\botscale}%
         \multnooverflow{\@ydim}{\botscale}%
       \raise \@ydim
         \hb@xt@\z@{\kern\@xdim
                    \unhcopy\@tempboxa\hss}%
       \advance\count@\@ne}}
%    \end{macrocode}
% End of definition of |\@rqbez|.
%    \begin{macrocode}
  \fi\fi}
%    \end{macrocode}
% \end{macro}
%
%    The end of this package.
%    \begin{macrocode}
%</bez>
%    \end{macrocode}
%
% \section{Multiplication without overflow: The \Lpack{multiply} package} \label{sec:mnoflow}
%
%    \TeX{} provides for integer arithmetic, subject to an upper limit
% given by |\maxdim|. For at least the \Lpack{bez123} package we need to 
% be able to multiply without overflow.
%
%    Announce the name of the package.
% \changes{v1.1}{1998/10/14}{Put multnooverflow into a seperate package}
%    \begin{macrocode}
%<*mult>
\ProvidesPackage{multiply}[1998/10/14 v1.1 Multiplication of lengths without overflow]
%    \end{macrocode}
%
% \begin{macro}{\n@fl@wa}
% \begin{macro}{\n@fl@wb}
% \begin{macro}{\n@fl@wc}
% \begin{macro}{\ifch@nge}
%    We need three length variables for this function. 
% We also need a boolean flag for dealing with negative numbers.
%    \begin{macrocode}
\newlength{\n@fl@wa}
\newlength{\n@fl@wb}
\newlength{\n@fl@wc}
\newif\ifch@nge
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\multnooverflow}
%
%    The routine |\multnooverflow{|\meta{a}|}{|\meta{b}|}| sets 
% $a$ to the minimum of $ab$ and |\maxdimen|, preserving signs. \meta{a}
% must be a length; it must not be a number literal.
%
%    \begin{macrocode}
\newcommand{\multnooverflow}[2]{%
  \n@fl@wa = #1\relax%
  \n@fl@wb = #2\relax%
  \ch@ngefalse%
%    \end{macrocode}
% Easy if $-1 \leq b \leq 1$.
%    \begin{macrocode}
  \ifnum\n@fl@wb = \@ne%
  \else%
    \ifnum\n@fl@wb = \z@%
      \n@fl@wa = \z@%
    \else%
      \ifnum\n@fl@wb = \m@ne%
        \ch@ngetrue%
      \else%
%    \end{macrocode}
% Also easy if $-1 \leq a \leq 1$.
%    \begin{macrocode}
        \ifnum\n@fl@wa = \z@%
        \else%
          \ifnum\n@fl@wa = \@ne%
            \n@fl@wa = \n@fl@wb%
          \else%
            \ifnum\n@fl@wa = \m@ne%
              \n@fl@wa = -\n@fl@wb%
            \else%
%    \end{macrocode}
% We have to check for potential overflow. First make sure that we deal
% only with positive values.
%    \begin{macrocode}
              \ifnum\n@fl@wa < \z@%
                \ch@ngetrue%
                \n@fl@wa = -\n@fl@wa%
              \fi%
              \ifnum\n@fl@wb < \z@%
                \n@fl@wb = -\n@fl@wb%
                \ifch@nge%
                  \ch@ngefalse%
                \else%
                  \ch@ngetrue%
                \fi%
              \fi%
%    \end{macrocode}
% Check for overflow.
%    \begin{macrocode}
              \n@fl@wc = \maxdimen%
              \divide\n@fl@wc by \n@fl@wb%
              \advance\n@fl@wc by -1sp% \m@ne
              \ifnum\n@fl@wa > \n@fl@wc%
%    \end{macrocode}
% We have overflow. Set the multiplication result to |\maxdimen|.
%    \begin{macrocode}
                \n@fl@wa = \maxdimen%
                \PackageWarning{multiply}{Multiplication overflow}%
              \else%
%    \end{macrocode}
% It is safe to do the multiplication.
%    \begin{macrocode}
                \multiply\n@fl@wa by \n@fl@wb%
              \fi%
            \fi%
          \fi%
        \fi%
      \fi%
    \fi%
  \fi%
%    \end{macrocode}
% The result of $ab$ is in |\n@fl@wa|. Adjust the sign if necessary.
%    \begin{macrocode}
  \ifch@nge%
    \n@fl@wa = -\n@fl@wa%
  \fi%
%    \end{macrocode}
% Return the result in the first argument variable.
%    \begin{macrocode}
  #1 = \n@fl@wa%
}
%    \end{macrocode}
% \end{macro}
%
%
%    The end of this package.
%    \begin{macrocode}
%</mult>
%    \end{macrocode}
%
%
% \bibliographystyle{alpha}
%
% \begin{thebibliography}{GMS94}
%
% \bibitem[Far90]{FARIN90}
% Gerald Farin.
% \newblock {\em Curves and Surfaces for Computer Aided Geometric Design --- A
%   Practical Guide}.
% \newblock Academic Press, Inc., second edition, 1990.
%
% \bibitem[FP81]{FandP}
% I.~D. Faux and M.~J. Pratt.
% \newblock {\em Computational Geometry for Design and Manufacture}.
% \newblock Ellis Horwood, 1981.
%
% \bibitem[GMS94]{GOOSSENS94}
% Michel Goossens, Frank Mittelbach, and Alexander Samarin.
% \newblock {\em The LaTeX Companion}.
% \newblock Addison-Wesley Publishing Company, 1994.
%
% \bibitem[Lam94]{LAMPORT94}
% Leslie Lamport.
% \newblock {\em LaTeX: A Document Preparation System}.
% \newblock Addison-Wesley Publishing Company, second edition, 1994.
%
% \bibitem[Mor85]{MORTENSON85}
% Michael~E. Mortenson.
% \newblock {\em Geometric Modeling}.
% \newblock John Wiley \& Sons, Inc., 1985.
%
% \bibitem[Wil96]{PRW96i}
% Peter~R. Wilson.
% \newblock {\em {LaTeX for standards: The LaTeX package files user manual}}.
% \newblock NIST Report NISTIR, June 1996.
%
% \end{thebibliography}
%
%
% \Finale
% \PrintIndex
%
\endinput

%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}