Curves in L^{A}TEX Pictures

 A Manual for CURVES.STY and CURVESLS.STY

Version 1.33

I.L. Maclaine-cross^{∗} School of Mechanical and Manufacturing Engineering The University of New South Wales Sydney Australia 2052 28 June 1994

Contents

1 Introduction 1 2 Installation 3 3 Curves 5 4 Scaling 6 5 Symbols 7 6 Dashes 9 7 Errors 10 8 Curves Summary 12

8.1 Arguments of Commands . . . . . . . . . . . . . . . . . . . . . . 12 8.2 Lengths used by Commands . . . . . . . . . . . . . . . . . . . . . 12 8.3 Parameter Setting Commands . . . . . . . . . . . . . . . . . . . . 12 8.4 Curve Drawing Commands . . . . . . . . . . . . . . . . . . . . . 13

∗Current Internet address: S7301165@csdvax.csd.unsw.edu.au

1 Introduction

The picture environment in the L^{A}TEX^{1} macro package for TEX^{2} allows simple line drawing using characters. These characters include quadrant circular arcs, solid disks with diameters from 1 to 15pt^{3} and short lines with a limited range of slopes in two thicknesses. A \begin{picture} command defines an area where following commands place these characters to draw a L^{A}TEX picture.

L^{A}TEX pictures save disk space for source descriptions and computer time in producing documents compared with printer commands or bit mapped graphics. From initial pencil sketch on squared graph paper to final printout, they take half the time for manual pen drawings. The labor savings are higher for revisions and rewrites. Unfortunately standard L^{A}TEX cannot draw curves like a pen, compass and French curves can.

Superimposing characters closely can draw any curve. Disks give directional independence of line thickness and visual smoothness at large pitch. Smoothness increases with output resolution but is almost independent of disk pitch below a critical maximum. The following table suggests this maximum varies from 0.34pt for an 0.5pt thick curve to 3pt for a 15pt curve.

Thickness Magnified Comments  Line at 1/6 slope
[figure: 15pt; ×1; 1pt pitch disks]
[figure: 15pt; ×1; 3pt pitch disks]
[figure: ≈0.5pt; ×1; L^{A}TEX \line(6,1)]
≈0.5pt  ×1  0.34pt pitch disks  _{.}_{.}_{.}_{.}_{.}_{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}^{.}
≈0.5pt ×30

0.34pt pitch disks resolution ×30

[figure]

L^{A}TEX \line^{1} or line drawing \special commands require a tenth the TEX memory so are preferable to disks if available. A smooth curve may require thousands of disks or hundreds of lines. L^{A}TEX can load TEX^{4} macros from style files with a .sty extension. These macros can calculate the disk or line positions for a curve.

curves.sty provides macro commands for drawing curves using disks. Version 1.33 loads in about 2500 words^{5} of TEX’s main memory, which allows a small TEX. Complex or numerous floating drawings still require a big TEX with curves.sty. curvesls.sty uses fewer disks and line drawing \specials for increased speed and a tenth the TEX memory.

1Leslie Lamport, L^{A}TEX A Document Preparation System, Addison-Wesley, 1986.

2Donald E. Knuth, The TEXbook, Addison-Wesley, 1984.

3A printer’s point, abbreviated pt, is approximately 0.351460 mm.

4Donald E. Knuth, The TEXbook, Addison-Wesley, 1984, Chapter 20.

5A character or token takes a TEX word, 32 bits or larger.

The capabilities of these macros are:—

• A compatible replacement for \bezier^{6} from bezier.sty.

• Work with SliTEX for overhead transparencies, LaTeX2e^{7} and NFSS^{8}.

• Curves have the minimum number of disks or straight lines for visual smoothness.

• Curve thickness adjustable from 0.5 to 15pt (0.17 to 5mm).

• Curves have continuous slope.

• Curves for any number of points greater than one using \curve.

• Control of end slopes using \tagcurve.

• Closed curves with continuous slope using \closecurve.

• Large circles \bigcircle and circular arcs \arc.

• Independent scaling of curve abscissa and ordinates to fit graphs.

• Affine scaling for making arcs or circles elliptical.

• Symbols and dash patterns combined without interference.

• Any dash length or spacing.

• Three methods for fitting dash patterns to curves.

