| 1 |
\documentclass[a4paper,11pt]{article} |
| 2 |
\usepackage[color]{lapdf} |
| 3 |
\usepackage{shortvrb} |
| 4 |
\textheight24.62cm |
| 5 |
\textwidth15.92cm |
| 6 |
\oddsidemargin0cm |
| 7 |
\topmargin-1cm |
| 8 |
\parindent0cm |
| 9 |
\parskip0cm |
| 10 |
\unitlength1cm |
| 11 |
\pagestyle{headings} |
| 12 |
|
| 13 |
\MakeShortVerb{\|} |
| 14 |
|
| 15 |
\newdimen\a |
| 16 |
\newdimen\x |
| 17 |
\newdimen\y |
| 18 |
\Defnum(\n,0) |
| 19 |
|
| 20 |
\title{\Huge{\bf\Lapdf} \\ \vspace{0.5cm} |
| 21 |
\Large Drawing in \TeX{} with PDF commands \\ \vspace{0.5cm} |
| 22 |
\normalsize Integral/Rational Bezier Curves \\ |
| 23 |
Many Useful Drawing Primitives \\ |
| 24 |
A Rich Set Of Math Functions \\ |
| 25 |
Function, Parametric \& Polar Plots and Grids \\ \vspace{0.8cm} |
| 26 |
\begin{lapdf}(6,6.3)(-3,-3.3) |
| 27 |
\Whilenum{\n<360}{% |
| 28 |
\Nextcol(0,23) \Rad(\n,\a) |
| 29 |
\Cos(\Np\a,\x) \Add(\x,\x) |
| 30 |
\Sin(\Np\a,\y) \Add(\y,\y) |
| 31 |
\Circle(64)(\Np\x,\Np\y,1.5) \Stroke |
| 32 |
\Add(\n,15)} |
| 33 |
\end{lapdf}} |
| 34 |
\author{Detlef Reimers, [email protected]} |
| 35 |
\date{\today} |
| 36 |
|
| 37 |
% --------------------------------------------------------------------------- |
| 38 |
\begin{document} |
| 39 |
\maketitle |
| 40 |
|
| 41 |
\begin{abstract} |
| 42 |
This package started as a project for drawing arbitrary bezier curves. |
| 43 |
It implements the integral and rational bezier curves of degree one up |
| 44 |
to seven. Using quadratic rational bezier curves makes it possible to |
| 45 |
exactly draw arbitrary conics. Also implemented are most elementary math |
| 46 |
functions as power series and two loop commands for programming constructs. |
| 47 |
|
| 48 |
This basic functionality gives the ability to draw many geometric |
| 49 |
shapes like arbitray circles, rotated ellipses, rectangles and polygons. |
| 50 |
The package also implements function, parametric and polar plotting |
| 51 |
routines together with the possibility to draw special grids. |
| 52 |
|
| 53 |
You are invited to extend this package to your own needs. This is not |
| 54 |
very complicated, because you can use all of the math capabilities in |
| 55 |
your \TeX{} documents directly and so, you can program your drawings |
| 56 |
(see example above). The package also defines a rainbow color palette |
| 57 |
and you can step through the colors. |
| 58 |
|
| 59 |
This package needs the standard \LaTeX{} |calc| package for multiplication |
| 60 |
and division of dimensions. No other packages are needed. Most of the drawing |
| 61 |
primitives rely on the graphic capabilities of PDF, which is mostly like |
| 62 |
PostScript without programming. With the help of the \pdfTeX{} engine this |
| 63 |
programming possibility is back at the users hand. Now you can write your |
| 64 |
PDF-graphics directly in your \pdfTeX{} source file. |
| 65 |
|
| 66 |
The author hopes that \Lapdf{} may be useful and helps, to produce beautiful |
| 67 |
and sophisticated drawings. I will be thankful for contructive criticism and |
| 68 |
help from the users to further improve this package. |
| 69 |
\end{abstract} |
| 70 |
|
| 71 |
\tableofcontents |
| 72 |
\parskip0.2cm |
| 73 |
|
| 74 |
\section{Introduction} |
| 75 |
|
| 76 |
\subsection{What is it for?} |
| 77 |
|
| 78 |
\Lapdf{} is intended as a practical extension to the standard \LaTeX{} |
| 79 |
|picture| environment. It gives the user the ability to quickly |
| 80 |
draw many useful geometric shapes like arbitrary lines, circles, |
| 81 |
rotated ellipses, arcs, vectors, rectangles, triangles and equilateral |
| 82 |
polygons. |
| 83 |
|
| 84 |
You can also draw bezier curves of degree one to seven. You may |
| 85 |
choose the integral bezier form or the more general rational form. |
| 86 |
The letter one enables you to exactly draw all kind of conic curves |
| 87 |
like parabolas, hyperbolas, ellipses and circles. There is no need to |
| 88 |
approximate them with quadratic or cubic bezier curves. |
| 89 |
|
| 90 |
This package also implements a rich set of basic math functions like: |Sin|, |
| 91 |
|Cos|, |Tan|, |Asin|, |Acos|, |Atan|, |Sinh|, |Cosh|, |Tanh|, |Asinh|, |Acosh|, |
| 92 |
|Atanh|, |Exp|, |Pow|, |Ln|, |Log|, |Sqrt|, |Hypot|, |Len|. They can be used in |
| 93 |
your documents to program special plot functions or in loop constructs in |
| 94 |
connection with drawing functions. Al these functions are based on the ability |
| 95 |
to do floating point multiplication and division with dimension values and |
| 96 |
with dimension registers. These calculations are provided by the help of the |
| 97 |
|calc| package, which belongs to the standard \LaTeX{} tools. |
| 98 |
|
| 99 |
\subsection{How does it work?} |
| 100 |
|
| 101 |
\TeX{} and also \LaTeX{} were made to typeset arbirary complicated and |
| 102 |
structured text documents, with the special ability to integrate math formulas |
| 103 |
into the document. |Donald Knuth|, the inventor of this marvellous |
| 104 |
typesetting machine, only provided a small peephole to implement |
| 105 |
inline graphics in \TeX{} documents. The basic shape of these drawing |
| 106 |
capabilities is the |dot|. If you want to draw a line with pure \TeX{} |
| 107 |
commands, you have to draw lots of evenly spaced dots. This uses much of |
| 108 |
\TeX{} memory and it takes a lot of time to place them. |Leslie Lamport|, |
| 109 |
the inventor of the \LaTeX{} macro package, used this technique together with |
| 110 |
some specially designed graphic fonts for his implementation of the |picture| |
| 111 |
environment, which allows to produce simple to moderate comlicated graphics |
| 112 |
from inside the \LaTeX{} document. This approach is nice for simple |
| 113 |
drawings, but you are limited to only a small set of line or vector slopes, |
| 114 |
you only can draw circles of limited radii and so on. This is the price for |
| 115 |
general portability, because the line and circle fonts are limited to special |
| 116 |
drawing primitives. |
| 117 |
|
| 118 |
Other new drawing packages avoid these limitations by using the |Postscript| |
| 119 |
programming language for calculations and drawing. With the help of |DVIPS| |
| 120 |
you can produce arbitrary sophisticated drawings to be integrated into you |
| 121 |
\LaTeX{} file. But you are limited to output devices which can handle postscript. |
| 122 |
|
| 123 |
So, there were other approaches to implement more general drawing capabilities. |
| 124 |
The first one uses so called |Tpic| specials. |Tpic| is a simple graphic |
| 125 |
language from Unix systems, which was used together with |Groff| to produce |
| 126 |
documents with inline graphics. Another approach was done by |
| 127 |
|Eberhard Matthes| in his |EmTeX| distribution. He implemented a small but |
| 128 |
powerful set of graphic primitives into his DVI drivers, which could set |
| 129 |
points, draw arbitrary lines and set the linewidth. |
| 130 |
|
| 131 |
\Lapdf{} evolved out of my former |Ladraw| style, which had very similar |
| 132 |
capabilities, but no way to fill or clip graphics. \Lapdf{} uses the |PDF| |
| 133 |
capabilities directly, so it does not rely on other packages or tools with the |
| 134 |
exception of the |calc| style to perform floating point arithmetic in \TeX{}. |
| 135 |
|
| 136 |
The ability to draw arbitrary lines frees us from the use of single dots as |
| 137 |
basic drawing primitve. We don't need to calculate the number of dots to draw |
| 138 |
a smooth bezier curve, because we use straight line segments to draw them. This |
| 139 |
way, we never have white spaces in curve shapes, but we have to take care to use |
| 140 |
enough line segments to produce a smooth curve. |
| 141 |
|
| 142 |
The Bezier curve drawing is invoked by two general calling routines |Curve| |
| 143 |
for integral curves and |Rcurve| for rational curves. As an example, the |
| 144 |
command: |
| 145 |
\begin{verbatim} |
| 146 |
\Curve(64)(0,0)(3,6)(6,-7)(9,0) |
| 147 |
\end{verbatim} |
| 148 |
will draw an integral cubic bezier curve (4 points), consisting of 64 line segments |
| 149 |
and the command: |
| 150 |
\begin{verbatim} |
| 151 |
\Rcurve(96)(0,0,1)(5,8,2)(10,0,1) |
| 152 |
\end{verbatim} |
| 153 |
will draw a rational quadratic bezier curve (3 points) with the weights (will be |
| 154 |
explained later) $w_0=1$, $w_1=2$ and $w_2=1$, consisting of 96 line segments. |
| 155 |
|
| 156 |
This package uses round brackets around command parameters with the only |
| 157 |
exception of the |Text| command, where the last argument (the actual text) |
| 158 |
cannot be bracketed with round brackets. This convention makes some functions |
| 159 |
a little more static, but you don't have to remember complicated calling |
| 160 |
syntaxes. My first decision was to make this style very easy to use. All |
| 161 |
\Lapdf{} commands begin with a capital letter to distinguish them from other, |
| 162 |
equally spelled \TeX{} commands. I hope that the names of the graphic macros |
| 163 |
helps guessing what they do. The standiest one seems to be |concat|, which |
| 164 |
is a native |PDF| matrix calculation commands, the others tell the user |
| 165 |
what they mean. |
| 166 |
|
| 167 |
\subsection{How to use it?} |
| 168 |
|
| 169 |
Here are some simple examples that will show you the basic usage of the |
| 170 |
\Lapdf{} package. First, we want to draw an ellipse at (1,2), rotated by an |
| 171 |
angle of $30\deg$ with diameters $a=3cm$ and $b=2cm$ with red color and linewidth |
| 172 |
of $0.3pt$. We also want to draw two axes with tick marks. The center point will |
| 173 |
be marked and also the two main axes of the ellipse will be drawn dashed. |
| 174 |
\vspace{0.1cm} |
| 175 |
|
| 176 |
\begin{minipage}[c][7cm]{8cm} |
| 177 |
\small{ |
| 178 |
\begin{verbatim} |
| 179 |
\documentclass{article} |
| 180 |
\usepackage[color]{Lapdf} |
| 181 |
\unitlength1cm |
| 182 |
\begin{document} |
| 183 |
\begin{lapdf}(6,6)(-2,-1) |
| 184 |
\Lingrid(10)(1,3)(-2,4)(-1,5) |
| 185 |
\Red |
| 186 |
\Ellipse(50)(1,2)(3,2,30) \Stroke |
| 187 |
\Blue |
| 188 |
\Dash(3) |
| 189 |
\Line(-2,0.5)(4,3.5) \Stroke |
| 190 |
\Line(-0.5,5)(2.5,-1) \Stroke |
| 191 |
\Dash(0) |
| 192 |
\Point(1)(1,2) |
| 193 |
\Text(1.1,2.2,cb){C} |
| 194 |
\end{lapdf} |
| 195 |
\end{document} |
| 196 |
\end{verbatim} |
| 197 |
} |
| 198 |
\end{minipage} |
| 199 |
\begin{minipage}[c][7cm]{7cm} |
| 200 |
\begin{lapdf}(6,6.3)(-2,-1) |
| 201 |
\Lingrid(10)(1,3)(-2,4)(-1,5) |
| 202 |
\Red |
| 203 |
\Ellipse(50)(1,2)(3,2,30) \Stroke |
| 204 |
\Blue |
| 205 |
\Dash(3) |
| 206 |
\Line(-2,0.5)(4,3.5) \Stroke |
| 207 |
\Line(-0.5,5)(2.5,-1) \Stroke |
| 208 |
\Dash(0) |
| 209 |
\Point(1)(1,2) |
| 210 |
\Text(1.1,2.2,cb){C} |
| 211 |
\end{lapdf} |
| 212 |
\end{minipage} |
| 213 |
\vspace{0.1cm} |
| 214 |
|
| 215 |
From this example you can see how the package is invoked in the preamble |
| 216 |
of the document. If you only want to draw in black and white, you would |
| 217 |
use the option |black| instead of |color| or simply no option. This means that |
| 218 |
all color commands will be silently ignored. The ellipse is drawn with 50 |
| 219 |
line segments in it's first part and with $2\cdot 50=100$ segments in |
| 220 |
the second part. |Line| draws a line (solid or dashed) between two points. The |
| 221 |
|Point| command draws a circle filled with a shade of gray (black..white). |
| 222 |
|Puttext| puts the bracketed text at a specific point with optional position |
| 223 |
parameters (here centered and bottom). |
| 224 |
|
| 225 |
Our next example shows how to plot the function $f(x)=2\sin x$ from $x=-4$ |
| 226 |
to $x=4$. We also want to write the term into the picture. We have to |
| 227 |
supply the function definition in |Fx|. |
| 228 |
\vspace{0.1cm} |
| 229 |
|
| 230 |
\begin{minipage}[c][5.7cm]{7.3cm} |
| 231 |
\small{ |
| 232 |
\begin{verbatim} |
| 233 |
\documentclass{article} |
| 234 |
\usepackage[color]{Lapdf} |
| 235 |
\unitlength1cm |
| 236 |
\begin{document} |
| 237 |
\begin{lapdf}(8,4)(-7,-2) |
| 238 |
\Lingrid(10)(1,3)(-4,4)(-2,2) |
| 239 |
\Red |
| 240 |
\def\Fx(#1,#2){\Sin(#1,#2) #2=2#2} |
| 241 |
\Fplot(50)(-4,4) \Stroke |
| 242 |
\Text(-2,1.2,cb){$y=2\sin x$} |
| 243 |
\end{lapdf} |
| 244 |
\end{document} |
| 245 |
\end{verbatim} |
| 246 |
} |
| 247 |
\end{minipage} |
| 248 |
\begin{minipage}[c][5.7cm]{8.5cm} |
| 249 |
\begin{lapdf}(8,4)(-4,-2) |
| 250 |
\Lingrid(10)(1,3)(-4,4)(-2,2) |
| 251 |
\Red |
| 252 |
\def\Fx(#1,#2){\Sin(#1,#2) #2=2#2} |
| 253 |
\Fplot(50)(-4,4) \Stroke |
| 254 |
\Text(-2,1.2,cb){$y=2\sin x$} |
| 255 |
\end{lapdf} |
| 256 |
\end{minipage} |
| 257 |
\vspace{0.1cm} |
| 258 |
|
| 259 |
The function definition has two parameters. The first is the |
| 260 |
$x$-value and the second is the register for the function value |
| 261 |
$f(x)$. The |Sin| function also takes two parameters, the |
| 262 |
same way as |Fx| does. So, $\sin x$ is in register |\#2|. |
| 263 |
At last we have to multiply this value with 2 to get $2\sin x$. |
| 264 |
The function is plotted with 50 line segments. The last introductory |
| 265 |
example will draw several bezier curves (integral and rational) and |
| 266 |
axes without a grid. All curves are drawn in different colors. |
| 267 |
\vspace{0.1cm} |
| 268 |
|
| 269 |
\begin{minipage}[c][7.8cm]{9cm} |
| 270 |
\small{ |
| 271 |
\begin{verbatim} |
| 272 |
\documentclass{article} |
| 273 |
\usepackage[color]{Lapdf} |
| 274 |
\unitlength1cm |
| 275 |
\begin{document} |
| 276 |
\begin{lapdf}(6,6)(0,0) |
| 277 |
\Lingrid(10)(0,2)(0,6)(0,6) |
| 278 |
\Stepcol(0,23,4) |
| 279 |
\Curve(32)(0,0)(6,6) \Stroke |
| 280 |
\Stepcol(0,23,4) |
| 281 |
\Curve(64)(0,0)(3,6)(6,0) \Stroke |
| 282 |
\Stepcol(0,23,4) |
| 283 |
\Curve(64)(0,3)(2,6)(4,0)(6,3) \Stroke |
| 284 |
\Stepcol(0,23,4) |
| 285 |
\Rcurve(64)(0,0,1)(3,6,5)(6,0,1) \Stroke |
| 286 |
\Stepcol(0,23,4) |
| 287 |
\Rcurve(64)(0,3,1)(2,6,10)(4,0,10)(6,3,1) |
| 288 |
\Stroke |
| 289 |
\end{lapdf} |
| 290 |
\end{document} |
| 291 |
\end{verbatim} |
| 292 |
} |
| 293 |
\end{minipage} |
| 294 |
\begin{minipage}[c][7.8cm]{6.5cm} |
| 295 |
\begin{lapdf}(6,6)(0,0) |
| 296 |
\Lingrid(10)(0,2)(0,6)(0,6) |
| 297 |
\Stepcol(0,23,4) |
| 298 |
\Curve(64)(0,0)(6,6) \Stroke |
| 299 |
\Stepcol(0,23,4) |
| 300 |
\Curve(64)(0,0)(3,6)(6,0) \Stroke |
| 301 |
\Stepcol(0,23,4) |
| 302 |
\Curve(64)(0,3)(2,6)(4,0)(6,3) \Stroke |
| 303 |
\Stepcol(0,23,4) |
| 304 |
\Rcurve(64)(0,0,1)(3,6,5)(6,0,1) \Stroke |
| 305 |
\Stepcol(0,23,4) |
| 306 |
\Rcurve(64)(0,3,1)(2,6,10)(4,0,10)(6,3,1) |
| 307 |
\Stroke |
| 308 |
\end{lapdf} |
| 309 |
\end{minipage} |
| 310 |
\vspace{0.1cm} |
| 311 |
|
| 312 |
The grid is disabled with the first 0 value in |Lingrid|. The next |
| 313 |
value 2 only shows ticks mark without text. The first three curves are |
| 314 |
integral bezier curves with degree 1, 2 and 3. The next two are |
| 315 |
rational bezier curves with degree 2 and 3. All curves are drawn with |
| 316 |
64 line segments. The rational form needs a so called |weight| parameter. |
| 317 |
Usually, the first and the last values are set to 1, the other may have |
| 318 |
arbitrary values. If $w>1$, the curve is pulled into the direction of |
| 319 |
the bezier point, otherwise it is pushed away from this point. This allows |
| 320 |
much more control over the shape of the bezier curve, compared to the |
| 321 |
integral form. The |Stepcol| command cycles between color 0 and color |
| 322 |
23 in step of length 4. Please look at the file |colors.tex| to see a |
| 323 |
whole color circle with all possible 96 colors. |
| 324 |
|
| 325 |
\end{document} |