Debian Codegraph @

texmf-dist/source/latex/bez123/bez123.dtx

raw
1 % \iffalse meta-comment
2 % bez123.dtx
3 % Author: Peter Wilson, Herries Press
4 % Maintainer: Will Robertson (will dot robertson at latex-project dot org)
5 % Copyright 1998--2004 Peter R. Wilson
6 %
7 % This work may be distributed and/or modified under the
8 % conditions of the LaTeX Project Public License, either
9 % version 1.3c of this license or (at your option) any
10 % later version: <http://www.latex-project.org/lppl.txt>
11 %
12 % This work has the LPPL maintenance status "maintained".
13 % The Current Maintainer of this work is Will Robertson.
14 %
15 % This work consists of the files listed in the README file.
16 %
17 %
18 %
19 %<*driver>
20 \documentclass{ltxdoc}
21 \usepackage{bez123}
22 \EnableCrossrefs
23 \CodelineIndex
24 \setcounter{StandardModuleDepth}{1}
25 \begin{document}
26 \DocInput{bez123.dtx}
27 \end{document}
28 %</driver>
29 %
30 % \fi
31 %
32 % \CheckSum{988}
33 %
34 % \DoNotIndex{\',\.,\@M,\@@input,\@addtoreset,\@arabic,\@badmath}
35 % \DoNotIndex{\@centercr,\@cite}
36 % \DoNotIndex{\@dotsep,\@empty,\@float,\@gobble,\@gobbletwo,\@ignoretrue}
37 % \DoNotIndex{\@input,\@ixpt,\@m}
38 % \DoNotIndex{\@minus,\@mkboth,\@ne,\@nil,\@nomath,\@plus,\@set@topoint}
39 % \DoNotIndex{\@tempboxa,\@tempcnta,\@tempdima,\@tempdimb}
40 % \DoNotIndex{\@tempswafalse,\@tempswatrue,\@viipt,\@viiipt,\@vipt}
41 % \DoNotIndex{\@vpt,\@warning,\@xiipt,\@xipt,\@xivpt,\@xpt,\@xviipt}
42 % \DoNotIndex{\@xxpt,\@xxvpt,\\,\ ,\addpenalty,\addtolength,\addvspace}
43 % \DoNotIndex{\advance,\Alph,\alph}
44 % \DoNotIndex{\arabic,\ast,\begin,\begingroup,\bfseries,\bgroup,\box}
45 % \DoNotIndex{\bullet}
46 % \DoNotIndex{\cdot,\cite,\CodelineIndex,\cr,\day,\DeclareOption}
47 % \DoNotIndex{\def,\DisableCrossrefs,\divide,\DocInput,\documentclass}
48 % \DoNotIndex{\DoNotIndex,\egroup,\ifdim,\else,\fi,\em,\endtrivlist}
49 % \DoNotIndex{\EnableCrossrefs,\end,\end@dblfloat,\end@float,\endgroup}
50 % \DoNotIndex{\endlist,\everycr,\everypar,\ExecuteOptions,\expandafter}
51 % \DoNotIndex{\fbox}
52 % \DoNotIndex{\filedate,\filename,\fileversion,\fontsize,\framebox,\gdef}
53 % \DoNotIndex{\global,\halign,\hangindent,\hbox,\hfil,\hfill,\hrule}
54 % \DoNotIndex{\hsize,\hskip,\hspace,\hss,\if@tempswa,\ifcase,\or,\fi,\fi}
55 % \DoNotIndex{\ifhmode,\ifvmode,\ifnum,\iftrue,\ifx,\fi,\fi,\fi,\fi,\fi}
56 % \DoNotIndex{\input}
57 % \DoNotIndex{\jobname,\kern,\leavevmode,\let,\leftmark}
58 % \DoNotIndex{\list,\llap,\long,\m@ne,\m@th,\mark,\markboth,\markright}
59 % \DoNotIndex{\month,\newcommand,\newcounter,\newenvironment}
60 % \DoNotIndex{\NeedsTeXFormat,\newdimen}
61 % \DoNotIndex{\newlength,\newpage,\nobreak,\noindent,\null,\number}
62 % \DoNotIndex{\numberline,\OldMakeindex,\OnlyDescription,\p@}
63 % \DoNotIndex{\pagestyle,\par,\paragraph,\paragraphmark,\parfillskip}
64 % \DoNotIndex{\penalty,\PrintChanges,\PrintIndex,\ProcessOptions}
65 % \DoNotIndex{\protect,\ProvidesClass,\raggedbottom,\raggedright}
66 % \DoNotIndex{\refstepcounter,\relax,\renewcommand,\reset@font}
67 % \DoNotIndex{\rightmargin,\rightmark,\rightskip,\rlap,\rmfamily,\roman}
68 % \DoNotIndex{\roman,\secdef,\selectfont,\setbox,\setcounter,\setlength}
69 % \DoNotIndex{\settowidth,\sfcode,\skip,\sloppy,\slshape,\space}
70 % \DoNotIndex{\symbol,\the,\trivlist,\typeout,\tw@,\undefined,\uppercase}
71 % \DoNotIndex{\usecounter,\usefont,\usepackage,\vfil,\vfill,\viiipt}
72 % \DoNotIndex{\viipt,\vipt,\vskip,\vspace}
73 % \DoNotIndex{\wd,\xiipt,\year,\z@}
74 %
75 % \def\dtxfile{bez123.dtx}
76 % \def\fileversion{v1.1}
77 % \def\filedate{1998/10/14}
78 % \def\fileversion{v1.1a}
79 % \def\filedate{2004/04/16}
80 % \def\fileversion{v1.1b}
81 % \def\filedate{2009/09/02}
82 % \newcommand*{\Lpack}[1]{\textsf {#1}} ^^A typest a package
83 % \newcommand*{\Lopt}[1]{\textsf {#1}} ^^A typeset an option
84 % \newcommand*{\file}[1]{\texttt {#1}} ^^A typeset a file
85 % \newcommand*{\Lcount}[1]{\textsl {\small#1}} ^^A typeset a counter
86 % \newcommand*{\pstyle}[1]{\textsl {#1}} ^^A typeset a pagestyle
87 % \newcommand*{\Lenv}[1]{\texttt {#1}} ^^A typeset an environment
88 % \newcommand{\eqref}[1]{equation~(\ref{#1})} ^^A typeset ref to an equation
89 %
90 % \title{The \Lpack{bez123} and \Lpack{multiply} packages\thanks{This
91 % file (\texttt{\dtxfile}) has version number \fileversion,
92 % last revised \filedate.}}
93 %
94 % \author{%
95 % Author: Peter Wilson, Herries Press\\
96 % Maintainer: Will Robertson\\
97 % \texttt{will dot robertson at latex-project dot org}
98 % }
99 % \date{\filedate}
100 % \maketitle
101 % \begin{abstract}
102 % The \Lpack{bez123} package provides for the drawing of linear, cubic,
103 % and rational quadratic Bezier curves. The \Lpack{multiply} package
104 % provides a command to multiply a length without numerical overflow.
105 % \end{abstract}
106 % \tableofcontents
107 % \listoftables
108 % \listoffigures
109 %
110 % \StopEventually{}
111 %
112 %
113 %
114 % \section{Introduction}
115 %
116 % This document provides the commented source for a \LaTeX{}
117 % package file that extends the \LaTeX{} facilities for drawing
118 % Bezier curves. The package was originally developed as part of
119 % a suite designed for the typesetting of
120 % documents according to the rules for ISO international
121 % standards~\cite{PRW96i}.
122 % This manual is typeset according to the conventions of the
123 % \LaTeX{} \textsc{docstrip} utility which enables the automatic
124 % extraction of the \LaTeX{} macro source files~\cite{GOOSSENS94}.
125 %
126 % Drawing a non-rational quadratic Bezier curve is provided as part
127 % of the standard \LaTeX{} system.
128 % Section~\ref{sec:usage} provides the user manual for the new commands
129 % supplied by this package for drawing a variety of Bezier curves.
130 % These include commands for drawing linear and cubic non-rational Bezier
131 % curves and rational quadratic curves.
132 %
133 % Section~\ref{sec:bez} describes the implementation of the package.
134 % As a side-effect of the implementation, a facility is also provided
135 % for performing multiplication in \TeX{} without overflow. This is
136 % described in Section~\ref{sec:mnoflow}.
137 %
138 %
139 %
140 % \section{Usage} \label{sec:usage}
141 %
142 % Leslie Lamport provided the means of drawing a quadratic Bezier curve
143 % \emph{via} the \LaTeXe{} |\qbezier|~\cite[pp. 125--126]{LAMPORT94} command.
144 % This package
145 % extends the Bezier facility by providing commands to draw linear,
146 % rational quadratic, and cubic Bezier curves.
147 %
148 % Bezier curves are named after Pierre Bezier who invented them. They
149 % are widely used within Computer Aided Design (CAD) programs and other
150 % graphics systems; descriptions can be found in many places, with varying
151 % degrees of mathematical complexity, such
152 % as~\cite{FandP,MORTENSON85,FARIN90}.
153 %
154 % The Bezier curve is a parameterized curve of degree $n$ and can
155 % therefore be specified by $(n+1)$ points
156 % (i.e., point $p_{0}$ through $p_{n}$).
157 % Among its other properties, a Bezier curve of degree $n$ passes through
158 % through the points $p_{0}$ and $p_{n}$ and passes close to the other
159 % defining points. The general equation for a Bezier curve of degree $n$ with
160 % parameter $t$ is
161 % \begin{equation}
162 % p(t) = a_{0} + a_{1}t + a_{2}t^{2} + \cdots + a_{n}t^{n} \label{eq:gen}
163 % \end{equation}
164 % where the coefficients $a_{i}$ depend on the defining points, and
165 % traditionally $0 \leq t \leq 1$.
166 %
167 % For a linear (degree $1$) curve, the equation is
168 % \begin{equation}
169 % p(t) = p_{0} + (p_{1} - p_{0})t \label{eq:lin}
170 % \end{equation}
171 % By inspection, $p(0) = p_{0}$ and $p(1) = p_{1}$.
172 %
173 % Rearranging \eqref{eq:gen} slightly we get
174 % \begin{equation}
175 % p(t) - p_{0} = (p_{1} - p_{0})t \label{eq:lin2}
176 % \end{equation}
177 % In other words, we can march along the curve from the starting point to
178 % the ending point by evaluating the right hand side of
179 % \eqref{eq:lin2} for increasing values of the parameter $t$.
180 %
181 % In order to shorten the equations slightly, and also make them more
182 % convenient to work with numerically, we will use the notation
183 % \begin{displaymath}
184 % l_{pq} = p_{p} - p_{q}
185 % \end{displaymath}
186 % Thus, the final form for the linear Bezier curve is
187 % \begin{equation}
188 % p(t) - p_{0} = l_{10}t \label{eq:lin3}
189 % \end{equation}
190 %
191 % \DescribeMacro{\lbezier}
192 % The command |\lbezier[|\meta{N}|](|\meta{p0}|)(|\meta{p1}|)| draws a
193 % linear Bezier curve with \meta{N} plotted points from the point \meta{p0}
194 % (with coordinates \meta{x0,y0}) to the point \meta{p1} (with
195 % coordinates \meta{x1,y1}). \meta{N} is an optional argument. If it is
196 % either not given or is given with a value of zero,
197 % then the command will calculate the number of points to be
198 % plotted, subject to a maximum number.
199 % There must be no spaces between the arguments to the
200 % |\lbezier| command; this restriction also applies to the other Bezier
201 % drawing commands provided by the \Lpack{bez123} package.
202 %
203 % Figure~\ref{fig:beta} shows an example of a dotted line drawn using
204 % the |\lbezier| command. The actual code used is:
205 % \begin{verbatim}
206 % \lbezier[50](15,30)(30,0)
207 % \end{verbatim}
208 % thus drawing a straight line consisting of 50 points.
209 %
210 % \DescribeMacro{\qbeziermax}
211 % The standard \LaTeX{} command |\qbeziermax| sets a maximum limit
212 % on the number of points used to draw any of the Bezier curves.
213 %
214 % \DescribeMacro{\thinlines}
215 % \DescribeMacro{\thicklines}
216 % \DescribeMacro{\linethickness}
217 % The `points' used in drawing the Bezier curves are small squares. The
218 % size of these squares are controlled by the standard \LaTeX{}
219 % |\thinlines|, |\thicklines| and/or |\linethickness| commands.
220 % Consult Lamport~\cite{LAMPORT94} for descriptions of these, and
221 % |\qbeziermax|, commands.
222 %
223 %
224 % It is convenient to introduce some general properties of Bezier curves
225 % at this point.
226 % \begin{itemize}
227 % \item A degree $n$ Bezier curve is defined by $(n+1)$ points which we
228 % will label as $p_{0}$ through $p_{n}$. The lines joining the points
229 % $p_{0}, p_{1}, \ldots , p_{n}$ are called the \emph{control polygon}.
230 % The Bezier curve is parameterized by a variable we will call $t$, with
231 % $0 \leq t \leq 1$.
232 % \item A degree $n$ Bezier curve starts at point $p_{0}$ and ends at
233 % point $p_{n}$.
234 % \item At $t=0$ the curve passes through $p_{0}$ and is tangent to the
235 % line $l_{10} = p_{1}-p_{0}$.
236 % \item At $t=1$ the curve passes through $p_{n}$ and is tangent to the
237 % line $l_{(n)(n-1)} = p_{n}-p_{(n-1)}$.
238 % \item A \emph{non-rational} Bezier curve lies within the \emph{convex
239 % hull}\footnote{The convex hull can be thought of as the shape that a rubber
240 % band will take if it is stretched around pins placed at each point.}
241 % of the points $p_{0}$ through $p_{n}$. For examples of convex hulls see
242 % figure~\ref{fig:ch}. Note that the shape of a convex hull is independant
243 % of the ordering of the points.
244 % \end{itemize}
245 %
246 % \begin{figure}
247 % \centering
248 % \setlength{\unitlength}{1mm}
249 % \begin{picture}(70,80)
250 % ^^A degree 3
251 % \put(0,5){\begin{picture}(30,30)
252 % \thinlines
253 % \put(0,0){\circle{2}}
254 % \put(-2,0){\makebox(0,0)[br]{0}}
255 % \put(10,30){\circle{2}}
256 % \put(8,30){\makebox(0,0)[br]{1}}
257 % \put(20,0){\circle{2}}
258 % \put(22,0){\makebox(0,0)[bl]{2}}
259 % \put(30,30){\circle{2}}
260 % \put(32,30){\makebox(0,0)[bl]{3}}
261 % ^^A convex hull
262 % \put(0,0){\line(1,0){20}}
263 % \put(20,0){\line(1,3){10}}
264 % \put(30,30){\line(-1,0){20}}
265 % \put(10,30){\line(-1,-3){10}}
266 % ^^A control polygon
267 % ^^A \put(0,0){\vector(1,3){10}}
268 % ^^A \put(10,30){\vector(1,-3){10}}
269 % ^^A \put(20,0){\vector(1,3){10}}
270 % \thicklines
271 % ^^A \cbezier[30](0,0)(10,30)(20,0)(30,30)
272 % \thinlines
273 % \end{picture}}
274 % ^^A degree 3
275 % \put(0,45){\begin{picture}(30,30)
276 % \thinlines
277 % \put(0,0){\circle{2}}
278 % \put(-2,0){\makebox(0,0)[br]{0, 3}}
279 % \put(30,0){\circle{2}}
280 % \put(32,0){\makebox(0,0)[bl]{1}}
281 % \put(0,30){\circle{2}}
282 % \put(2,30){\makebox(0,0)[bl]{2}}
283 % ^^A convex hull
284 % \put(0,0){\line(1,0){30}}
285 % \put(30,0){\line(-1,1){30}}
286 % \put(0,30){\line(0,-1){30}}
287 % ^^A control polygon
288 % ^^A \put(0,0){\vector(1,0){30}}
289 % ^^A \put(30,0){\vector(-1,1){30}}
290 % ^^A \put(0,30){\vector(0,-1){30}}
291 % \thicklines
292 % ^^A \cbezier[30](0,0)(30,0)(0,30)(0,0)
293 % \thinlines
294 % \end{picture}}
295 % ^^A degree 3
296 % \put(45,0){\begin{picture}(30,30)
297 % \thinlines
298 % \put(0,0){\circle{2}}
299 % \put(-2,0){\makebox(0,0)[br]{0}}
300 % \put(10,30){\circle{2}}
301 % \put(8,30){\makebox(0,0)[br]{2}}
302 % \put(20,0){\circle{2}}
303 % \put(22,0){\makebox(0,0)[bl]{3}}
304 % \put(30,30){\circle{2}}
305 % \put(32,30){\makebox(0,0)[bl]{1}}
306 % ^^A convex hull
307 % \put(0,0){\line(1,0){20}}
308 % \put(20,0){\line(1,3){10}}
309 % \put(30,30){\line(-1,0){20}}
310 % \put(10,30){\line(-1,-3){10}}
311 % ^^A control polygon
312 % ^^A \put(0,0){\vector(1,1){30}}
313 % ^^A \put(30,30){\vector(-1,0){20}}
314 % ^^A \put(10,30){\vector(1,-3){10}}
315 % \thicklines
316 % ^^A \cbezier(0,0)(30,30)(10,30)(20,0)
317 % \thinlines
318 % \end{picture}}
319 % \put(45,45){\begin{picture}(30,30)
320 % \thinlines
321 % \put(0,0){\circle{2}}
322 % \put(-2,0){\makebox(0,0)[br]{0}}
323 % \put(30,0){\circle{2}}
324 % \put(32,0){\makebox(0,0)[bl]{1}}
325 % \put(0,30){\circle{2}}
326 % \put(2,30){\makebox(0,0)[bl]{2}}
327 % \put(10,10){\circle{2}}
328 % \put(8,10){\makebox(0,0)[br]{3}}
329 % ^^A convex hull
330 % \put(0,0){\line(1,0){30}}
331 % \put(30,0){\line(-1,1){30}}
332 % \put(0,30){\line(0,-1){30}}
333 % ^^A control polygon
334 % ^^A \put(0,0){\vector(1,0){30}}
335 % ^^A \put(30,0){\vector(-1,1){30}}
336 % ^^A \put(0,30){\vector(1,-2){10}}
337 % \thicklines
338 % ^^A \cbezier(0,0)(30,0)(0,30)(10,10)
339 % \thinlines
340 % \end{picture}}
341 % \end{picture}
342 % \setlength{\unitlength}{1pt}
343 % \caption{Four sets of points and their convex hulls} \label{fig:ch}
344 % \end{figure}
345 %
346 % The equation for cubic Bezier curves is
347 % \begin{equation}
348 % p(t) - p_{0} = 3l_{10}t + 3(l_{21} - l_{10})t^{2} + (l_{30} - 3l_{21})t^{3}
349 % \label{eq:cubic}
350 % \end{equation}
351 %
352 % \DescribeMacro{\cbezier}
353 % The command
354 % |\cbezier[|\meta{N}|](|\meta{p0}|)(|\meta{p1}|)(|\meta{p2}|)(|\meta{p3}|)|
355 % draws a cubic Bezier curve, as defined by \eqref{eq:cubic},
356 % from point \meta{p0} to point \meta{p3}, where \meta{p1} and \meta{p2}
357 % are the intermediate points defining the control polygon.
358 %
359 % \begin{figure}
360 % \centering
361 % \setlength{\unitlength}{1mm}
362 % \begin{picture}(70,80)
363 % ^^A degree 3
364 % \put(0,5){\begin{picture}(30,30)
365 % \thinlines
366 % \put(0,0){\circle{2}}
367 % \put(-2,0){\makebox(0,0)[br]{0}}
368 % \put(10,30){\circle{2}}
369 % \put(8,30){\makebox(0,0)[br]{1}}
370 % \put(20,0){\circle{2}}
371 % \put(22,0){\makebox(0,0)[bl]{2}}
372 % \put(30,30){\circle{2}}
373 % \put(32,30){\makebox(0,0)[bl]{3}}
374 % ^^A convex hull
375 % ^^A \put(0,0){\line(1,0){20}}
376 % ^^A \put(20,0){\line(1,3){10}}
377 % ^^A \put(30,30){\line(-1,0){20}}
378 % ^^A \put(10,30){\line(-1,-3){10}}
379 % ^^A control polygon
380 % \put(0,0){\vector(1,3){10}}
381 % \put(10,30){\vector(1,-3){10}}
382 % \put(20,0){\vector(1,3){10}}
383 % \thicklines
384 % \cbezier[30](0,0)(10,30)(20,0)(30,30)
385 % \thinlines
386 % \end{picture}}
387 % ^^A degree 3
388 % \put(0,45){\begin{picture}(30,30)
389 % \thinlines
390 % \put(0,0){\circle{2}}
391 % \put(-2,0){\makebox(0,0)[br]{0, 3}}
392 % \put(30,0){\circle{2}}
393 % \put(32,0){\makebox(0,0)[bl]{1}}
394 % \put(0,30){\circle{2}}
395 % \put(2,30){\makebox(0,0)[bl]{2}}
396 % ^^A convex hull
397 % ^^A \put(0,0){\line(1,0){30}}
398 % ^^A \put(30,0){\line(-1,1){30}}
399 % ^^A \put(0,30){\line(0,-1){30}}
400 % ^^A control polygon
401 % \put(0,0){\vector(1,0){30}}
402 % \put(30,0){\vector(-1,1){30}}
403 % \put(0,30){\vector(0,-1){30}}
404 % \thicklines
405 % \cbezier[30](0,0)(30,0)(0,30)(0,0)
406 % \thinlines
407 % \end{picture}}
408 % ^^A degree 3
409 % \put(45,0){\begin{picture}(30,30)
410 % \thinlines
411 % \put(0,0){\circle{2}}
412 % \put(-2,0){\makebox(0,0)[br]{0}}
413 % \put(10,30){\circle{2}}
414 % \put(8,30){\makebox(0,0)[br]{2}}
415 % \put(20,0){\circle{2}}
416 % \put(22,0){\makebox(0,0)[bl]{3}}
417 % \put(30,30){\circle{2}}
418 % \put(32,30){\makebox(0,0)[bl]{1}}
419 % ^^A convex hull
420 % ^^A \put(0,0){\line(1,0){20}}
421 % ^^A \put(20,0){\line(1,3){10}}
422 % ^^A \put(30,30){\line(-1,0){20}}
423 % ^^A \put(10,30){\line(-1,-3){10}}
424 % ^^A control polygon
425 % \put(0,0){\vector(1,1){30}}
426 % \put(30,30){\vector(-1,0){20}}
427 % \put(10,30){\vector(1,-3){10}}
428 % \thicklines
429 % \cbezier(0,0)(30,30)(10,30)(20,0)
430 % \thinlines
431 % \end{picture}}
432 % \put(45,45){\begin{picture}(30,30)
433 % \thinlines
434 % \put(0,0){\circle{2}}
435 % \put(-2,0){\makebox(0,0)[br]{0}}
436 % \put(30,0){\circle{2}}
437 % \put(32,0){\makebox(0,0)[bl]{1}}
438 % \put(0,30){\circle{2}}
439 % \put(2,30){\makebox(0,0)[bl]{2}}
440 % \put(10,10){\circle{2}}
441 % \put(8,10){\makebox(0,0)[br]{3}}
442 % ^^A convex hull
443 % ^^A \put(0,0){\line(1,0){30}}
444 % ^^A \put(30,0){\line(-1,1){30}}
445 % ^^A \put(0,30){\line(0,-1){30}}
446 % ^^A control polygon
447 % \put(0,0){\vector(1,0){30}}
448 % \put(30,0){\vector(-1,1){30}}
449 % \put(0,30){\vector(1,-2){10}}
450 % \thicklines
451 % \cbezier(0,0)(30,0)(0,30)(10,10)
452 % \thinlines
453 % \end{picture}}
454 % \end{picture}
455 % \setlength{\unitlength}{1pt}
456 % \caption{Four sets of points, the cubic Bezier curves and their control
457 % polygons. Left --- curves plotted with $N=30$; Right ---
458 % curves plotted with $N=0$} \label{fig:cp}
459 % \end{figure}
460 %
461 % Figure~\ref{fig:cp} shows four such cubic Bezier curves, their
462 % defining points and their control polygons. These are the same points
463 % that were used in figure~\ref{fig:ch} to illustrate convex hulls. It is
464 % easy to verify that a cubic Bezier curve does indeed lie within the convex
465 % hull of its defining points. The curves on the left of the figure were
466 % specified with a value of 30 for the argument \meta{N}, while those
467 % on the right had no value given for \meta{N} and thus were drawn with
468 % the number of plotted points calculated by the drawing algorithm.
469 % The actual drawing commands used were:
470 % \begin{verbatim}
471 % \cbezier[30](0,0)(10,30)(20,0)(30,30)
472 % \cbezier[30](0,0)(30,0)(0,30)(0,0)
473 % \cbezier(0,0)(30,30)(10,30)(20,0)
474 % \cbezier(0,0)(30,0)(0,30)(10,10)
475 % \end{verbatim}
476 % Note that points are plotted along the curve at equidistant values of the
477 % of the parameter $t$. However, as the relationship between the actual
478 % distance in $(x,y)$ coordinate space is a non-linear function of $t$,
479 % the seperation between the plotted points is non-uniform.
480 %
481 % The equation for a \emph{non-rational} quadratic Bezier curve is
482 % \begin{equation}
483 % p(t) - p_{0} = 2l_{10}t + (l_{20} - 2l_{10})t^{2} \label{eq:quad}
484 % \end{equation}
485 % Using standard \LaTeX{} this can be drawn by the |\qbezier| command.
486 % There is another form of a quadratic Bezier curve called a \emph{rational}
487 % quadratic Bezier curve. Its equation is
488 % \begin{equation}
489 % p(t) - p_{0} = \frac^^A
490 % {2w_{1}l_{10}t + (w_{2}l_{20} - 2w_{1}l_{10})t^{2}}^^A
491 % {w_{0} + 2\omega_{10}t + (\omega_{20} - \omega_{10})t^{2}}
492 % \label{eq:rqfull}
493 % \end{equation}
494 % where the $w_{i}$ are the \emph{weights} corresponding to the
495 % points $p_{i}$ and $\omega_{pq} = w_{p} - w_{q}$. The shape of a
496 % non-rational curve can be changed by changing the positions of the defining
497 % points. The shape of a rational curve can also be modified by changing
498 % the values of the weights. A rational curve
499 % has the same general properties, outlined above, as a non-rational curve
500 % with the exception that the curve may lie outside the convex hull of the
501 % control polygon.
502 %
503 % For the purposes at hand, we use a more restricted form of a
504 % rational quadratic Bezier curve, obtained by putting
505 % $W = w_{1}/w_{0}$ and then making
506 % $w_{0} = w_{2} = 1$ in \eqref{eq:rqfull}. Performing these
507 % substitutions we end up with
508 % \begin{equation}
509 % p(t) - p_{0} = \frac^^A
510 % {2Wl_{10}t + (l_{20} - 2Wl_{10})t^{2}}^^A
511 % {1 + 2(1 - W)t + 2(1 - W)t^{2}}
512 % \label{eq:rqfinal}
513 % \end{equation}
514 % Note that when $W=1$, (\ref{eq:rqfinal}) reduces to \eqref{eq:quad}
515 % and when $W=0$ it effectively reduces to \eqref{eq:lin3}.
516 %
517 % It turns out that a non-rational quadratic Bezier curve is an arc of
518 % a parabola, which is one of the conic curves. All the other conic curves
519 % can be represented by the rational quadratic Bezier curve described
520 % by \eqref{eq:rqfinal} by suitable choices for the value of $W$.
521 % From now on, we will call $W$ the \emph{weight} of the rational quadratic
522 % Bezier curve. Table~\ref{tab:rq} lists the value, or value range,
523 % of $W$ for the various forms of the conic curve.\footnote{We do not deal
524 % with the degenerate cases.} For the case of a circle, $\beta$ is the
525 % angle between the lines $l_{10} = (p_{1} - p_{0})$ and
526 % $l_{20} = (p_{2} - p_{0})$, as shown in figure~\ref{fig:beta}.
527 %
528 % \begin{table}
529 % \centering
530 % \caption{Conic forms of the rational quadratic Bezier curve} \label{tab:rq}
531 % \begin{tabular}{lc} \hline
532 % Conic form & Weight ($W$) \\ \hline
533 % Hyperbola & $\|W\| > 1$ \\
534 % Parabola & $\|W\| = 1$ \\
535 % Ellipse & $0 < \|W\| < 1$ \\
536 % Circle & $\|l_{10}\| = \|l_{21}\|$ and $W = \cos \beta$ \\
537 % Straight line & $W = 0$ \\ \hline
538 % \end{tabular}
539 % \end{table}
540 %
541 %
542 % \begin{figure}
543 % \centering
544 % \setlength{\unitlength}{1mm}
545 % \begin{picture}(30,40)
546 % \put(0,5){\begin{picture}(30,30)
547 % \put(0,0){\circle{2}}
548 % \put(-2,0){\makebox(0,0)[br]{1}}
549 % \put(15,30){\circle{2}}
550 % \put(13,30){\makebox(0,0)[br]{0}}
551 % \put(30,0){\circle{2}}
552 % \put(32,0){\makebox(0,0)[bl]{2}}
553 % ^^A polygon
554 % \thicklines
555 % \put(15,30){\vector(-1,-2){15}}
556 % \put(0,0){\vector(1,0){30}}
557 % ^^A dashed line from 0 to 2
558 % ^^A \lbezier(15,30)(30,0)
559 % \lbezier[50](15,30)(30,0)
560 % \thinlines
561 % \put(15,26){\makebox(0,0){$\beta$}}
562 % \end{picture}}
563 % \end{picture}
564 % \setlength{\unitlength}{1pt}
565 % \caption{The angle $\beta$} \label{fig:beta}
566 % \end{figure}
567 %
568 % \DescribeMacro{\rqbezier}
569 % The command
570 % |\rqbezier[|\meta{N}|](|\meta{p0}|)(|\meta{p1}|)(|\meta{p2}|)(|\meta{W}|)|
571 % draws a rational quadratic Bezier curve from \meta{p0} to \meta{p2} with
572 % weight \meta{W}, according to \eqref{eq:rqfinal}. As in the
573 % other Bezier commands, \meta{N} is optional and controls the number
574 % of plotted points along the curve. Figure~\ref{fig:qrb} shows several
575 % rational quadratic curves, all with the same control polygon but with
576 % differing values for the weight $W$. The code is:
577 % \begin{verbatim}
578 % \rqbezier[100](15,30)(0,0)(30,0)(4)
579 % \rqbezier[100](15,30)(0,0)(30,0)(2)
580 % \rqbezier(15,30)(0,0)(30,0)(1)
581 % \rqbezier[100](15,30)(0,0)(30,0)(0.75)
582 % \rqbezier[100](15,30)(0,0)(30,0)(0.5)
583 % \rqbezier[100](15,30)(0,0)(30,0)(0.25)
584 % \rqbezier(15,30)(0,0)(30,0)(0)
585 % \end{verbatim}
586 % When $W > 1$ the curve is pulled toward the point $p_{1}$. Conversely,
587 % when $W < 1$ the curve is pushed away from the point $p_{1}$. In all
588 % cases, though, the curve starts and stops at $p_{0}$ and $p_{2}$
589 % respectively.
590 %
591 % \begin{figure}
592 % \centering
593 % \setlength{\unitlength}{1mm}
594 % \begin{picture}(30,40)
595 % \put(0,5){\begin{picture}(30,30)
596 % \put(0,0){\circle{2}}
597 % \put(-2,0){\makebox(0,0)[br]{1}}
598 % \put(15,30){\circle{2}}
599 % \put(13,30){\makebox(0,0)[br]{0}}
600 % \put(30,0){\circle{2}}
601 % \put(32,0){\makebox(0,0)[bl]{2}}
602 % ^^A polygon
603 % \thinlines
604 % \put(15,30){\vector(-1,-2){15}}
605 % \put(0,0){\vector(1,0){30}}
606 % ^^A dashed line from 0 to 2
607 % ^^A \lbezier(15,30)(30,0)
608 % ^^A \lbezier[50](15,30)(30,0)
609 % ^^A \thinlines
610 % ^^A \put(15,26){\makebox(0,0){$\beta$}}
611 % \thicklines
612 % \rqbezier[100](15,30)(0,0)(30,0)(4)
613 % \rqbezier[100](15,30)(0,0)(30,0)(2)
614 % \rqbezier(15,30)(0,0)(30,0)(1)
615 % \rqbezier[100](15,30)(0,0)(30,0)(0.75)
616 % \rqbezier[100](15,30)(0,0)(30,0)(0.5)
617 % \rqbezier[100](15,30)(0,0)(30,0)(0.25)
618 % \rqbezier(15,30)(0,0)(30,0)(0)
619 % \end{picture}}
620 % \end{picture}
621 % \setlength{\unitlength}{1pt}
622 % \caption{The effect of weight variation ($W \geq 0$)
623 % on rational quadratic Bezier curves
624 % (\texttt{weightscale = \theweightscale} (the default)) }
625 % \label{fig:qrb}
626 % \end{figure}
627 %
628 % Like the case of the cubic curve, points are plotted at equidistant
629 % values of the parameter $t$. The relationship between parameter value
630 % and coordinate positions in the rational case are highly non-linear.
631 % Thus the distance between the plotted points can vary quite remarkably.
632 % This is an inherent disadvantage with this type of curve. The user's remedy
633 % is to increase the number of points to be plotted, but this can lead to
634 % \TeX{} running out of memory, not to mention the increased time to
635 % generate the drawing.
636 %
637 % \DescribeMacro{\setweightscale}
638 % \DescribeMacro{\resetweightscale}
639 % Because of the way in which \TeX{} performs arithmetic, and especially
640 % division, it
641 % is necessary to perform some scaling operations on the divisor when
642 % evaluating \eqref{eq:rqfinal}. The optimum value for the
643 % scaling is a complex function of the weight and the size and orientation
644 % of the control polygon. The algorithm uses a heuristic approach to
645 % calculate a `good' value but is not always successful. The
646 % |\setweightscale{|\meta{number}|}| command can be used to specify
647 % a scale factor. \meta{number} must be a positive integer. The
648 % |\resetweightscale| command resets the scale factor to its default
649 % value, which is currently 10000 (ten thousand).
650 %
651 % \begin{figure}
652 % \centering
653 % \setlength{\unitlength}{1mm}
654 % \begin{picture}(70,80)
655 % \put(0,5){\begin{picture}(30,30)
656 % \put(0,0){\circle{2}}
657 % \put(-2,0){\makebox(0,0)[br]{1}}
658 % \put(15,30){\circle{2}}
659 % \put(13,30){\makebox(0,0)[br]{0}}
660 % \put(30,0){\circle{2}}
661 % \put(32,0){\makebox(0,0)[bl]{2}}
662 % ^^A polygon
663 % \thinlines
664 % ^^A \put(15,30){\vector(-1,-2){15}}
665 % ^^A \put(0,0){\vector(1,0){30}}
666 % ^^A dashed line from 0 to 2
667 % ^^A \lbezier(15,30)(30,0)
668 % ^^A \lbezier[50](15,30)(30,0)
669 % ^^A \thinlines
670 % ^^A \put(15,26){\makebox(0,0){$\beta$}}
671 % \thicklines
672 % \setweightscale{100}
673 % \rqbezier[100](15,30)(0,0)(30,0)(4)
674 % \rqbezier[100](15,30)(0,0)(30,0)(2)
675 % \rqbezier(15,30)(0,0)(30,0)(1)
676 % \rqbezier[100](15,30)(0,0)(30,0)(0.75)
677 % \rqbezier[100](15,30)(0,0)(30,0)(0.5)
678 % \rqbezier[100](15,30)(0,0)(30,0)(0.25)
679 % \rqbezier(15,30)(0,0)(30,0)(0)
680 % \put(15,-5){\makebox(0,0)[b]{\texttt{weightscale = \theweightscale}}}
681 % \end{picture}}
682 % \put(0,45){\begin{picture}(30,30)
683 % \put(0,0){\circle{2}}
684 % \put(-2,0){\makebox(0,0)[br]{1}}
685 % \put(15,30){\circle{2}}
686 % \put(13,30){\makebox(0,0)[br]{0}}
687 % \put(30,0){\circle{2}}
688 % \put(32,0){\makebox(0,0)[bl]{2}}
689 % ^^A polygon
690 % \thinlines
691 % ^^A \put(15,30){\vector(-1,-2){15}}
692 % ^^A \put(0,0){\vector(1,0){30}}
693 % ^^A dashed line from 0 to 2
694 % ^^A \lbezier(15,30)(30,0)
695 % ^^A \lbezier[50](15,30)(30,0)
696 % ^^A \thinlines
697 % ^^A \put(15,26){\makebox(0,0){$\beta$}}
698 % \thicklines
699 % \setweightscale{1000}
700 % \rqbezier[100](15,30)(0,0)(30,0)(4)
701 % \rqbezier[100](15,30)(0,0)(30,0)(2)
702 % \rqbezier(15,30)(0,0)(30,0)(1)
703 % \rqbezier[100](15,30)(0,0)(30,0)(0.75)
704 % \rqbezier[100](15,30)(0,0)(30,0)(0.5)
705 % \rqbezier[100](15,30)(0,0)(30,0)(0.25)
706 % \rqbezier(15,30)(0,0)(30,0)(0)
707 % \put(15,-5){\makebox(0,0)[b]{\texttt{weightscale = \theweightscale}}}
708 % \end{picture}}
709 % \put(45,5){\begin{picture}(30,30)
710 % \put(0,0){\circle{2}}
711 % \put(-2,0){\makebox(0,0)[br]{1}}
712 % \put(15,30){\circle{2}}
713 % \put(13,30){\makebox(0,0)[br]{0}}
714 % \put(30,0){\circle{2}}
715 % \put(32,0){\makebox(0,0)[bl]{2}}
716 % ^^A polygon
717 % \thinlines
718 % ^^A \put(15,30){\vector(-1,-2){15}}
719 % ^^A \put(0,0){\vector(1,0){30}}
720 % ^^A dashed line from 0 to 2
721 % ^^A \lbezier(15,30)(30,0)
722 % ^^A \lbezier[50](15,30)(30,0)
723 % ^^A \thinlines
724 % ^^A \put(15,26){\makebox(0,0){$\beta$}}
725 % \thicklines
726 % \resetweightscale
727 % \rqbezier[100](15,30)(0,0)(30,0)(4)
728 % \rqbezier[100](15,30)(0,0)(30,0)(2)
729 % \rqbezier(15,30)(0,0)(30,0)(1)
730 % \rqbezier[100](15,30)(0,0)(30,0)(0.75)
731 % \rqbezier[100](15,30)(0,0)(30,0)(0.5)
732 % \rqbezier[100](15,30)(0,0)(30,0)(0.25)
733 % \rqbezier(15,30)(0,0)(30,0)(0)
734 % \put(15,-5){\makebox(0,0)[b]{\texttt{weightscale = \theweightscale}}}
735 % \end{picture}}
736 % \put(45,45){\begin{picture}(30,30)
737 % \put(0,0){\circle{2}}
738 % \put(-2,0){\makebox(0,0)[br]{1}}
739 % \put(15,30){\circle{2}}
740 % \put(13,30){\makebox(0,0)[br]{0}}
741 % \put(30,0){\circle{2}}
742 % \put(32,0){\makebox(0,0)[bl]{2}}
743 % ^^A polygon
744 % \thinlines
745 % ^^A \put(15,30){\vector(-1,-2){15}}
746 % ^^A \put(0,0){\vector(1,0){30}}
747 % ^^A dashed line from 0 to 2
748 % ^^A \lbezier(15,30)(30,0)
749 % ^^A \lbezier[50](15,30)(30,0)
750 % ^^A \thinlines
751 % ^^A \put(15,26){\makebox(0,0){$\beta$}}
752 % \thicklines
753 % \setweightscale{100000}
754 % \rqbezier[100](15,30)(0,0)(30,0)(4)
755 % \rqbezier[100](15,30)(0,0)(30,0)(2)
756 % \rqbezier(15,30)(0,0)(30,0)(1)
757 % \rqbezier[100](15,30)(0,0)(30,0)(0.75)
758 % \rqbezier[100](15,30)(0,0)(30,0)(0.5)
759 % \rqbezier[100](15,30)(0,0)(30,0)(0.25)
760 % \rqbezier(15,30)(0,0)(30,0)(0)
761 % \put(15,-5){\makebox(0,0)[b]{\texttt{weightscale = \theweightscale}}}
762 % \end{picture}}
763 % \end{picture}
764 % \setlength{\unitlength}{1pt}
765 % \resetweightscale
766 % \caption{The effect of \texttt{weightscale} on the drawing
767 % of rational quadratic Bezier curves}
768 % \label{fig:qrw}
769 % \end{figure}
770 %
771 % Figure~\ref{fig:qrw} illustrates the effect on changing the
772 % \texttt{weightscale} used for drawing the same curves as shown
773 % in figure~\ref{fig:qrb}. Note that the \texttt{weightscale}
774 % has no effect when
775 % $W = 1$ or $W = 0$ as in these cases the curves are drawn using the
776 % algorithms for the |\qbezier| and |\lbezier| commands respectively.
777 %
778 % It is obvious that some choices give very poorly formed curves. In
779 % other cases the curves may be poorly formed but do result in interesting
780 % cross-stitch like patterns.
781 %
782 % Table~\ref{tab:rq} indicates that it is possible to draw circular
783 % arcs using a rational quadratic Bezier curves. The two legs of the
784 % control polygon define the tangents to the curve at the
785 % end points.
786 % Therefore, to draw a circular arc the two legs must be equal in length.
787 % That is, the convex hull is an isosceles triangle. In the special case
788 % when the convex hull forms an equilateral triangle, the required
789 % weight ($\cos \beta$, see figure~\ref{fig:beta}) for drawing a circular
790 % arc is $\cos \beta = 0.5$. Further,
791 % for any given control polygon the the curves drawn with weights of
792 % $\pm W$ are complementary. That is, the curve with weight $-W$ is
793 % the `remainder' of the curve drawn with weight $W$. Thus, we have a
794 % simple means of drawing a complete circle, as shown in figure~\ref{fig:qrc}.
795 % The plotting commands of interest were:
796 % \begin{verbatim}
797 % \lbezier[25](0,0)(15,26)
798 % \lbezier[25](0,0)(30,0)
799 % \setweightscale{50000}
800 % \rqbezier[100](15,26)(0,0)(30,0)(0.5)
801 % \rqbezier[200](15,26)(0,0)(30,0)(-0.5)
802 % \resetweightscale
803 % \end{verbatim}
804 % where the |\lbezier| drawing commands were used to draw the dotted outline
805 % of the control polygon.
806 %
807 % \begin{figure}
808 % \centering
809 % \setlength{\unitlength}{1mm}
810 % \setweightscale{50000}
811 % \begin{picture}(60,62)
812 % \put(0,5){\begin{picture}(30,30)
813 % \thinlines
814 % \put(0,0){\circle{2}}
815 % \put(-2,0){\makebox(0,0)[br]{1}}
816 % \put(15,26){\circle{2}}
817 % \put(13,26){\makebox(0,0)[br]{0}}
818 % \put(30,0){\circle{2}}
819 % \put(32,0){\makebox(0,0)[bl]{2}}
820 % ^^A polygon
821 % \lbezier[25](0,0)(15,26)
822 % \lbezier[25](0,0)(30,0)
823 % ^^A RQBEZIER
824 % \thicklines
825 % \rqbezier[100](15,26)(0,0)(30,0)(0.5)
826 % \rqbezier[200](15,26)(0,0)(30,0)(-0.5)
827 % \end{picture}}
828 % \end{picture}
829 % \setlength{\unitlength}{1pt}
830 % \caption{Rational quadratics with weights of $\pm 0.5$ and an equilateral
831 % triangular convex hull
832 % (\texttt{weightscale = \theweightscale}) } \label{fig:qrc}
833 % \resetweightscale
834 % \end{figure}
835 %
836 % A more robust picture of the same circle is shown in
837 % figure~\ref{fig:qr3c} where the complete circle is pieced together from
838 % three non-complementary circular arcs. The drawing commands of interest
839 % were
840 % \begin{verbatim}
841 % \rqbezier[100](15,26)(0,0)(30,0)(0.5)
842 % \rqbezier[100](30,0)(60,0)(45,26)(0.5)
843 % \rqbezier[100](45,26)(30,52)(15,26)(0.5)
844 % \end{verbatim}
845 %
846 % \begin{figure}
847 % \centering
848 % \setlength{\unitlength}{1mm}
849 % \begin{picture}(60,62)
850 % \put(0,5){\begin{picture}(60,52)
851 % \thinlines
852 % \put(0,0){\circle{2}}
853 % ^^A \put(-2,0){\makebox(0,0)[br]{1}}
854 % \put(15,26){\circle{2}}
855 % ^^A \put(13,30){\makebox(0,0)[br]{0}}
856 % \put(30,0){\circle{2}}
857 % ^^A \put(32,0){\makebox(0,0)[bl]{2}}
858 % \put(60,0){\circle{2}}
859 % \put(45,26){\circle{2}}
860 % \put(30,52){\circle{2}}
861 % ^^A polygon
862 % \lbezier[50](0,0)(30,52)
863 % \lbezier[50](30,52)(60,0)
864 % \lbezier[50](0,0)(60,0)
865 % ^^A RQBEZIER
866 % \thicklines
867 % \rqbezier[100](15,26)(0,0)(30,0)(0.5)
868 % \rqbezier[100](30,0)(60,0)(45,26)(0.5)
869 % \rqbezier[100](45,26)(30,52)(15,26)(0.5)
870 % \end{picture}}
871 % \end{picture}
872 % \setlength{\unitlength}{1pt}
873 % \caption{Three rational quadratics with weights of $0.5$
874 % (\texttt{weightscale = \theweightscale}) }
875 % \label{fig:qr3c}
876 % \end{figure}
877 %
878 % The astute reader will have realised that the divisor in
879 % \eqref{eq:rqfinal} can go to zero, and can even be negative.
880 % This has interesting consequences, both when trying to do computer
881 % arithmetic, and also on the the kind of curve that results. Essentially,
882 % the curve tends to $\infty$ as $W \rightarrow +0$. At $W = -0$ the curve
883 % is at $-\infty$ and then it tends to $-0$ as $W \rightarrow -\infty$.
884 % We will get a curve point at $\infty$ whenever $W = -1$ and a `negative'
885 % curve for $W < -1$.
886 %
887 % \begin{figure}
888 % \centering
889 % \setlength{\unitlength}{1mm}
890 % \begin{picture}(60,60)
891 % \put(30,20){\begin{picture}(30,20)
892 % \thinlines
893 % \put(0,10){\circle{2}}
894 % \put(30,0){\circle{2}}
895 % \put(30,20){\circle{2}}
896 % ^^A polygon
897 % \lbezier[25](30,20)(0,10)
898 % \lbezier[25](0,10)(30,0)
899 % ^^A RQBEZIER
900 % \thicklines
901 % \rqbezier[100](30,20)(0,10)(30,0)(2)
902 % \rqbezier[100](30,20)(0,10)(30,0)(-2)
903 % \end{picture}}
904 % \end{picture}
905 % \setlength{\unitlength}{1pt}
906 % \caption{A rational quadratic that has gone negative; weights of $\pm 2$
907 % (\texttt{weightscale = \theweightscale}) }
908 % \label{fig:neg}
909 % \end{figure}
910 %
911 % This effect is shown in figure~\ref{fig:neg} which draws the two branches
912 % of a hyperbola. The basic code for the illustration was
913 % \begin{verbatim}
914 % \lbezier[25](30,20)(0,10)
915 % \lbezier[25](0,10)(30,0)
916 % \rqbezier[100](30,20)(0,10)(30,0)(2)
917 % \rqbezier[100](30,20)(0,10)(30,0)(-2)
918 % \end{verbatim}
919 % where the control polygon was drawn using the |\lbezier| commands.
920 %
921 %
922 % \section{The \Lpack{bez123} package implementation} \label{sec:bez}
923 %
924 % \LaTeX{} provides a facility for drawing quadratic Bezier curves.
925 % This package provides additional facilities for drawing linear,
926 % rational quadratic, and cubic Bezier curves.
927 %
928 %
929 % Announce the name and version of the package, which requires \LaTeXe.
930 % \begin{macrocode}
931 %<*bez>
932 \NeedsTeXFormat{LaTeX2e}
933 \ProvidesPackage{bez123}[2009/09/02 v1.1b Bezier curves]
934 % \end{macrocode}
935 % \changes{v1.1}{1998/10/14}{Added call to include multiply package}
936 % The package also requires the \Lpack{multiply} package.
937 % \begin{macrocode}
938 \RequirePackage{multiply}[2009/09/02]
939 %</bez>
940 % \end{macrocode}
941 %
942 %
943 % \subsection{Arithmetic in \TeX}
944 %
945 % All arithmetic in \TeX{} is based on integer arithmetic, with a
946 % maximum integer value of $M = \number\maxdimen$. For example,
947 % \setcounter{weightscale}{8}\makeatletter\divide\c@weightscale by 3\makeatother
948 % $8/3 = \theweightscale$,
949 % \setcounter{weightscale}{9}\makeatletter\divide\c@weightscale by 3\makeatother
950 % $9/3 = \theweightscale$, and
951 % \setcounter{weightscale}{10}\makeatletter\divide\c@weightscale by 3\makeatother
952 % $10/3 = \theweightscale$.
953 % In other words, division always reduces the absolute value of the dividend,
954 % and also possibly truncates the value. One consequence of this is that the
955 % ordering of multiplication and division is important. For instance,
956 % \setcounter{weightscale}{8}\makeatletter\multiply\c@weightscale by 3 \divide\c@weightscale by 3\makeatother
957 % $(8 \times 3)/3 = \theweightscale$ but
958 % \setcounter{weightscale}{8}\makeatletter\divide\c@weightscale by 3 \multiply\c@weightscale by 3\makeatother
959 % $(8/3) \times 3 = \theweightscale$!
960 % Thus, in arithmetic calculations involving both multiplication and
961 % division, the dividend should be maximised and the divisor minimised,
962 % with multiplication preceeding division; also remembering that there
963 % is a limit on the size of an integer. To avoid multiplication overflow
964 % when calculating say, $a \times b$, we must ensure that
965 % $\|a\| \leq \|M/b\|$.
966 %
967 % When calculating polynomials, such as that in \eqref{eq:gen},
968 % we use a technique called Horner's schema, which is also known as nested
969 % multiplication. A general cubic equation, for example, can be written as:
970 % \begin{equation}
971 % p(t) - a_{0} = t(a_{1} + t(a_{2} + ta_{3})) \label{eq:horn}
972 % \end{equation}
973 % The following pseudo-code shows one way to implement Horner's schema for
974 % plotting $N$ points in the interval $0 \leq t \leq 1$
975 % of \eqref{eq:horn} using integer arithmetic.
976 % \begin{verbatim}
977 % procedure plot_cubic(a0, a1, a2, a3:vector; N:integer);
978 % local p:vector; end_local;
979 % a3 := a3/N;
980 % repeat i := 0 to N by 1;
981 % p := a3*i;
982 % p := p + a2; p := p/N; p := p*i;
983 % p := p + a1; p := p/N; p := p*i;
984 % draw(p + a0);
985 % end_repeat;
986 % return;
987 % end_procedure;
988 % \end{verbatim}
989 % We use the above algorithm, with suitable modifications according to the
990 % degree of the polynomial, for plotting the points along Bezier curves.
991 %
992 % \subsection{Linear Bezier curves}
993 %
994 % \begin{macrocode}
995 %<*bez>
996 % \end{macrocode}
997 %
998 % As a linear curve is simpler than a quadratic curve there is no
999 % need to declare extra variables from those used in the kernel by the
1000 % |\qbezier| macro.
1001 %
1002 % \begin{macro}{\lbezier}
1003 % The user command to draw a linear Bezier curve represented by
1004 % \eqref{eq:lin3}. The form of the command is:\\
1005 % |\lbezier[|\meta{N}|]{(|\meta{p0}|)(|\meta{p1}|)| \\
1006 % where \meta{pN} is the comma seperated X and Y coordinate values of
1007 % point \textit{pN}.
1008 %
1009 % \begin{macrocode}
1010 \newcommand{\lbezier}[2][0]{\@lbez{#1}#2}
1011 % \end{macrocode}
1012 % \end{macro}
1013 %
1014 % \begin{macro}{\@lbez}
1015 % The drawing macro.
1016 % \begin{macrocode}
1017 \gdef\@lbez#1(#2,#3)(#4,#5){%
1018 %%%%\def\lbezier#1(#2,#3)(#4,#5){%
1019 \ifnum #1<\@ne
1020 % \end{macrocode}
1021 % When the number of plotting points are not given, then we calculate
1022 % how many are needed. First determine the X distance between the end points.
1023 % \begin{macrocode}
1024 \@ovxx = #4\unitlength
1025 \advance\@ovxx by -#2\unitlength
1026 \ifdim \@ovxx < \z@
1027 \@ovxx = -\@ovxx
1028 \fi
1029 % \end{macrocode}
1030 % Similarly calculate the Y distance.
1031 % \begin{macrocode}
1032 \@ovyy = #5\unitlength
1033 \advance\@ovyy by -#3\unitlength
1034 \ifdim \@ovyy < \z@
1035 \@ovyy = -\@ovyy
1036 \fi
1037 % \end{macrocode}
1038 % Temporarily store the maximum distance in |\@multicnt|.
1039 % \begin{macrocode}
1040 \ifdim \@ovxx > \@ovyy
1041 \@multicnt = \@ovxx
1042 \else
1043 \@multicnt = \@ovyy
1044 \fi
1045 % \end{macrocode}
1046 % We use a small square as the visual representation of a point.
1047 % Calculate the number of points required to give 50\% overlap of adjacent
1048 % squares, making
1049 % sure that it doesn't exceed the limit. Store the result in |\@multicnt|.
1050 % \begin{macrocode}
1051 \@ovxx = 0.5\@halfwidth
1052 \divide\@multicnt by \@ovxx
1053 \ifnum \qbeziermax < \@multicnt
1054 \@multicnt = \qbeziermax\relax
1055 \fi
1056 \else
1057 % \end{macrocode}
1058 % The number of points is given.
1059 % \begin{macrocode}
1060 \@multicnt = #1\relax
1061 \fi
1062 % \end{macrocode}
1063 %
1064 % Now we can prepare the constants for the plotting loop.
1065 % \begin{macrocode}
1066 \@tempcnta = \@multicnt
1067 \advance\@tempcnta by \@ne
1068 \@ovdx = #4\unitlength
1069 \advance\@ovdx by -#2\unitlength
1070 \divide\@ovdx by \@multicnt
1071 \@ovdy = #5\unitlength
1072 \advance\@ovdy by -#3\unitlength
1073 \divide\@ovdy by \@multicnt
1074 % \end{macrocode}
1075 % The next bit of code defines the size of the square representing a point.
1076 % \begin{macrocode}
1077 \setbox\@tempboxa\hbox{\vrule \@height\@halfwidth
1078 \@depth \@halfwidth
1079 \@width \@wholewidth}%
1080 % \end{macrocode}
1081 % Start the plot at the first point.
1082 % \begin{macrocode}
1083 \put(#2,#3){%
1084 \count@ = \z@
1085 \@whilenum{\count@ < \@tempcnta}\do
1086 % \end{macrocode}
1087 % Evaluate the polynomial (simple in this case) using Horner's schema.
1088 % \begin{macrocode}
1089 {\@xdim = \count@\@ovdx
1090 \@ydim = \count@\@ovdy
1091 % \end{macrocode}
1092 % Plot this point.
1093 % \begin{macrocode}
1094 \raise \@ydim
1095 \hb@xt@\z@{\kern\@xdim
1096 \unhcopy\@tempboxa\hss}%
1097 \advance\count@\@ne}}%
1098 % \end{macrocode}
1099 % The end of the definition of |\@lbez|.
1100 % \begin{macrocode}
1101 }
1102 % \end{macrocode}
1103 % \end{macro}
1104 %
1105 % \subsection{Cubic Bezier curves}
1106 %
1107 % As cubic curves are more complex than quadratic curves we need some
1108 % extra variables.
1109 % \begin{macro}{\@wxc}
1110 % \begin{macro}{\@wyc}
1111 % Lengths.
1112 % \begin{macrocode}
1113 \newlength{\@wxc}
1114 \newlength{\@wyc}
1115 % \end{macrocode}
1116 % \end{macro}
1117 % \end{macro}
1118 %
1119 % \begin{macro}{\cbezier}
1120 % The user command for drawing a cubic Bezier curve as represented
1121 % by \eqref{eq:cubic}. It is called as: \\
1122 % |\cbezier[|\meta{N}|](|\meta{p0}|)(|\meta{p1}|)(|\meta{p2}|)(|\meta{p3}|)|.
1123 %
1124 % \begin{macrocode}
1125 \newcommand{\cbezier}[2][0]{\@cbez{#1}#2}
1126 % \end{macrocode}
1127 % \end{macro}
1128 %
1129 % \begin{macro}{\@cbez}
1130 % The drawing macro for cubic Bezier curves.
1131 % \begin{macrocode}
1132 \gdef\@cbez#1(#2,#3)(#4,#5)(#6,#7)(#8,#9){%
1133 \ifnum #1<\@ne
1134 % \end{macrocode}
1135 % We have to calculate the number of plotting points required. We will
1136 % use the maximum of the box enclosing the convex hull as a measure.
1137 % First do the X value, using |\@ovxx| to store the maximum X coordinate
1138 % and |\@ovdx| the minimum.
1139 % \begin{macrocode}
1140 \@ovxx = #2\unitlength
1141 \@ovdx = \@ovxx
1142 \@ovdy = #4\unitlength
1143 \ifdim \@ovdy > \@ovxx
1144 \@ovxx = \@ovdy
1145 \fi
1146 \ifdim \@ovdy < \@ovdx
1147 \@ovdx = \@ovdy
1148 \fi
1149 \@ovdy = #6\unitlength
1150 \ifdim \@ovdy > \@ovxx
1151 \@ovxx = \@ovdy
1152 \fi
1153 \ifdim \@ovdy < \@ovdx
1154 \@ovdx = \@ovdy
1155 \fi
1156 \@ovdy = #8\unitlength
1157 \ifdim \@ovdy > \@ovxx
1158 \@ovxx = \@ovdy
1159 \fi
1160 \ifdim \@ovdy < \@ovdx
1161 \@ovdx = \@ovdy
1162 \fi
1163 % \end{macrocode}
1164 % Store the maximum X in |\@ovxx|.
1165 % \begin{macrocode}
1166 \advance\@ovxx by -\@ovdx
1167 % \end{macrocode}
1168 % Repeat the process for the maximum Y value, finally storing
1169 % this in |\@ovyy|.
1170 % \begin{macrocode}
1171 \@ovyy = #3\unitlength
1172 \@ovdy = \@ovyy
1173 \@ovdx = #5\unitlength
1174 \ifdim \@ovdx > \@ovyy
1175 \@ovyy = \@ovdx
1176 \fi
1177 \ifdim \@ovdx < \@ovdy
1178 \@ovdy = \@ovdx
1179 \fi
1180 \@ovdx = #7\unitlength
1181 \ifdim \@ovdx > \@ovyy
1182 \@ovyy = \@ovdx
1183 \fi
1184 \ifdim \@ovdx < \@ovdy
1185 \@ovdy = \@ovdx
1186 \fi
1187 \@ovdx = #9\unitlength
1188 \ifdim \@ovdx > \@ovyy
1189 \@ovyy = \@ovdx
1190 \fi
1191 \ifdim \@ovdx < \@ovdy
1192 \@ovdy = \@ovdx
1193 \fi
1194 \advance\@ovyy by -\@ovdy
1195 % \end{macrocode}
1196 % Temporarily store the max of X and Y in |\@multicnt|.
1197 % \begin{macrocode}
1198 \ifdim \@ovxx > \@ovyy
1199 \@multicnt = \@ovxx
1200 \else
1201 \@multicnt = \@ovyy
1202 \fi
1203 % \end{macrocode}
1204 % Calculate the number of points required to give 50\% overlap, making
1205 % sure that it doesn't exceed the limit. Store the number of points in
1206 % |\@multicnt|.
1207 % \begin{macrocode}
1208 \@ovxx = 0.5\@halfwidth
1209 \divide\@multicnt by \@ovxx
1210 \ifnum \qbeziermax < \@multicnt
1211 \@multicnt = \qbeziermax\relax
1212 \fi
1213 \else
1214 % \end{macrocode}
1215 % The number of points is given.
1216 % \begin{macrocode}
1217 \@multicnt = #1\relax
1218 \fi
1219 % \end{macrocode}
1220 %
1221 % Now we can prepare the constants for the plotting loop. First the control
1222 % counts.
1223 % \begin{macrocode}
1224 \@tempcnta = \@multicnt
1225 \advance\@tempcnta by \@ne
1226 % \end{macrocode}
1227 % Then the cubic coefficients, firstly for X.
1228 % \begin{macrocode}
1229 \@ovdx = #4\unitlength \advance\@ovdx by -#2\unitlength
1230 \@ovxx = #6\unitlength \advance\@ovxx by -\@ovdx
1231 \multiply\@ovdx by \thr@@
1232 \advance\@ovxx by -#4\unitlength \multiply\@ovxx by \thr@@
1233 \@wxc = #4\unitlength \advance\@wxc by -#6\unitlength
1234 \multiply\@wxc by \thr@@ \advance\@wxc by #8\unitlength
1235 \advance\@wxc by -#2\unitlength \divide\@wxc by \@multicnt
1236 % \end{macrocode}
1237 % And similarly for Y.
1238 % \begin{macrocode}
1239 \@ovdy = #5\unitlength \advance\@ovdy by -#3\unitlength
1240 \@ovyy = #7\unitlength \advance\@ovyy by -\@ovdy
1241 \multiply\@ovdy by \thr@@
1242 \advance\@ovyy by -#5\unitlength \multiply\@ovyy by \thr@@
1243 \@wyc = #5\unitlength \advance\@wyc by -#7\unitlength
1244 \multiply\@wyc by \thr@@ \advance\@wyc by #9\unitlength
1245 \advance\@wyc by -#3\unitlength \divide\@wyc by \@multicnt
1246 % \end{macrocode}
1247 % Set up the plotting box.
1248 % \begin{macrocode}
1249 \setbox\@tempboxa\hbox{\vrule \@height\@halfwidth
1250 \@depth \@halfwidth
1251 \@width \@wholewidth}%
1252 % \end{macrocode}
1253 % Start the plot at the first point.
1254 % \begin{macrocode}
1255 \put(#2,#3){%
1256 \count@ = \z@
1257 \@whilenum{\count@ < \@tempcnta}\do
1258 {\@xdim = \count@\@wxc
1259 \advance\@xdim by \@ovxx
1260 \divide\@xdim by \@multicnt
1261 \multiply\@xdim by \count@
1262 \advance\@xdim by \@ovdx
1263 \divide\@xdim by \@multicnt
1264 \multiply\@xdim by \count@
1265 \@ydim = \count@\@wyc
1266 \advance\@ydim by \@ovyy
1267 \divide\@ydim by \@multicnt
1268 \multiply\@ydim by \count@
1269 \advance\@ydim by \@ovdy
1270 \divide\@ydim by \@multicnt
1271 \multiply\@ydim by \count@
1272 % \end{macrocode}
1273 % Plot the point.
1274 % \begin{macrocode}
1275 \raise \@ydim
1276 \hb@xt@\z@{\kern\@xdim
1277 \unhcopy\@tempboxa\hss}%
1278 \advance\count@\@ne}}%
1279 % \end{macrocode}
1280 % The end of the definition of |\@cbez|.
1281 % \begin{macrocode}
1282 }
1283 % \end{macrocode}
1284 % \end{macro}
1285 %
1286 %
1287 % \subsection{Quadratic rational Bezier curve}
1288 %
1289 % This is the most complex of the Bezier curves that we deal with.
1290 % We need yet more variables.
1291 %
1292 % \begin{macro}{\@ww}
1293 % \begin{macro}{\@wwa}
1294 % \begin{macro}{\@wwb}
1295 % \begin{macro}{\@wwo}
1296 % \begin{macro}{\@wwi}
1297 % Variables for the weight calculations.
1298 % \begin{macrocode}
1299 \newlength{\@ww}
1300 \newlength{\@wwa}
1301 \newlength{\@wwb}
1302 \newlength{\@wwo}
1303 \newlength{\@wwi}
1304 % \end{macrocode}
1305 % \end{macro}
1306 % \end{macro}
1307 % \end{macro}
1308 % \end{macro}
1309 % \end{macro}
1310 %
1311 % \begin{macro}{\c@@pntscale}
1312 % Scale factor for points.
1313 % \begin{macrocode}
1314 \newcounter{@pntscale}
1315 % \end{macrocode}
1316 % \end{macro}
1317 %
1318 % \begin{macro}{\c@weightscale}
1319 % Scale factor for divisor.
1320 % \begin{macrocode}
1321 \newcounter{weightscale}
1322 % \end{macrocode}
1323 % \end{macro}
1324 %
1325 % \begin{macro}{\botscale}
1326 % Scale factor for bottom weights.
1327 % \begin{macrocode}
1328 \newlength{\botscale}
1329 % \end{macrocode}
1330 % \end{macro}
1331 %
1332 % \begin{macro}{\setweightscale}
1333 % User level command |\setweightscale{|\meta{number}|}| for setting the
1334 % divisor scaling.
1335 % \begin{macrocode}
1336 \newcommand{\setweightscale}[1]{\setcounter{weightscale}{#1}}
1337 % \end{macrocode}
1338 % \end{macro}
1339 %
1340 % \begin{macro}{\resetweightscale}
1341 % User level command for setting the divisor scaling to its default
1342 % value ($10^{4}$). We also ensure that the scaling is set to this value.
1343 % \begin{macrocode}
1344 \newcommand{\resetweightscale}{\setcounter{weightscale}{10000}}
1345 \resetweightscale
1346 % \end{macrocode}
1347 % \end{macro}
1348 %
1349 % \begin{macro}{\rqbezier}
1350 % The user level command for drawing a rational quadratic Bezier curve
1351 % as represented by \eqref{eq:rqfinal}. The form of the command is \\
1352 % |\rqbezier[|\meta{N}|](|\meta{p0}|)(|\meta{p1}|)(|\meta{p2}|)(|\meta{W}|)| \\
1353 % where the arguments are as per the other Bezier drawing commands, but with
1354 % the final argument being the weight.
1355 %
1356 % \begin{macrocode}
1357 \newcommand{\rqbezier}[2][0]{\@rqbez{#1}#2}
1358 % \end{macrocode}
1359 % \end{macro}
1360 %
1361 %
1362 % \begin{macro}{\@rqbez}
1363 % The drawing macro for a rational quadratic Bezier curve. If the weight
1364 % is such that the curve is either rational quadratic ($W = 1$) or
1365 % linear ($W = 0$), we use the simpler drawing macro.
1366 % \begin{macrocode}
1367 \gdef\@rqbez#1(#2,#3)(#4,#5)(#6,#7)(#8){%
1368 \@ovxx = #8\unitlength
1369 \ifdim\@ovxx = \unitlength
1370 \PackageWarning{bez123}{Rational quadratic denerates to quadratic}
1371 \qbezier[#1](#2,#3)(#4,#5)(#6,#7)
1372 \else
1373 \ifdim\@ovxx = \z@
1374 \PackageWarning{bez123}{Rational quadratic degenerates to linear}
1375 \lbezier[#1](#2,#3)(#6,#7)
1376 \else
1377 % \end{macrocode}
1378 % Calculate the maximum length of the control polygon's bounding box.
1379 % Store the result in |\@wwi|.
1380 % \begin{macrocode}
1381 \@ovxx = #4\unitlength
1382 \advance\@ovxx by -#2\unitlength
1383 \ifdim \@ovxx < \z@
1384 \@ovxx = -\@ovxx
1385 \fi
1386 \@ovdx = #6\unitlength
1387 \advance\@ovdx by -#4\unitlength
1388 \ifdim \@ovdx < \z@
1389 \@ovdx = -\@ovdx
1390 \fi
1391 \ifdim \@ovxx < \@ovdx
1392 \@ovxx = \@ovdx
1393 \fi
1394 \@ovyy = #5\unitlength
1395 \advance\@ovyy by -#3\unitlength
1396 \ifdim \@ovyy < \z@
1397 \@ovyy = -\@ovyy
1398 \fi
1399 \@ovdy = #7\unitlength
1400 \advance\@ovdy by -#5\unitlength
1401 \ifdim \@ovdy < \z@
1402 \@ovdy = -\@ovdy
1403 \fi
1404 \ifdim \@ovyy < \@ovdy
1405 \@ovyy = \@ovdy
1406 \fi
1407 \ifdim \@ovxx > \@ovyy
1408 \@multicnt = \@ovxx
1409 \else
1410 \@multicnt = \@ovyy
1411 \fi
1412 \@wwi = \@multicnt sp
1413 % \end{macrocode}
1414 % Now determine the number of points to be plotted.
1415 % \begin{macrocode}
1416 \ifnum #1<\@ne
1417 \@ovxx = 0.5\@halfwidth
1418 \divide\@multicnt by \@ovxx
1419 \ifnum\qbeziermax < \@multicnt
1420 \@multicnt = \qbeziermax\relax
1421 \fi
1422 \else
1423 % \end{macrocode}
1424 % Number of points is a given.
1425 % \begin{macrocode}
1426 \@multicnt = #1\relax
1427 \fi
1428 % \end{macrocode}
1429 % We are going to plot the curve in two halves in an attempt to reduce
1430 % roundoff problems. At
1431 % a minimum this should at least make a symmetrical curve look symmetric
1432 % about its mid point.
1433 % \begin{macrocode}
1434 \@tempcnta = \@multicnt
1435 \advance\@tempcnta by \@ne
1436 \divide\@tempcnta by \tw@
1437 \advance\@tempcnta by \@ne
1438 % \end{macrocode}
1439 % We now have to deal with a possible multiplication overflow problem due
1440 % to multiplication by the weight. In \eqref{eq:rqfinal} the potentially
1441 % largest term is the coefficient of $t^{2}$ (i.e., $(l_{20}-2Wl_{10})$).
1442 % The maximum length likely to be encountered is, say, 10 inches for a
1443 % drawing on either A4 or US letterpaper. This is approximately
1444 % $4.8\times10^{8}$sp. Doing a little arithmetic, and remembering that the
1445 % maximum length in \TeX{} is $M = \number\maxdimen$sp, it means that we must
1446 % have $\|W\| \leq 1$ to prevent overflow. However, a typical range for
1447 % $W$ is $-10 \leq W \leq 10$. Therefore we might have to do some scaling.
1448 % Being pessimistic, we'll assume that $l_{20} = - l_{10}$ and that $l_{10}$
1449 % is the largest dimension in the drawing. To prevent overflow we then have to
1450 % meet the condition $\|W\| \leq (M - l_{20})/2l_{20}$, where all lengths are
1451 % positive. We will use |\c@@pntscale| as a scale factor on $W$ to meet this
1452 % condition. Earlier we set |\@wwi| to be the positive value of the largest
1453 % dimension in the drawing.
1454 %
1455 % Set the distance scale factor. First evaluating the test condition.
1456 % \begin{macrocode}
1457 \@wwo = \maxdimen
1458 \advance\@wwo by -\@wwi
1459 \divide\@wwo by \tw@
1460 \divide\@wwo by \@wwi
1461 % \end{macrocode}
1462 % Now perform the check and set the scale factor. We have to get a positive
1463 % integer value for $W$ as it may be a fraction. Actually, we only need to
1464 % be concerned if $\|W\| > 1$.
1465 % \begin{macrocode}
1466 \@wwi = 10sp
1467 \@wwi = #8\@wwi
1468 \ifdim\@wwi < \z@
1469 \@wwi = -\@wwi
1470 \fi
1471 \divide\@wwi by 10\relax
1472 \ifdim\@wwi < \@wwo
1473 \c@@pntscale = \@ne
1474 \else
1475 \divide\@wwi by \tw@
1476 \ifdim\@wwi < \@wwo
1477 \c@@pntscale = \tw@
1478 \else
1479 \divide\@wwi by \tw@
1480 \ifdim\@wwi < \@wwo
1481 \c@@pntscale = 4\relax
1482 \else
1483 \divide\@wwi by \tw@
1484 \ifdim\@wwi < \@wwo
1485 \c@@pntscale = 8\relax
1486 \else
1487 \c@@pntscale = 16\relax
1488 \fi
1489 \fi
1490 \fi
1491 \fi
1492 % \end{macrocode}
1493 % Calculate the constants for the top line of the function.
1494 % \begin{macrocode}
1495 \@ovxx = #4\unitlength \advance\@ovxx by -#2\unitlength
1496 \multiply\@ovxx by \tw@
1497 \divide\@ovxx by \c@@pntscale
1498 \@ovdx = #8\@ovxx
1499 \@ovxx = #6\unitlength \advance\@ovxx by -#2\unitlength
1500 \divide\@ovxx by \c@@pntscale
1501 \advance\@ovxx by -\@ovdx
1502 \divide\@ovxx by \@multicnt
1503 \@ovyy = #5\unitlength \advance\@ovyy by -#3\unitlength
1504 \multiply\@ovyy by \tw@
1505 \divide\@ovyy by \c@@pntscale
1506 \@ovdy = #8\@ovyy
1507 \@ovyy = #7\unitlength \advance\@ovyy by -#3\unitlength
1508 \divide\@ovyy by \c@@pntscale
1509 \advance\@ovyy by -\@ovdy
1510 \divide\@ovyy by \@multicnt
1511 % \end{macrocode}
1512 % Now the constants for the bottom line. We also need to do some scaling
1513 % here. This scaling can be set by the user.
1514 % \begin{macrocode}
1515 \setlength{\botscale}{\c@weightscale sp}
1516 \@wwo = \botscale
1517 \@wwi = #8\@wwo
1518 \@wwa = \@wwo \advance\@wwa by -\@wwi
1519 \multiply\@wwa by \tw@
1520 \@wwb = \@wwa
1521 \divide\@wwb by \@multicnt
1522 % \end{macrocode}
1523 % Prepare for the drawing.
1524 % \begin{macrocode}
1525 \@wwi = \botscale
1526 \setbox\@tempboxa\hbox{\vrule \@height\@halfwidth
1527 \@depth \@halfwidth
1528 \@width \@wholewidth}%
1529 % \end{macrocode}
1530 % Draw the first half of the curve.
1531 % \begin{macrocode}
1532 \put(#2,#3){%
1533 \count@ = \z@
1534 \@whilenum{\count@ < \@tempcnta}\do
1535 {\@xdim = \count@\@ovxx
1536 \advance\@xdim by \@ovdx
1537 \divide\@xdim by \@multicnt
1538 \multiply\@xdim by \count@
1539 \@ydim = \count@\@ovyy
1540 \advance\@ydim by \@ovdy
1541 \divide\@ydim by \@multicnt
1542 \multiply\@ydim by \count@
1543 \@ww = \count@\@wwb
1544 \advance\@ww by -\@wwa
1545 \divide\@ww by \@multicnt
1546 \multiply\@ww by \count@
1547 \advance\@ww by \@wwo
1548 \divide\@ww by \c@@pntscale
1549 \ifdim\@ww = \z@
1550 % \end{macrocode}
1551 % We are about to divide by |\@ww| which is zero. Treat |\@ww| as unity.
1552 % \begin{macrocode}
1553 \else
1554 \divide\@xdim by \@ww
1555 \divide\@ydim by \@ww
1556 \fi
1557 % \end{macrocode}
1558 % For reasons I don't understand, the \% signs at the end of the next few
1559 % lines are important!
1560 % \begin{macrocode}
1561 \multnooverflow{\@xdim}{\botscale}%
1562 \multnooverflow{\@ydim}{\botscale}%
1563 \raise \@ydim
1564 \hb@xt@\z@{\kern\@xdim
1565 \unhcopy\@tempboxa\hss}%
1566 \advance\count@\@ne}}
1567 % \end{macrocode}
1568 %
1569 % We now repeat the above process for plotting the second half of the
1570 % curve, starting at the end point.
1571 %
1572 % Calculate the constants for the top line of the function.
1573 % \begin{macrocode}
1574 \@ovxx = #4\unitlength \advance\@ovxx by -#6\unitlength
1575 \multiply\@ovxx by \tw@
1576 \divide\@ovxx by \c@@pntscale
1577 \@ovdx = #8\@ovxx
1578 \@ovxx = #2\unitlength \advance\@ovxx by -#6\unitlength
1579 \divide\@ovxx by \c@@pntscale
1580 \advance\@ovxx by -\@ovdx
1581 \divide\@ovxx by \@multicnt
1582 \@ovyy = #5\unitlength \advance\@ovyy by -#7\unitlength
1583 \multiply\@ovyy by \tw@
1584 \divide\@ovyy by \c@@pntscale
1585 \@ovdy = #8\@ovyy
1586 \@ovyy = #3\unitlength \advance\@ovyy by -#7\unitlength
1587 \divide\@ovyy by \c@@pntscale
1588 \advance\@ovyy by -\@ovdy
1589 \divide\@ovyy by \@multicnt
1590 % \end{macrocode}
1591 % The constants for the bottom line are the same as before as the function
1592 % is symmetric. Similarly we don't need to recalculate the size of the
1593 % rule box.
1594 %
1595 % Draw the second half of the curve.
1596 % \begin{macrocode}
1597 \put(#6,#7){%
1598 \count@ = \z@
1599 \@whilenum{\count@ < \@tempcnta}\do
1600 {\@xdim = \count@\@ovxx
1601 \advance\@xdim by \@ovdx
1602 \divide\@xdim by \@multicnt
1603 \multiply\@xdim by \count@
1604 \@ydim = \count@\@ovyy
1605 \advance\@ydim by \@ovdy
1606 \divide\@ydim by \@multicnt
1607 \multiply\@ydim by \count@
1608 \@ww = \count@\@wwb
1609 \advance\@ww by -\@wwa
1610 \divide\@ww by \@multicnt
1611 \multiply\@ww by \count@
1612 \advance\@ww by \@wwo
1613 \divide\@ww by \c@@pntscale
1614 \ifnum\@ww = \z@
1615 % \end{macrocode}
1616 % We are about to divide by |\@ww| which is zero. Treat |\@ww| as unity.
1617 % \begin{macrocode}
1618 \else
1619 \divide\@xdim by \@ww
1620 \divide\@ydim by \@ww
1621 \fi
1622 % \end{macrocode}
1623 % For reasons I don't understand, the \% signs at the end of the next few
1624 % lines are important!
1625 % \begin{macrocode}
1626 \multnooverflow{\@xdim}{\botscale}%
1627 \multnooverflow{\@ydim}{\botscale}%
1628 \raise \@ydim
1629 \hb@xt@\z@{\kern\@xdim
1630 \unhcopy\@tempboxa\hss}%
1631 \advance\count@\@ne}}
1632 % \end{macrocode}
1633 % End of definition of |\@rqbez|.
1634 % \begin{macrocode}
1635 \fi\fi}
1636 % \end{macrocode}
1637 % \end{macro}
1638 %
1639 % The end of this package.
1640 % \begin{macrocode}
1641 %</bez>
1642 % \end{macrocode}
1643 %
1644 % \section{Multiplication without overflow: The \Lpack{multiply} package} \label{sec:mnoflow}
1645 %
1646 % \TeX{} provides for integer arithmetic, subject to an upper limit
1647 % given by |\maxdim|. For at least the \Lpack{bez123} package we need to
1648 % be able to multiply without overflow.
1649 %
1650 % Announce the name of the package.
1651 % \changes{v1.1}{1998/10/14}{Put multnooverflow into a seperate package}
1652 % \begin{macrocode}
1653 %<*mult>
1654 \ProvidesPackage{multiply}[1998/10/14 v1.1 Multiplication of lengths without overflow]
1655 % \end{macrocode}
1656 %
1657 % \begin{macro}{\n@fl@wa}
1658 % \begin{macro}{\n@fl@wb}
1659 % \begin{macro}{\n@fl@wc}
1660 % \begin{macro}{\ifch@nge}
1661 % We need three length variables for this function.
1662 % We also need a boolean flag for dealing with negative numbers.
1663 % \begin{macrocode}
1664 \newlength{\n@fl@wa}
1665 \newlength{\n@fl@wb}
1666 \newlength{\n@fl@wc}
1667 \newif\ifch@nge
1668 % \end{macrocode}
1669 % \end{macro}
1670 % \end{macro}
1671 % \end{macro}
1672 % \end{macro}
1673 %
1674 % \begin{macro}{\multnooverflow}
1675 %
1676 % The routine |\multnooverflow{|\meta{a}|}{|\meta{b}|}| sets
1677 % $a$ to the minimum of $ab$ and |\maxdimen|, preserving signs. \meta{a}
1678 % must be a length; it must not be a number literal.
1679 %
1680 % \begin{macrocode}
1681 \newcommand{\multnooverflow}[2]{%
1682 \n@fl@wa = #1\relax%
1683 \n@fl@wb = #2\relax%
1684 \ch@ngefalse%
1685 % \end{macrocode}
1686 % Easy if $-1 \leq b \leq 1$.
1687 % \begin{macrocode}
1688 \ifnum\n@fl@wb = \@ne%
1689 \else%
1690 \ifnum\n@fl@wb = \z@%
1691 \n@fl@wa = \z@%
1692 \else%
1693 \ifnum\n@fl@wb = \m@ne%
1694 \ch@ngetrue%
1695 \else%
1696 % \end{macrocode}
1697 % Also easy if $-1 \leq a \leq 1$.
1698 % \begin{macrocode}
1699 \ifnum\n@fl@wa = \z@%
1700 \else%
1701 \ifnum\n@fl@wa = \@ne%
1702 \n@fl@wa = \n@fl@wb%
1703 \else%
1704 \ifnum\n@fl@wa = \m@ne%
1705 \n@fl@wa = -\n@fl@wb%
1706 \else%
1707 % \end{macrocode}
1708 % We have to check for potential overflow. First make sure that we deal
1709 % only with positive values.
1710 % \begin{macrocode}
1711 \ifnum\n@fl@wa < \z@%
1712 \ch@ngetrue%
1713 \n@fl@wa = -\n@fl@wa%
1714 \fi%
1715 \ifnum\n@fl@wb < \z@%
1716 \n@fl@wb = -\n@fl@wb%
1717 \ifch@nge%
1718 \ch@ngefalse%
1719 \else%
1720 \ch@ngetrue%
1721 \fi%
1722 \fi%
1723 % \end{macrocode}
1724 % Check for overflow.
1725 % \begin{macrocode}
1726 \n@fl@wc = \maxdimen%
1727 \divide\n@fl@wc by \n@fl@wb%
1728 \advance\n@fl@wc by -1sp% \m@ne
1729 \ifnum\n@fl@wa > \n@fl@wc%
1730 % \end{macrocode}
1731 % We have overflow. Set the multiplication result to |\maxdimen|.
1732 % \begin{macrocode}
1733 \n@fl@wa = \maxdimen%
1734 \PackageWarning{multiply}{Multiplication overflow}%
1735 \else%
1736 % \end{macrocode}
1737 % It is safe to do the multiplication.
1738 % \begin{macrocode}
1739 \multiply\n@fl@wa by \n@fl@wb%
1740 \fi%
1741 \fi%
1742 \fi%
1743 \fi%
1744 \fi%
1745 \fi%
1746 \fi%
1747 % \end{macrocode}
1748 % The result of $ab$ is in |\n@fl@wa|. Adjust the sign if necessary.
1749 % \begin{macrocode}
1750 \ifch@nge%
1751 \n@fl@wa = -\n@fl@wa%
1752 \fi%
1753 % \end{macrocode}
1754 % Return the result in the first argument variable.
1755 % \begin{macrocode}
1756 #1 = \n@fl@wa%
1757 }
1758 % \end{macrocode}
1759 % \end{macro}
1760 %
1761 %
1762 % The end of this package.
1763 % \begin{macrocode}
1764 %</mult>
1765 % \end{macrocode}
1766 %
1767 %
1768 % \bibliographystyle{alpha}
1769 %
1770 % \begin{thebibliography}{GMS94}
1771 %
1772 % \bibitem[Far90]{FARIN90}
1773 % Gerald Farin.
1774 % \newblock {\em Curves and Surfaces for Computer Aided Geometric Design --- A
1775 % Practical Guide}.
1776 % \newblock Academic Press, Inc., second edition, 1990.
1777 %
1778 % \bibitem[FP81]{FandP}
1779 % I.~D. Faux and M.~J. Pratt.
1780 % \newblock {\em Computational Geometry for Design and Manufacture}.
1781 % \newblock Ellis Horwood, 1981.
1782 %
1783 % \bibitem[GMS94]{GOOSSENS94}
1784 % Michel Goossens, Frank Mittelbach, and Alexander Samarin.
1785 % \newblock {\em The LaTeX Companion}.
1786 % \newblock Addison-Wesley Publishing Company, 1994.
1787 %
1788 % \bibitem[Lam94]{LAMPORT94}
1789 % Leslie Lamport.
1790 % \newblock {\em LaTeX: A Document Preparation System}.
1791 % \newblock Addison-Wesley Publishing Company, second edition, 1994.
1792 %
1793 % \bibitem[Mor85]{MORTENSON85}
1794 % Michael~E. Mortenson.
1795 % \newblock {\em Geometric Modeling}.
1796 % \newblock John Wiley \& Sons, Inc., 1985.
1797 %
1798 % \bibitem[Wil96]{PRW96i}
1799 % Peter~R. Wilson.
1800 % \newblock {\em {LaTeX for standards: The LaTeX package files user manual}}.
1801 % \newblock NIST Report NISTIR, June 1996.
1802 %
1803 % \end{thebibliography}
1804 %
1805 %
1806 % \Finale
1807 % \PrintIndex
1808 %
1809 \endinput
1810
1811 %% \CharacterTable
1812 %% {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
1813 %% 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
1814 %% Digits \0\1\2\3\4\5\6\7\8\9
1815 %% Exclamation \! Double quote \" Hash (number) \#
1816 %% Dollar \$ Percent \% Ampersand \&
1817 %% Acute accent \' Left paren \( Right paren \)
1818 %% Asterisk \* Plus \+ Comma \,
1819 %% Minus \- Point \. Solidus \/
1820 %% Colon \: Semicolon \; Less than \<
1821 %% Equals \= Greater than \> Question mark \?
1822 %% Commercial at \@ Left bracket \[ Backslash \\
1823 %% Right bracket \] Circumflex \^ Underscore \_
1824 %% Grave accent \` Left brace \{ Vertical bar \|
1825 %% Right brace \} Tilde \~}
1826
1827