These macros approximate segments between coordinate points as parabolas. They draw disks or lines at high speed using a simple tail chasing macro. This macro’s arithmetic calculations are four fixed point additions per disk or line drawn. The TEX arithmetic in curves.sty for the initial differences between disk positions gives an error of less than 0.005% at the segment end. Even for a segment 1000pt long, this is less than 0.05pt and the resolution of most output devices.

For circles and circular arcs, a parabola approximates an arc segment no more than 23^{∘} giving a radius increase between segment ends less than 0.02%. The error in computing and multiplying by sine and cosine is usually less than 0.01% of the radius at the far end of an arc.

Brief descriptions, simple examples and a command summary follow. They presume familiarity with relevant chapters of the L^{A}TEX manual^{1}.

6See your Local Guide. Try the system command latex local to get a L^{A}TEXed Guide.

7Michel Goossens, Frank Mittelbach and Alexander Samarin, The L^{A}TEX Companion, Addison-Wesley, 1994.

8Frank Mittelbach and Rainer Schöpf, The New Font Selection Scheme—User Interface to Standard L^{A}TEX, TUGboat, vol.11, No.2, pp.297–305, June 1990.

BOX

Figure 1: This is a box.

2 Installation

Name either curves or curvesls in the \documentstyle command at the top of your main .tex file e.g.,

  \documentstyle[a4,11pt,curves]{article}

curves.sty or curvesls.sty should be in the default or a texinput directory.

Do not combine curves or curvesls with bezier in this command. They contain a compatible but faster replacement for \bezier. Drawings using \bezier will not change their appearance.

PICTEX^{9} is a large set of TEXnical drawing macros for plain TEX which L^{A}TEX pictures can also use. PICTEX requires a big TEX. I have not checked compatibility with curves or curvesls because I do not use PICTEX.

curvesls.sty uses line drawing \specials to reduce required memory and increase speed. As originally supplied it uses the \specials of emTEX by Eberhard Mattes for IBM PC compatibles. emTEX is available from computer networks and the TEX Users’ Group. To use other line drawing \specials substitute them at curvesls.sty’s start. Your system guru may do this for you. You can test curvesls.sty after substituting \specials, by replacing curves with curvesls in this file’s \documentstyle command. This file looks the same L^{A}TEXed with either curves or curvesls.

A drawing frequently uses auxiliary commands to size, place, label and caption it. The following commands draw the box in Figure 1 on page 4:

9Michael J. Wichura, The PICTEX Manual, Chicago, 1987, available from TEX Users’ Group.

  \begin{figure}
  \begin{center}
  \setlength{\unitlength}{1mm}
  \begin{picture}(100,50) \large\sf
  \linethickness{1mm}
  \put(20,5){\framebox(60,40){BOX}}
  \end{picture}
  \end{center}
  \caption{This is a box.}
  \label{box}
  \end{figure}

Lamport^{1} explains these commands. This example is for those unfamiliar with the L^{A}TEX picture environment. The following examples avoid the figure environment but it is often essential.

3 Curves

The curve drawing commands, \curve, \closecurve and \tagcurve, draw parabola segments between coordinate points in the argument. The segments’ tangents at these points are parallel to each other and to straight lines through the points either side. Segments at curve ends are from parabolas through the last three points. \closecurve adds a parabola between end points to close the curve. \tagcurve omits the first and last segments drawing curves with end tangents specified. The following table shows these features.

Example  Curve

      [figure: \curve(0,0, 50,100, 100,0)]

      [figure: \closecurve(0,0, 50,100, 100,0)]

       [figure: \tagcurve(100,0, 0,0, 50,100, 100,0, 0,0)]

Axial flow fans often use the RAF 6E aerofoil section. The section coordinates in the following macro come directly from aerodynamic tables^{10}. The \arc commands draw the leading and trailing radii and the two coordinate \curve the flat chord.

  \newcommand{\RAFsixE}{
    \scaleput(1.25,1.25){\arc(0,-1.25){-135}}
    \scaleput(0,0){\curve(0.366,2.133, 1.25,3.19, 2.5,4.42,
      5.0,6.10, 7.5,7.24, 10,8.09, 15,9.28, 20,9.90, 30,10.3,
      40,10.22, 50,9.80, 60,8.98, 70,7.70, 80,5.91, 90,3.79,
      95,2.58, 99.24,1.52)}
    \scaleput(99.24,0.76){\arc(0,-0.76){180}}
    \scaleput(0,0){\curve(1.25,0, 99.24,0)}
    }

In a picture environment like:

  \begin{picture}(100,20)
    \RAFsixE
  \end{picture}

this macro draws:

[figure]

The RAF 6E has a flat undersurface.

The drawing command \bigcircle works similarly to \circle except there is no \circle* equivalent. The following section scales it to an ellipse.

4 Scaling

The size of L^{A}TEX picture objects may be uniformly scaled by preceding them with:

  \setlength{\unitlength}{x\unitlength}

where x the desired scale factor is a decimal number.

The \scaleputs in \RAFsixE position the curves using the scale factors

\xscale, \xscaley, \yscale and \yscalex. The drawing commands use the

same scale factors. curve initially sets these scale factors to 1, 0, 1 and 0 respectively. \renewcommand may reset them to any decimal number. These factors can rotate pictures. The factors following rotate the RAF 6E through 12^{∘} clockwise about its (0,0) co-ordinate:

10R.A. Wallis, Axial Flow Fans, Academic Press, 1961, p.335

  \renewcommand{\xscale}{0.9781}
  \renewcommand{\xscaley}{0.2079}
  \renewcommand{\yscale}{0.9781}
  \renewcommand{\yscalex}{-0.2079}
  \put(0,20){\RAFsixE}

This draws:

[figure]

The RAF 6E has maximum lift at angles of attack over 12^{∘}.

Note that cos 12^{∘} ≈ 0.9781 and sin 12^{∘} ≈ 0.2079

Axonometric projection is another scaling application. Circles become ellipses and circular arcs become elliptical arcs. The commands drawing the ellipse and arc in the following washer are:

  \put(20,5){
    \renewcommand{\xscale}{1}
    \renewcommand{\xscaley}{-1}
    \renewcommand{\yscale}{0.6}
    \renewcommand{\yscalex}{0.6}
    \scaleput(10,10){\bigcircle{10}}
    \put(0,-2){
      \scaleput(10,10){\arc(5,0){121}}
      \scaleput(10,10){\arc(5,0){-31}}
      }
    }

(20,5) are the drawing coordinates of the upper vertex of the washer closest to the reader. The angles for the \arcs were found by trial and error.

[figure: ^{............................................................................................................................................................................................................................} ^{.................................................................................} . . . . . . . . . . . . . . . . . .]

Square washers are sometimes preferred for soft materials.

5 Symbols

curves can also place symbols. \curvesymbol must first define the symbol as anything a \put or \multiput may draw. A negative symbol count between drawing command and coordinates e.g., \tagcurve[-3](0,100,...) fixes the number of symbols per curve segment.

These commands draw flight times and successive positions in the following drawing:

  \newcounter{time}
    \curvesymbol{\thetime\,s\addtocounter{time}{1}}
    \put(5,4){\curve[-2](0,0, 9.8,19.6, 19.6,0)}
    \curvesymbol{\phantom{\circle*{1}}\circle*{1}}
    \put(5,2){\curve[-2](0,0, 9.8,19.6, 19.6,0)}

where \phantom is a plain TEX command from the TEXbook^{2}.

[figure: ^{0 s 1 s 2 s 3 s 4 s}; 0; 5; 10; 15; 20; 25; x (m); 0; 5; 10; 15; 20; 25; y (m)]

Successive positions of a sphere with initial position (5, 2) m, initial velocity (4.9, 9.8) m/s, and acceleration (0, −9.8) m/s^{2}. The flight time is recorded above each sphere position.

Fixed spacing of symbols at lengths other than the segment’s requires more commands. Empty \curvedashes, empty \curvesymbol and negative symbol count stops drawing so a drawing command will calculate \curvelength only. \curvesymbol then resets the symbol and \curvedashes sets the spacing to its pattern length. If there are no symbols at the ends, \overhang pulls symbols along the curve. The last command with no symbol count draws the symbols.

\arc and \bigcircle use sixteen segments for a circle so if eight symbols are required the fixed spacing technique is necessary. The following commands draw the pin numbers on a relay base:

    \newcounter{pin}
    \curvedashes{}
    \curvesymbol{}
    \put(60,60){\arc[-1](40,0){-360}}
    \setlength{\curvelength}{0.125\curvelength}
    \curvedashes[\curvelength]{1}
    \setlength{\overhang}{0.5\curvelength}
    \curvesymbol{\addtocounter{pin}{1}\thepin}
    \put(60,60){\arc(40,0){-360}}

[figure: ^{................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................}; ^{..........................................................................................................} . . . . . . . . . . . . . . . . .; ^{1 2 3 4 5 6  7 8}]

The pin numbering of plug-in relays is clockwise from the spigot key when viewed from below.

If symbols and dash pattern exist and \overhang is 0pt, curves draw the first position blank. For equal spacing they draw the last position blank if rounding error causes the last pattern to be slightly short. If \renewcommand changes \diskpitchstretch, rounding error changes and the final symbol may reappear. To avoid fiddling with \diskpitchstretch for closed curves with symbols equally spaced, use an \overhang which is a fraction of a pattern length as in the previous example.

6 Dashes

\curvedashes must first define a dash pattern with length greater than 0pt. Many symbol and pattern combinations are possible. The fixed number and fixed spacing methods of symbol drawing described in Section 5 work with three methods of drawing dashes which are:

1. if there is no symbol count and no symbol, a dash pattern with its length reduced by \csdiameter is drawn between symbols spaces of width close to \csdiameter to give an overall spacing equal to the pattern length specified by the \curvedashes command;

2. if there is a symbol count but no symbol, the dash patterns drawn have their length equal to that defined by \curvedashes with \csdiameter gaps at symbol positions;

3. if there is a symbol count and a symbol, the dash patterns drawn have their length adjusted slightly so an integral number of patterns fit between symbol positions.

Dash pattern commands for centrelines^{11} follow for the three techniques above in order:

  \linethickness{0.25mm}
  \curvedashes[1.2mm]{0,8,1,3,1,8}
  \settowidth{\csdiameter}{00}
  \put(0,20){\curve(0,0, 30,5, 60,0)}
  \put(0,10){\curve[1](0,0, 30,5, 60,0)}
  \curvesymbol{\thepin\addtocounter{pin}{1}}
  \setlength{\csdiameter}{2\csdiameter}
  \put(0,0){\curve[1](0,0, 30,5, 60,0)}

The following figure shows the resulting dash patterns. The upper line has first position blank because the \overhang is 0pt. It has patterns shrunk to scale between symbol spaces e.g., 1 to 2, and symbol space centres one pattern length apart. The middle line has patterns close to defined length but with the first dash part blanked by half of symbol space 3 and the second pattern broken in its first dash by symbol space 4. The lower line patterns are stretched between symbol spaces. Which pattern is appropriate depends on picture meaning and function.

............................................................................................................................................................................. .............................................................................................................................................................................. .........................................................................^{..................................................................... ..................................................................................................................................................... ....................... ...................................................................................................................................................................................................}^{........................................................................................... .................................. ........................................................................................... ........................................................................................... .................................. ...........................................................................................}^{1  2}^{3  4  5} 6  7  8

Centrelines and Symbols

11R.N. Roth and I.A. van Haeringen, The Australian Engineering Drawing Handbook, Part 1 Basic Principles and Techniques, The Institution of Engineers, Australia, Canberra,

7 Errors

Syntax errors like incorrect or missing punctuation while using curves will result in TEX or L^{A}TEX error messages. The TEXbook^{2} and L^{A}TEX manual^{1} explain the meaning and correction of these errors. The previous examples and Section 8 should make the correct syntax for curves commands clear.

curves will write a LaTeX error. message to the screen and log file if you supply an incorrect number of coordinates.

If four sequential points in a drawing command argument have the line through the first and third parallel to the line through the second and fourth:

• exactly, curves knows it cannot draw a parabola tangent to two parallel lines, issues a LaTeX Warning: and draws a straight line;

• closely, curves tries but may exceed TEX’s main memory capacity or draw off the page;

• or approximately, curves may draw an unexpected curve with no warning.

If four sequential points in a drawing command argument have the line through the first and second parallel to the line through the third and fourth:

• curves draws a parabola which may be nowhere near the curve.

If the four points were on a straight line, removing one or more points is a remedy. If they are not on a straight line curves thinks there is an inflexion point between the second and third points with a change in the sign of curvature.

Curvature changes sign on curves like y = sin x. Specifying inflection points as curve coordinates will prevent errors and specifying sufficient coordinates will then give satisfactory results. For discontinuous tangents splitting a curve into pieces is unavoidable. Splitting a curve into pieces with curvature the same sign can give satisfactory results with fewer coordinates. \tagcurve can prevent tangent discontinuities. If an inflexion point’s exact location is unknown, try the midpoint of the straight line through the ends of its segment.

Curves appear rougher than horizontal and vertical lines. Picture digitization causes this not inaccuracy in TEX, curves.sty or curvesls.sty. Setting \diskpitchstretch to a value less than one with \renewcommand may smooth an unusually rough curve.

Symbols and symbol spaces misaligned are usually due to rounding error. Adjusting \diskpitchstretch below one can reduce rounding error and increase alignment accuracy. This should be limited to the misaligned curve with { }^{1}.

8 Curves Summary

The commands following are for the picture environment in the L^{A}TEX manual^{1}.

8.1 Arguments of Commands

<blank length> decimal number of <unit len> blank. Not negative.

<character or symbol> is anything which a \put or \multiput may draw.

<coordinates> are decimal numbers giving alternate x and y coordinates of the curve as multiples of \unitlength, comma separated.

<[,dash...]> optional continuation of alternating dash and blank numbers of unit lengths, comma separated. Not negative. Allows decimal points.

<diameter> is a decimal number giving the diameter in \unitlengths.

<symbol count> is the number of symbols or patterns to be drawn, default 0.

<unit len> unit length dimension e.g., 2.5mm, 10pt, used in measuring blanks and dashes. Not negative. Default value is \unitlength.

8.2 Lengths used by Commands

\csdiameter is the size of the space left for a symbol and can be increased or

   set with \settowidth{\csdiameter}{<character or symbol>}.

\curvelength is the total length of the curve calculated before drawing by using Simpson’s rule once between each pair of coordinate points.

\overhang length of as drawn dash pattern overlapping start of patterns.

8.3 Parameter Setting Commands

\curvesymbol{<character or symbol>} sets symbol and \csdiameter.
\curvedashes[<unit len>]{<blank length><[,dash...]>} A drawing com-

mand before a \curvedashes or after one with an empty or zero length pattern will draw:

if <symbol count> is zero or missing, a continuous curve;

else if <symbol count> is positive, <symbol count>-1 squares of line thickness size between and additional squares at coordinates or bezier end points;

else if no <character or symbol> exists, nothing;

else, -<symbol count>-1 characters or symbols between coordinates and additional ones at coordinates or bezier end points.

After a \curvedashes command defining a pattern whose length exceeds zero, commands draw: if <symbol count> is zero or missing then at a spacing equal to the specified

pattern length,

if no <character or symbol> exists, a dash pattern reduced in length

by \csdiameter to fit between symbol spaces of \csdiameter, else if \overhang is not 0pt, a <character or symbol> at all positions, else a <character or symbol> with the first position blank;

else, \csdiameter wide symbol spaces, one at and |<symbol count>|-1 between coordinate points with dash pattern lengths, if no <character or symbol> exists, exact but broken by the spaces, else, adjusted to give a whole number of patterns between spaces.

\diskpitchstretch is initially 1 but \renewcommand can change it to a higher value like 5 to save memory in drafts of complex documents or a lower local value like 0.5 to smooth curve digitization.

\linethickness{<len>} sets line or dash thicknesses to <len> from 0.5pt up to 15pt (0.17mm to 5mm). \thicklines and \thinlines also set thickness.

\xscale, \xscaley, \yscale and \yscalex are scale factors initially set to 1, 0, 1 and 0 respectively which \renewcommand or \def can reset.

8.4 Curve Drawing Commands

Curves drawn consist of parabolic arcs between coordinate points with tangents at each point parallel to the straight line through adjacent points.

\arc[<symbol count>](X1,Y1){<angle>} draws a circular arc centred on cur-

rent position, starting from (X1,Y1) and proceeding counterclockwise for <angle> degrees.

\bezier{<symbol count>}(X1,Y1)(X2,Y2)(X3,Y3) draws a curve through the

end points (X1,Y1) and (X3,Y3) tangent to the straight lines joining each of them to (X2,Y2). Extended faster replacement for bezier.sty version.

\bigcircle[<symbol count>]{<diameter>} draws a circle of diameter equal
to <diameter> times \unitlength.
\closecurve[<symbol count>](<coordinates>) draws a closed curve with

continuous tangents at all points. At least 6 coordinates required.

\curve[<symbol count>](<coordinates>) draws a curve through the spe-

cified <coordinates>. For 4 coordinates this is a straight line.

\scaleput(X1,Y1){<picture object>} places a picture object in a position

scaled by \xscale, \xscaley, \yscale and \yscalex for axonometric projection or rotations.

\tagcurve[<symbol count>](<coordinates>) draws a curve without its first

and last segments but if only 6 coordinates draws the last segment only.