Debian Codegraph @

texmf-dist/doc/latex/xpicture/xpicture-doc.tex

raw
1 \documentclass{article}
2
3 \usepackage[a4paper,margin=2cm]{geometry}
4 \usepackage[T1]{fontenc}
5
6 \usepackage{xpicture}
7
8 \usepackage{ifthen}
9 \usepackage{array}
10 \usepackage{fancyvrb}
11 \usepackage[colorlinks]{hyperref}
12
13 \usepackage{amsmath}
14 \usepackage{paralist}
15 \usepackage{graphicx}
16 \usepackage{makeidx}
17 \makeindex
18 \renewcommand{\today}{2012/12/17}
19
20 \newcommand{\TIT}{\textit}
21 \newcommand{\TTT}{\texttt}
22 \newcommand{\TTTit}[1]{\TTT{\TIT{#1}}}
23 \newcommand{\cs}[1]{\mbox{\textnormal{\TTT{\textbackslash #1}}}}
24 \newcommand{\environ}[1]{\textnormal{\TTT{#1}}}
25 \newcommand{\package}[1]{\textnormal{\TTT{#1}}}
26 \newcommand{\ttindex}[1]{\index{#1@\texttt{#1}}}
27 \newcommand{\ttslashindex}[1]{\index{#1@\texttt{\textbackslash #1}}}
28 \newcommand{\csdef}[1]{\cs{#1}\ttslashindex{#1}}
29 \newcommand{\packagedef}[1]{%
30 \package{#1}\index{#1@\texttt{#1} (package)}}
31 \newcommand{\environdef}[1]{%
32 \package{#1}\index{#1@\texttt{#1} (environment)}}
33 \newcommand{\optiondef}[1]{%
34 \textnormal{\TTT{#1}}\index{#1@\texttt{#1} (package option)}}
35 \newcounter{exem}\stepcounter{exem}
36 \newenvironment{exemple}{%
37 \VerbatimEnvironment\begin{VerbatimOut}{./xpicture\theexem.tex}}{%
38 \end{VerbatimOut}
39 \par\medskip\noindent
40 \marginpar{\fbox{Ex. \theexem}}\begin{minipage}{\linewidth}
41 \begin{minipage}{0.45\linewidth}
42 \setlength{\parindent}{2ex}
43 \catcode`\%=14
44 \input{./xpicture\theexem}
45 \end{minipage}\hfill
46 \begin{minipage}{0.45\linewidth}
47 \small
48 \VerbatimInput{./xpicture\theexem.tex}
49 \end{minipage}
50 \end{minipage}
51 \stepcounter{exem}\par\bigskip\noindent}
52 \newenvironment{Exemple}{%
53 \VerbatimEnvironment\begin{VerbatimOut}{./xpicture\theexem.tex}}{%
54 \end{VerbatimOut}
55 \par\noindent
56 \marginpar{\fbox{Ex. \theexem}}\fbox{\begin{minipage}{\linewidth}
57 \begin{minipage}{\linewidth}
58 \setlength{\parindent}{2ex}
59 \bigskip\par
60 \catcode`\%=14
61 \input{./xpicture\theexem}
62 \end{minipage}\medskip\par
63 \hspace*{0.125\linewidth}\rule{0.75\linewidth}{0.4pt}\par\medskip
64 \small
65 \VerbatimInput{./xpicture\theexem.tex}
66 \end{minipage}}\stepcounter{exem}\par\bigskip\noindent}
67
68 \begin{document}
69 \begin{titlepage}
70 \centering
71 \bfseries\Large Robert Fuster
72
73 \rule{\textwidth}{1pt}
74
75 The \textsf{xpicture} package
76
77 (\Verb+http://www.upv.es/~rfuster/xpicture+)
78
79 Several extensions of the \textsf{picture} standard environment
80
81 User Manual
82 \vspace{\stretch{1}}
83 \begin{Exemple}
84 \setlength{\unitlength}{1cm}
85 \footnotesize
86 \DIVIDE{1}{12}{\invXII}
87 \MULTIPLY{12}{\numberTWOPI}{\phione}
88 \MULTIPLY{12}{64}{\divisions}
89
90 \COMPOSITIONfunction{\EXPfunction}{\COSfunction}{\Afunction}
91 \SCALEVARIABLEfunction{4}{\COSfunction}{\Bfunction}
92 \SCALEVARIABLEfunction{\invXII}{\SINfunction}{\cfunction}
93 \POWERfunction{\cfunction}{5}{\Cfunction}
94 \LINEARCOMBINATIONfunction{1}{\Afunction}{-2}{\Bfunction}{\ABfunction}
95 \SUMfunction{\ABfunction}{\Cfunction}{\ABCfunction}
96 \PRODUCTfunction{\SINfunction}{\ABCfunction}{\Xfunction}
97 % x=(sin t)(exp(cos t)-2 cos 4t + (sin(t/12))^5)
98 \PRODUCTfunction{\COSfunction}{\ABCfunction}{\Yfunction}
99 % y=(cos t)(exp(cos t)-2 cos 4t + (sin(t/12))^5)
100 \PARAMETRICfunction{\Xfunction}{\Yfunction}{\butterfly}
101 \centering
102 \begin{Picture}(-4,-3)(4,4)
103 \PlotParametricFunction[\divisions]\butterfly{0}{\phione}
104 \end{Picture}
105 \begin{gather*}
106 x=\sin t\left(\mathrm e^{\cos t}-2\cos 4t
107 +\sin^5\left(\frac t{12}\right)\right) \\
108 y=\cos t\left(\mathrm e^{\cos t}-2\cos 4t
109 +\sin^5\left(\frac t{12}\right)\right)
110 \end{gather*}
111 \end{Exemple}
112 \footnotesize\today
113 \end{titlepage}
114 \stepcounter{page}
115
116 \tableofcontents
117 \newpage
118
119 The \package{xpicture} package extends the
120 \environ{picture} standard environment
121 and packages \package{pict2e} and \package{curve2e},
122 adding the ability to work with arbitrary
123 reference systems and with Cartesian or polar coordinates.
124 In addition to other utilities,
125 the greater interest of \package{xpicture}
126 lies in its capacity to draw function graphs,
127 conic sections and arcs, and parametrically defined curves.
128
129 This is the user manual of \package{xpicture}.
130 Technical documentation and reference manual are contained
131 in file \texttt{xpicture.pdf}, distributed together with the package.
132
133 \section{Introduction. New graphical instructions}
134 The \package{xpicture} package introduces several new graphical
135 instructions, and some enriched versions of standard
136 instructions used inside the \environ{picture} environment.
137 All these new instructions can be classified as follows:
138 \begin{itemize}
139 \item Reference systems and coordinates:
140 \begin{itemize}
141 \item Declaration and use of different reference systems,
142 with Cartesian or polar coordinates.
143 \item Instructions to show Cartesian or polar reference systems.
144 \end{itemize}
145 \item An alternative to the \environ{picture} environment,
146 compatible with the new reference systems.
147 \item Alternative instructions or extensions of the standard
148 \environ{picture} commands and those defined by the packages
149 \packagedef{pict2e} and \packagedef{curve2e}:
150 \begin{itemize}
151 \item Enriched versions of marks \cs{put} and \cs{multiput},
152 providing an adequate control of the precise position
153 in which objects are composed
154 (this functionality is especially useful in the composition
155 of not strictly graphical objects, such as formulas or labels).
156 \item Instructions for drawing straight segments, vectors
157 (in any direction and using any reference system), polygonal lines,
158 and regular and arbitrary polygons.
159 \end{itemize}
160 \item Regular curves:
161 \begin{itemize}
162 \item Instructions for drawing conic sections (circles, ellipses,
163 hyperbolas and parabolas) and arcs of these curves.
164 \item Instructions to graph functions and parametrically defined curves
165 (this is the most interesting feature of this package).
166 \end{itemize}
167 \end{itemize}
168
169 The only requeriments for \package{xpicture} are packages
170 \packagedef{calculator}, \packagedef{calculus},
171 \packagedef{curve2e} and \packagedef{xcolor}.
172 Therefore, it works with any \TeX{}
173 extension compatible with these packages. You can compile a document
174 including \package{xpicture} pictures directly with
175 \TTT{pdflatex},\ttindex{pdflatex}
176 \TTT{lualatex},\ttindex{lualatex}
177 \TTT{xelatex}\ttindex{xelatex}
178 or indirectly, via \TTT{latex/dvips}\ttindex{latex},\ttindex{dvips}
179 \TTT{latex/dvips/dvipdfm},\ttindex{dvipdfm} \ldots
180 Pure \TTT{dvi} files are not supported, but some \TTT{dvi} previewers
181 may show partially \package{xpicture} draws included in \TTT{dvi} files.
182
183 \section{A preliminary observation.
184 Compatibility with text composition in color}
185 The \package{xpicture} package automatically loads the
186 \packagedef{xcolor} package.
187 So, we can compose our
188 pictures (and the whole document) in various colors. However,
189 when used in the body of the \textsf{picture} environment,
190 marks \cs{color} and \cs{colortext}
191 often introduce spurious spaces.
192 For this reason, the \package{xpicture} package introduces the new command
193 \csdef{pictcolor}.
194 \begin{Verbatim}[commandchars=\|\[\]]
195 \pictcolor{|TIT[color]}
196 \end{Verbatim}
197 This mark behaves like the \cs{color} command, but does not produces these
198 inappropriate spaces.
199 To change colors inside a picture, instead of \cs{color} or \cs{colortext},
200 use always the \cs{pictcolor} declaration.
201
202 \section{Coordinate systems and the \environ{Picture} environment}
203 \subsection{Coordinates}
204 The standard \environ{picture} environment establishes
205 a rectangular coordinate system, so that all
206 graphic objects are placed in the picture using the canonical
207 coordinates of the plane. From now on, we will call
208 this reference system \emph{the standard reference system}.
209 Loading the \package{xpicture} package, we can use any other affine
210 reference system and combine it with the use of polar coordinates.
211
212 \subsubsection{Reference systems}
213 The \package{xpicture} package allows us to use other reference systems.
214 For the purpose we are interested, a reference system consists
215 of an origin of coordinates and a pair of linearly independent vectors.
216 Typing\ttslashindex{referencesystem}
217 \begin{Verbatim}[commandchars=\|\[\]]
218 \referencesystem(|TIT[x0],|TIT[y0])(|TIT[x1],|TIT[y1])(|TIT[x2],|TIT[y2])
219 \end{Verbatim}
220 we declare the new reference system with origin at point
221 $(\TTT{\TIT{x0}},\TTT{\TIT{y0})} $ and coordinate vectors
222 $(\TTT{\TIT{x1}},\TTT{\TIT{y1}})$ and
223 $(\TTT{\TIT{x2}},\TTT{\TIT{y2}})$.
224 If the coordinates of the point $P$ with respect to this reference system
225 are $(\bar{\TTT{\TIT{x}}},\bar{\TTT{\TIT{y}}})$, then the
226 coordinates of $ P $ with respect to the standard system,
227 $(\TTT{\TIT{x}},\TTT{\TIT{y}})$, are calculated with the formula
228 \newenvironment{qmatrix}{\left[\begin{matrix}}{\end{matrix}\right]}
229 \[
230 \begin{qmatrix}
231 \TTT{\TIT{x}} \\ \TTT{\TIT{y}}
232 \end{qmatrix}=\begin{qmatrix}
233 \TTT{\TIT{x0}} \\ \TTT{\TIT{y0}}
234 \end{qmatrix} +
235 \begin{qmatrix}
236 \TTT{\TIT{x1}} & \TTT{\TIT{x2}} \\
237 \TTT{\TIT{y1}} & \TTT{\TIT{y2}}
238 \end{qmatrix} \begin{qmatrix}
239 \bar{\TTT{\TIT{x}}} \\ \bar{\TTT{\TIT{y}}}
240 \end{qmatrix}
241 \]
242
243 For example,
244 \begin{Verbatim}[commandchars=\|\[\]]
245 \referencesystem(1,2)(1,0)(0.5,0.5)
246 \end{Verbatim}
247 sets a new reference system that has its origin in the point $O(1,2)$
248 and the coordinate vectors $\vec u_1=(1,0)$ and $\vec u_2=(1/2,1/2)$.
249 The following pictures show this coordinate system built on the standard
250 reference system
251 and a Cartesian grid refered to the new reference system.
252
253 \noindent
254 \setlength\unitlength{1cm}%
255 \renewcommand{\Pictlabelsep}{0.2}
256 \begin{Picture}(-3.1,-3.1)(3.1,3.1)
257 \put(-1.5,0){\line(1,0){3}}
258 \put(0,-1.5){\line(0,1){3}}
259 {\makenolabels
260 \cartesianaxes(-3,-3)(3,3)}
261 \thicklines
262 \xVECTOR(0,0)(1,2)
263 \pictcolor{red}
264 \referencesystem(1,2)(1,0)(0.5,0.5)
265 \Put[-45](0,0){$O$}
266 \renewcommand\axescolor{red}
267 \renewcommand\axeslabelcolor{red}
268 \cartesianaxes(-2.1,-2.1)(2.1,2.1)
269 \linethickness{1pt}
270 \xVECTOR(0,0)(1,0)
271 \xVECTOR(0,0)(0,1)
272 \rPut{SE}(1,0){$\vec u_1$}
273 \Put[SE](0,1){$\vec u_2$}
274 \end{Picture}
275 \hfill%
276 {\referencesystem(1,2)(1,0)(0.5,0.5)
277 \begin{Picture}(-3.6,-3.6)(3.5,3.5)
278 \thinlines
279 \cartesiangrid(-3,-3)(3,3)
280 \pictcolor{red}
281 \linethickness{1pt}
282 \xVECTOR(0,0)(1,0)
283 \xVECTOR(0,0)(0,1)
284 \end{Picture}}
285
286 Alternatively, you can use the \csdef{changereferencesystem} declaration:
287 in the instruction
288 \begin{Verbatim}[commandchars=\|\[\]]
289 \changereferencesystem(|TIT[x0],|TIT[y0])(|TIT[x1],|TIT[y1])(|TIT[x2],|TIT[y2])
290 \end{Verbatim}
291 point $(\TTT{\TIT{x0}},\TTT{\TIT{y0})}$ and vectors
292 $(\TTT{\TIT{x1}},\TTT{\TIT{y1}})$ i $(\TTT{\TIT{x2}},\TTT{\TIT{y2}})$
293 are not refered to the standard system,
294 but to the \emph{active} reference system.\footnote{%
295 In other words, the instruction
296 \cs{referencesystem} changes from the standard reference system
297 to the new one, while
298 \cs{changereferencesystem} changes from the active system.}
299 Moreover, as the more interesting (and frequent) reference system changes
300 consist of translations of the origin, rotations of the axes
301 and symmetries, \package{xpicture}
302 introduces three specific commands to these special cases:
303 \ttslashindex{translateorigin}
304 \begin{Verbatim}[commandchars=\|\[\]]
305 \translateorigin(|TIT[x0],|TIT[y0])
306 \end{Verbatim}
307 moves the origin to the specified coordinates.
308 \ttslashindex{rotateaxes}
309 \begin{Verbatim}[commandchars=\|\[\]]
310 \rotateaxes{|TIT[angle]}
311 \end{Verbatim}
312 rotates the axes. The \TTT{\TIT{angle}} parameter is interpreted
313 as the rotation angle in radians
314 (if the \csdef{radiansangles} declaration is active) or in
315 sexagesimal degrees (if the \csdef{degreesangles} declaration is active).
316 And\ttslashindex{symmetrize}
317 \begin{Verbatim}[commandchars=\|\[\]]
318 \symmetrize{|TIT[angle]}
319 \end{Verbatim}
320 performs a symmetry, being \TTT{\TIT{angle}}
321 the angle between the $x$ axis and the symmetry axis.
322 Also here, the \csdef{radiansangles} and \csdef{degreesangles}
323 declarations determine if angles are
324 interpreted as radians or degrees.
325 %
326 These three declarations always apply to the active reference system.
327 \begin{Exemple}
328 \newcommand{\mypicture}{%
329 {\thicklines
330 \xVECTOR(-1,-1)(1,1)
331 \pictcolor{red}\Circle{1}
332 \pictcolor{blue}\regularPolygon{1}{4}
333 \polarreference\degreesangles
334 \pictcolor{green}\Polygon(1,90)(0,0)(1,-30)}}
335 \centering
336 \setlength{\unitlength}{1cm}
337 \fbox{\begin{Picture}[black!5!white](-1.5,-6.5)(14.5,1.5)
338 \cartesiangrid(-1,-1)(14,1)
339 \mypicture
340 {\referencesystem(3,0)(1,1)(1,0)
341 \mypicture
342 \changereferencesystem(0,4)(-1,1)(1,-2)
343 \mypicture}
344 \degreesangles
345 \translateorigin(10,0)
346 {\rotateaxes{45}
347 \mypicture}
348 \translateorigin(3,0)
349 \symmetrize{45}
350 \mypicture
351 \referencesystem(6.5,-4)(7,0)(0,-2)\mypicture
352 \end{Picture}}
353 \end{Exemple}
354
355 The \csdef{standardreferencesystem} declaration restores the standard
356 reference.
357
358 \medskip
359
360 Changes of reference system can
361 be used inside or outside the \environ{Picture} environment.
362 In the next sections we will see what are the effects produced in each case.
363
364 \subsubsection{Polar coordinates}
365 Instead of Cartesian coordinates, we can refer to a point $P$ using the
366 polar coordinates $(r,\phi)$ of this point:
367 $r$ is the distance from the origin $O$ and $\phi$ is the angle between
368 the first coordinate vector and the $OP$ segment.
369 The \csdef{cartesianreference} and \csdef{polarreference} declarations
370 establish the coordinates of one or the other type.
371 By default, the Cartesian coordinates are used, but in some cases
372 is much easier determine polar coordinates.
373 Additionally, the \csdef{radiansangles} and \csdef{degreesangles}
374 declarations
375 sets angle measuring in radians or in degrees, respectively
376 (by default, angles are measured in radians).
377
378 The following example shows a typical situation in which it is more
379 appropriate to use polar coordinates:
380 the \emph{natural} way to enter coordinates on a circle is using
381 polar coordinates.
382
383 \begin{exemple}
384 \setlength{\unitlength}{3cm}
385 \fbox{\begin{Picture}(-1.3,-1.3)(1.3,1.3)
386 \polarreference
387 \degreesangles
388
389 \renewcommand{\Pictlabelsep}{0.1}
390
391 \multiPut(1,0)(0,30){12}{\circle*{0.05}}
392 % Put twelve dots, one unit apart,
393 % at 0, 30, 60, ..., 330 degrees
394
395 \cPut{90}(1,90){\textsc{xii}}
396 \cPut{0}(1,0){\textsc{iii}}
397 \cPut{270}(1,270){\textsc{vi}}
398 \cPut{180}(1,180){\textsc{ix}}
399
400 \pictcolor{blue}\thicklines
401
402 \arrowsize{8}{2}
403 \xtrivVECTOR(0,0)(0.5,37.5)
404 \xtrivVECTOR(0,0)(0.9,180)
405
406 \Put(0,0){\circle*{0.1}}
407 \linethickness{4pt}
408 \Circle{1.3}
409 \end{Picture}}
410 \end{exemple}
411
412 The new commands defined in the \package{xpicture} package and requiring
413 some kind of coordinates support polar coordinates,
414 except the \environ{Picture} and \environ{xpicture} environments
415 and the \cs{cartesianaxes} and \cs{cartesiangrid} environments.
416 \subsection{The \environ{Picture} (or \environ{xpicture}) environment}
417 The \package{xpicture} package supports all drawing commands
418 from standard \LaTeX;
419 in particular, you can use the \environ{picture} environment.
420 However, in the expression
421 \begin{Verbatim}[commandchars=\|\[\]]
422 \begin{picture}(|TIT[x],|TIT[y])(|TIT[x0],|TIT[y0])
423 \end{Verbatim}
424 the pairs of numbers \TTT{(\TIT x,\TIT y)} and
425 \TTT{(\TIT{x0},\TIT{y0})} always denote standard coordinates,
426 namely,
427 the \environ{picture} environment only uses the standard reference,
428 thus it defines, as drawing area, the rectangle
429 \TTT{[\TIT{x0},\TIT{x-x0}]}$\times$\TTT{[\TIT{y0},\TIT{y-y0}]},
430 regardless of whether this is the active reference.
431 If we want draw a picture referring coordinates to an alternative reference
432 system, to determine the appropriate drawing area in absolute coordinates
433 is not obvious (and often is difficult).
434 However, the \environdef{Picture} environment
435 defines a working area on the active reference system: the
436 \begin{Verbatim}[commandchars=\|\{\}]
437 \begin|{Picture|}[|TIT{color}](|TIT{x0},|TIT{y0})(|TIT{x1},|TIT{y1})
438 \end{Verbatim}
439 instruction fixes the drawing area
440 \TTT{[\TIT{x0},\TIT{x1}]}$\times$\TTT{[\TIT{y0},\TIT{y1}]},
441 refered to the active reference system.
442 Here, the \TTT{(\TIT{x0},\TIT{y0})} i \TTT{(\TIT{x1},\TIT{y1})}
443 coordinates are always rectangular
444 (even when reference in polar coordinates is active).
445 More precisely, this environment defines a \environ{picture} box
446 that circumscribes our drawing area.
447 If the optional argument is used, background is colored in the given
448 \textit{color}.
449
450 \emph{Very important: note that the syntax of the
451 \environ{picture} environment is not analogous
452 to the new environment \environ{Picture}}:
453 Here two pairs of coordinates are required,
454 \TTT{(\TIT{x0},\TIT{y0})} and \TTT{(\TIT{x1},\TIT{y1})},
455 representing two opposite corners of the drawing area.\footnote{%
456 Although it may seem more \emph{logical}
457 preserve the syntax of \environ{picture} environment,
458 it is more natural to define the drawing area in that way.}
459 Obviously, if the reference sustem is the standard, expression
460 \begin{Verbatim}[commandchars=\|\[\]]
461 \begin{Picture}(0,0)(|TIT[x],|TIT[y])
462 \end{Verbatim}
463 is equivalent to
464 \begin{Verbatim}[commandchars=\|\[\]]
465 \begin{picture}(|TIT[x],|TIT[y])
466 \end{Verbatim}
467
468 The following example shows the boxes produced by the
469 \environ{picture} and \environ{Picture} environments.
470
471 \medskip
472
473 \begin{Exemple}
474 \begin{center}
475 \setlength{\unitlength}{0.5cm}
476 \referencesystem(0,0)(1,-1)(1,1)
477
478 \fbox{\begin{picture}(6,6)(-3,-3)
479 \cartesiangrid(-3,-3)(3,3)
480 \end{picture}}\qquad
481 \fbox{\begin{Picture}(-3,-3)(3,3)
482 \cartesiangrid(-3,-3)(3,3)
483 \end{Picture}}
484 \end{center}
485 \end{Exemple}
486
487 The left picture does not fit the box.
488 In fact, some elementary geometric considerations
489 shown that a square box of $ 12\times12$ units of length must be reserved,
490 \begin{Verbatim}[commandchars=\|\[\]]
491 \begin{picture}(12,12)(-6,-6)
492 \end{Verbatim}
493 The use of the \environ{Picture} environment frees us to determine the
494 actual dimensions of the drawing.
495
496 The new environment \environdef{xpicture} is an alias to the
497 \environ{Picture} environment.
498 Its sintax and its behavior are identical.
499
500 On the other hand, the \csdef{draftPictures} declaration
501 disables all the instructions defined in this package,
502 replacing each picture set in a \environ{Picture} environment
503 by a parallelogram circumscribed by a white rectangle (the box that shows
504 the area reserved for the drawing).\footnote{If you use an instruction
505 not directly defined by \package{xpicture} (inside of a \environ{Picture}
506 environment), this instruction may take effect.}
507
508 \begin{center}
509 \setlength{\unitlength}{1cm}
510 \draftPictures
511
512 \begin{minipage}{5cm}\centering
513 \begin{Picture}(0,0)(5,5)
514 \end{Picture}
515
516 \verb+\standardreferencesystem+
517 \end{minipage}\quad
518 \begin{minipage}{7.5cm}\centering
519 \referencesystem(0,0)(1,0)(0.5,1)
520 \begin{Picture}(0,0)(5,5)
521 \end{Picture}
522
523 \verb+\referencesystem(0,0)(1,0)(0.5,1)+
524 \end{minipage}
525 \end{center}
526
527 \subsection{Coordinate axes}
528 Instruction\ttslashindex{cartesianaxes}
529 \begin{Verbatim}[commandchars=\|\[\]]
530 \cartesianaxes(|TIT[x0],|TIT[y0])(|TIT[x1],|TIT[y1])
531 \end{Verbatim}
532 draws the coordinate axes corresponding to the
533 \TTT{[\TIT{x0},\TIT{x1}]}$\times$\TTT{[\TIT{y0},\TIT{y1}]} rectangle.
534 Arguments \TTT{\TIT{x0}}, \TTT{\TIT{y0}},
535 \TTT{\TIT{x1}} and \TTT{\TIT{y1}} must satisfy the conditions
536 \TTT{\TIT{x0}}$<$\TTT{\TIT{x1}} and \TTT{\TIT{y0}}$<$\TTT{\TIT{y1}}.
537 Here, coordinates \TTT{(\TIT{x0},\TIT{y0})} and \TTT{(\TIT{x1},\TIT{y1})}
538 are always rectangular (even when reference in polar coordinates is active).
539 \begin{exemple}
540 \begin{center}
541 \setlength{\unitlength}{0.75cm}%
542 \begin{Picture}[black!10!white](-4,-3)(4,3)
543 \renewcommand{\Pictlabelsep}{0.2}
544 \cartesianaxes(-3.5,-2.5)(3.5,2.5)
545 \Put[r](3.5,0){$x$}
546 \Put[t](0,2.5){$y$}
547 \end{Picture}
548 \end{center}
549 \end{exemple}
550 \begin{exemple}
551 \begin{center}
552 \referencesystem(0,0)(1,0)(0.5,1)
553 \setlength{\unitlength}{0.75cm}%
554 \begin{Picture}[black!10!white](-4,-3)(4,3)
555 \renewcommand{\Pictlabelsep}{0.2}
556 \cartesianaxes(-3.5,-2.5)(3.5,2.5)
557 \Put[r](3.5,0){$x$}
558 \Put[t](0,2.5){$y$}
559 \end{Picture}
560 \end{center}
561 \end{exemple}
562 The following parameters control the style of the axes, the cut marks
563 and labels on the axes:
564
565 \subsubsection{The style of the axes}
566 \begin{description}
567 \item[\csdef{axescolor}] By default, the axes color is \TTT{black}, but
568 we can change it by redefining the \cs{axescolor} declaration. For example,
569 \begin{Verbatim}[commandchars=\|\[\]]
570 \renewcommand{\axescolor}{orange}
571 \end{Verbatim}
572
573 We must use a color name predefined in the package \textsf{xcolor}
574 or defined by the user (for example, using the \cs{definecolor} command).
575 \item[\csdef{axesthickness}] Length determining the thickness of axes
576 (default \verb+1 pt+).
577 You can modify it using any command that fixes a length (as \cs{setlength}
578 or \cs{settowidth}).
579 \item[\csdef{xunitdivisions}, \csdef{yunitdivisions}] Number of subdivisions of
580 the unit (in each axis).
581 By default, 1. These arguments can also be redefined using
582 the \cs{renewcommand} command (they must be positive integers).
583 \end{description}
584 \begin{exemple}
585 \renewcommand{\xunitdivisions}{2}
586 \renewcommand{\yunitdivisions}{3}
587
588 \begin{center}
589 \setlength{\unitlength}{1cm}%
590 \begin{Picture}(-4,-4)(4,4)
591 \cartesianaxes(-3.5,-3.5)(3.5,3.5)
592 \end{Picture}
593 \end{center}
594 \end{exemple}
595 \subsubsection{Axes position}
596 The coordinate axes (and also tags and cut marks)
597 are placed by default in the traditional way, on the $y = 0$ (the $x$ axis)
598 and $x = 0$ (the $y$ axis) lines.
599 However, sometimes the fact that labels are inside the graphic can be
600 annoying.\footnote{And produces strange effects when the origin $(0.0)$
601 is not in the drawing area.}
602 Alternatively, we can place axes and tags at the
603 lower and left sides of the coordinate rectangle.
604 To choose between these two options we should use the following
605 declarations:
606 \begin{description}
607 \item[\csdef{internalaxes}, \csdef{externalaxes}]
608 If the \cs{internalaxes} declaration is active, then axes lies
609 on $y=0$ and $x=0$.
610
611 However, if we activate the \cs{externalaxes} declaration, the axes
612 produced by the instruction
613 \begin{Verbatim}[commandchars=\|\[\]]
614 \cartesianaxes(|TIT[x0],|TIT[y0])(|TIT[x1],|TIT[y1])
615 \end{Verbatim}
616 lies on $y=\TTT{\TIT{y0}}$ and $x=\TTT{\TIT{x0}}$.
617
618 By default, the \cs{internalaxes} declaration is active.
619 \end{description}
620 \begin{exemple}
621 \renewcommand{\xunitdivisions}{2}
622 \renewcommand{\yunitdivisions}{2}
623
624 \begin{center}
625 \externalaxes
626 \setlength{\unitlength}{1cm}%
627 \begin{Picture}(-4,-4)(4,4)
628 \cartesianaxes(-3.5,-3.5)(3.5,3.5)
629 \end{Picture}
630 \end{center}
631 \end{exemple}
632
633 \subsubsection{Tags style}
634 The numerical tags on the axes are made in math mode.
635 If you need textual labels, put them in a \cs{mbox} or,
636 using \package{amsmath}, a \cs{text} box.
637 We can control the color, attributes and distance to the axes of these tags,
638 redefining
639 (with \cs{renewcommand}) the following marks:
640 \begin{description}
641 \item[\csdef{axeslabelcolor}] The color of the numerical tags on the axes.
642 By default, this color is identical to the axes color.
643 \item[\csdef{axeslabelsize}] Size of numerical tags.
644 By default, \cs{small}.
645 \item[\csdef{axeslabelmathversion}]
646 Mathversion of numerical tags.
647 By default, \TTT{normal}.\footnote{Standard \emph{math versions}
648 are \TTT{normal} and \TTT{bold}, but some packages
649 define other math versions.}
650 \item[\csdef{axeslabelmathalphabet}] Mathalphabet of numerical tags.
651 By default, \cs{mathrm}.
652 \item[\csdef{axislabelsep}] Distance between tags and cut marks,
653 measured in \cs{unitlength} units;\footnote{The distance between axes and
654 tags equals \cs{ticssize}$+$\cs{axislabelsep}.}
655 by default, \verb+0.1+ (see later the description of \cs{makenotics}).
656 \end{description}
657
658 \subsubsection{Tags position}
659 Position of tags is controlled by two declarations:
660 \begin{description}
661 \item[\cs{xlabelpos\{\TIT{position}\}}]\ttslashindex{xlabelpos}
662 change the relative position of labels in $x$ axis.
663 Admissible values are those allowed in the \TTT{\TIT{position}}
664 argument of command \cs{Put} (see subsection~\ref{subsec:put}).
665 Default is \verb+-90+.
666 \item[\cs{ylabelpos\{\TIT{position}\}}]\ttslashindex{ylabelpos}
667 change the relative position of labels in $y$ axis.
668 Default is \verb+180+.
669 \end{description}
670
671 \subsubsection{Style of cut marks}
672 Units (and, optionally, unit fractions) are marked over axes with small
673 segments,
674 the style of which is controlled by the following parameters:
675 \begin{description}
676 \item[\csdef{ticssize}, \csdef{secundaryticssize}]
677 These lengths control the size of the tics:
678 \cs{ticssize} is half the length of main cuts
679 (by default, \verb+4pt+)
680 and \cs{secundaryticssize} is half the length of secundary cuts
681 (by default, \verb+2pt+).
682 \item[\csdef{ticsthickness}] Thickness of the marks on axes
683 (by default, \verb+1pt+).
684 \item[\csdef{ticscolor}] Color of the marks on axes (by default, \verb+black+).
685 \end{description}
686 \begin{exemple}
687 \renewcommand{\axescolor}{blue}
688 \setlength{\axesthickness}{3pt}
689 \renewcommand{\xunitdivisions}{2}
690 \renewcommand{\yunitdivisions}{3}
691
692 \renewcommand{\axeslabelcolor}{teal}
693 \renewcommand{\axeslabelsize}{\footnotesize}
694 \renewcommand{\axeslabelmathversion}{bold}
695 \renewcommand{\axeslabelmathalphabet}{\mathsf}
696 \renewcommand{\axislabelsep}{0.05}
697 \xlabelpos{ttl}
698 \ylabelpos{r}
699
700 \setlength{\ticssize}{0.2cm}
701 \setlength{\secundaryticssize}{0.1cm}
702 \setlength{\ticsthickness}{2pt}
703 \renewcommand{\ticscolor}{blue!50}
704
705 \begin{center}
706 \degreesangles
707 \rotateaxes{-30}
708 \setlength{\unitlength}{0.75cm}%
709 \begin{Picture}(-5,-4)(5,4)
710 \cartesianaxes(-4.5,-3.5)(4.5,3.5)
711 \end{Picture}
712 \end{center}
713 \end{exemple}
714
715 \subsubsection{Removing and directly printing cut marks and labels}
716 \begin{description}
717 \item [\csdef{maketics}, \csdef{makenotics}]
718 These two declarations determine if
719 divisions on the axes should be marked or not.
720 By default the \cs{maketics} declaration is active.
721
722 If divisions are not marked, the \csdef{axislabelsep}
723 declaration determines the distance between axes and labels.
724 \end{description}
725 \begin{exemple}
726 \begin{center}
727 \setlength{\unitlength}{0.75cm}%
728 \begin{Picture}(-4.5,-2.5)(4.5,2.5)
729 \makenotics
730 \cartesianaxes(-4,-2)(4,2)
731 \end{Picture}
732 \end{center}
733 \end{exemple}
734 \begin{description}
735 \item [\csdef{makelabels}, \csdef{makenolabels}] Two declarations
736 determining whether numerical labels on the axes must appear or not.
737 By default, the \cs{makelabels} declaration is active.
738 \end{description}
739 \begin{exemple}
740 \begin{center}
741 \setlength{\unitlength}{0.75cm}%
742 \begin{Picture}(-4.5,-2.5)(4.5,2.5)
743 \makenolabels
744 \cartesianaxes(-4,-2)(4,2)
745 \end{Picture}
746 \end{center}
747 \end{exemple}
748
749 Declarations \cs{makenotics} and \cs{makenolabels}
750 can be useful when you want to show only some specific coordinates,
751 when the points to be highlighted on the axes are not integers
752 and when you need to print labels in some special format. In this cases
753 you can plot tics and/or print labels using the following commands.
754 \begin{description}
755 \item [\cs{plotxtic\{\TIT{x-coor}\}}, \cs{plotytic\{\TIT{y-coor}\}}]
756 \ttslashindex{plotxtic}\ttslashindex{plotytic}
757 plot a tic for the given \TIT{x} or \TIT{y} coordinate.
758 \item [\cs{printxlabel\{\TIT{x-coor}\}\{\TIT{label}\}},
759 \cs{printylabel\{\TIT{y-coor}\}\{\TIT{label}\}}]
760 \ttslashindex{printxlabel}\ttslashindex{printylabel}
761 print \TIT{label}
762 for the given \TIT{x} or \TIT{y} coordinate. Labels are printed in math mode.
763 \item [\cs{printxticlabel\{\TIT{x-coor}\}\{\TIT{label}\}},
764 \cs{printyticlabel\{\TIT{y-coor}\}\{\TIT{label}\}}]
765 plot a tic and print \TIT{label} for the given \TIT{x} or \TIT{y} coordinate.
766 \end{description}
767 \begin{exemple}
768 \begin{center}
769 \setlength{\unitlength}{1cm}%
770 \begin{Picture}(-4.5,-0.5)(4.5,3.5)
771 \makenolabels
772 \makenotics
773 \cartesianaxes(-4,0)(4,3)
774
775 \plotytic{0.5}
776 \printylabel{0.5}{1/2}
777 \printxticlabel{2}{2}
778
779 \Polyline(2,0)(2,0.5)(0,0,5)
780 \thicklines
781 \SCALEfunction{0.125}{\SQUAREfunction}{\F}
782 \PlotFunction[3]{\F}{-4}{4}
783 \end{Picture}
784 \end{center}
785 \end{exemple}
786
787 Multiple equally spaced tics and/or labels can be drawn simultaneously:
788 \begin{description}
789 \item [\cs{plotxtics\{\TIT{firstcoor}\}\{\TIT{incr}\}\{\TIT{bound}\}},
790 \cs{plotytics\{\TIT{firstcoor}\}\{\TIT{incr}\}\{\TIT{bound}\}}]
791 \ttslashindex{plotxtics}\ttslashindex{plotytics}
792 plot several (\TIT{x} or \TIT{y}) tics,
793 from the initial coordinate \TIT{firstcoor}; \TIT{incr} is the distance
794 between consecutive tics, and the last tic is not in a position
795 greater than \TIT{bound}.
796 \item [\cs{printxlabels[\TIT{digits}]\{\TIT{firstcoor}\}\{\TIT{incr}\}%
797 \{\TIT{bound}\}},
798 \cs{printylabels[\TIT{digits}]\{\TIT{firstcoor}\}\{\TIT{incr}\}%
799 \{\TIT{bound}\}}]
800 \ttslashindex{printxlabels}\ttslashindex{printylabels} print several labels,
801 from the initial coordinate \TIT{firstcoor}; \TIT{incr} is the distance
802 between consecutive label positions,
803 and the last position is not greater than \TIT{bound}.
804 The optional argument \TIT{digits} is the number of decimal digits to be
805 printed (by default, numbers are printed with its natural number of decimals).
806 \item [\cs{printxticslabels[\TIT{digits}]\{\TIT{firstcoor}\}\{\TIT{incr}\}%
807 \{\TIT{bound}\}}]\ttslashindex{printxticslabels}
808 plot \TIT{x} tics and labels simultaneously.
809 \item [\cs{printyticslabels[\TIT{digits}]\{\TIT{firstcoor}\}\{\TIT{incr}\}%
810 \{\TIT{bound}\}}]\ttslashindex{printyticslabels}
811 plot \TIT{y} tics and labels simultaneously.
812 \end{description}
813 \begin{exemple}
814 \externalaxes
815 \setlength{\unitlength}{1cm}
816 \renewcommand{\axeslabelsize}{\tiny}
817 \referencesystem(0,0)(1.5,0)(0,2)
818 \begin{center}
819 \begin{Picture}(-2.5,-1.5)(2.5,1.5)
820 \makenotics
821 \makenolabels
822 \cartesianaxes(-2.25,-1.25)(2.25,1.25)
823 \printxticslabels[1]{-2}{0.5}{2.25}
824 \printyticslabels[4]{-1}{0.25}{1}
825 \end{Picture}
826 \end{center}
827 \end{exemple}
828 \begin{Exemple}
829 \setlength{\unitlength}{1cm}
830 \begin{center}
831 \begin{Picture}(-7,-2.5)(7,2.5)
832 {\referencesystem(0,0)(\numberHALFPI,0)(0,1)
833 \renewcommand{\xunitdivisions}{2}
834 \renewcommand{\yunitdivisions}{2}
835 \makenolabels
836 \renewcommand{\Pictlabelsep}{0.25}
837 \cartesianaxes(-4.2,-2.2)(4.2,2.2)
838
839 \printylabels{-2}{0.5}{2}
840
841 \highestlabel{$-3\pi/2$}
842 \printxlabel{-4}{-2\pi}
843 \printxlabel{-3}{-3\pi/2}
844 \printxlabel{-2}{-\pi}
845 \printxlabel{-1}{-\pi/2}
846 \printxlabel{1}{\pi/2}
847 \printxlabel{2}{\pi}
848 \printxlabel{3}{3\pi/2}
849 \printxlabel{4}{2\pi}
850 }
851 \end{Picture}
852 \end{center}
853 \end{Exemple}
854
855 \subsection{Cartesian grids}
856 As an alternative to the \cs{cartesianaxes} command,
857 we can use \csdef{cartesiangrid},
858 to better visualize the coordinates:
859 \begin{Verbatim}[commandchars=\|\[\]]
860 \cartesiangrid(|begin[math]x0,y0|end[math])(|begin[math]x1,y1|end[math])
861 \end{Verbatim}
862 \begin{exemple}
863 \definecolor{myblue}{cmyk}{1,1,0,0.5}
864 \renewcommand{\gridcolor}{myblue}
865 \renewcommand{\secundarygridcolor}{cyan}
866 \setlength{\gridthickness}{0.5pt}
867 \setlength{\secundarygridthickness}{0.1pt}
868 \renewcommand{\xunitdivisions}{5}
869 \renewcommand{\yunitdivisions}{5}
870 \renewcommand{\axeslabelsize}{\footnotesize}
871 \begin{center}
872 \setlength{\unitlength}{1cm}
873 \begin{Picture}(-3.5,-2.5)(3.5,2.5)
874 \cartesiangrid(-3.4,-2.4)(3.4,2.4)
875 \end{Picture}
876 \end{center}
877 \end{exemple}
878 \begin{exemple}
879 \definecolor{myblue}{cmyk}{1,1,0,0.5}
880 \renewcommand{\gridcolor}{myblue}
881 \renewcommand{\secundarygridcolor}{cyan}
882 \setlength{\gridthickness}{0.5pt}
883 \setlength{\secundarygridthickness}{0.1pt}
884 \renewcommand{\xunitdivisions}{5}
885 \renewcommand{\yunitdivisions}{5}
886 \renewcommand{\axeslabelsize}{\footnotesize}
887 \begin{center}
888 \setlength{\unitlength}{1cm}
889 \referencesystem(0,0)(1,0)(0.25,1)
890 \externalaxes
891 \begin{Picture}(-4,-3)(4,3)
892 \cartesiangrid(-3.4,-2.4)(3.4,2.4)
893 \end{Picture}
894 \end{center}
895 \end{exemple}
896
897 \subsubsection{Grid style}
898 Note that, in addition to the parameters outlined above, there are the
899 following ones, which control the style of the grid
900 (as in previous cases, these parameters are changed
901 by redefining them with the \cs{renewcommand} declaration,
902 or using the usual instructions when they are lengths).
903
904 \begin{description}
905 \item [\csdef{gridcolor}] determines the color of main divisions in the grid
906 (regardless of the axes color). By default, this color is \verb+gray+.
907 \item [\csdef{secundarygridcolor}] determines the color of secundary
908 divisions in the grid.
909 By default, \verb+lightgray+).
910 \item[\csdef{gridthickness}] thickness of main divisions
911 (by default, \verb+0.4pt+).
912 \item[\csdef{secundarygridthickness}] thickness of secundary divisions
913 (by default, \verb+0.2pt+).
914 \end{description}
915 \subsection{Polar grids}
916 Finally, instead of Cartesian axes, we can construct a polar grid
917 (obviously, this option will be interesting when we use polar coordinates).
918 \ttslashindex{polargrid}
919 \begin{Verbatim}[commandchars=\|\[\]]
920 \polargrid{|TIT[radius]}{|TIT[circledivs]}
921 \end{Verbatim}
922 (\TTT{\TIT{radius}} and \TTT{\TIT{circledivs}} are, respectively,
923 the radius and the number of divisions of the circle
924 (\TTT{\TIT{circledivs}}must be a positive integer).
925
926 This command supports the same parameters that \cs{cartesianaxes} and
927 \cs{cartesiangrid} (when they makes sense), and also the following:
928 \begin{description}
929 \item[\csdef{runitdivisions}] Number of radial subdivisions of the unit.
930 By default, $1$ (it must be a positive integer).
931 \end{description}
932 \begin{exemple}
933 \renewcommand{\runitdivisions}{2}
934 \setlength{\unitlength}{0.75cm}
935 \renewcommand{\gridcolor}{magenta}
936 \begin{center}
937 \begin{Picture}(-4,-4)(4,4)
938 \polargrid{3.5}{12}
939 \end{Picture}
940 \end{center}
941 \end{exemple}
942 \begin{exemple}
943 \renewcommand{\runitdivisions}{2}
944 \setlength{\unitlength}{0.75cm}
945 \renewcommand{\gridcolor}{magenta}
946 \referencesystem(0,0)(1,-1)(0.5,0.5)
947 \begin{center}
948 \begin{Picture}(-3.5,-3.5)(3.5,3.5)
949 \polargrid{3.5}{12}
950 \end{Picture}
951 \end{center}
952 \end{exemple}
953 \begin{description}
954 \item[\csdef{degreespolarlabels}, \csdef{radianspolarlabels}]
955 Arcs are printed, by default, in radians.
956 If you want angular units mesured in degrees,
957 use the \csdef{degreespolarlabels} declaration (obviously,
958 \csdef{radianspolarlabels} recovers tags in radians).
959 \end{description}
960 \begin{exemple}
961 \begin{center}
962 \degreespolarlabels
963 \setlength{\unitlength}{1cm}
964 \begin{Picture}(-4,-4)(4,4)
965 \polargrid{3}{24}
966 \end{Picture}
967 \end{center}
968 \end{exemple}
969 \begin{description}
970 \item[\csdef{rlabelpos}] Relative position of labels in polar axis.
971 Admissible values are those allowed in the \TTT{\TIT{position}}
972 argument of command \cs{Put} (see subsection~\ref{subsec:put}).
973 Default is \verb+bbr+.
974 \end{description}
975 \begin{exemple}
976 \begin{center}
977 \setlength{\unitlength}{1cm}
978 \begin{Picture}(-4,-4)(4,4)
979 \rlabelpos{b}
980 \polargrid{3.5}{10}
981 \end{Picture}
982 \end{center}
983 \end{exemple}
984
985
986 To remove tags on the polar axis and angles you can use the
987 \csdef{makenolabels} declaration.
988
989 \section[Alternatives to some standard commands]{%
990 Alternatives to standard commands
991 \cs{put},\cs{multiput}, \cs{line}, and \cs{vector}}
992 Standard commands used inside the \environ{picture} environment
993 are not modified by this package
994 (although if we include these commands in the body of a \environ{Picture}
995 environment).
996 In particular, there does not affect the \cs{referencesystem} declaration.
997 This package introduces similar commands to those which are sensitive to the
998 active reference system and give us a greater control over their behavior.
999 These are the instructions described below.
1000
1001 \subsection{Extensions of the \cs{put} command}\label{subsec:put}
1002 \begin{description}
1003 \item[\csdef{Put}, \csdef{cPut}, \csdef{rPut}]
1004 \mbox{}
1005
1006 \begin{Verbatim}[commandchars=\|\{\}]
1007 \Put[|TIT{position}](|TIT{x},|TIT{y})|{|TIT{object}|}
1008 \Put*[|TIT{position}](|TIT{x},|TIT{y})|{|TIT{object}|}
1009 \cPut|{|TIT{position}|}(|TIT{x},|TIT{y})|{|TIT{object}|}
1010 \rPut|{|TIT{position}|}(|TIT{x},|TIT{y})|{|TIT{object}|}
1011 \rPut*|{|TIT{position}|}(|TIT{x},|TIT{y})|{|TIT{object}|}
1012 \end{Verbatim}
1013 place the drawing pointer in the point
1014 of coordinates \verb+(+\TTT{\TIT{x}}\verb+,+\TTT{\TIT{y}}\verb+)+
1015 with respect to the active reference system (which may coincide or not with
1016 the standard system).
1017 These commands differ in the criteria used to determine the precise position
1018 of the object.
1019
1020 Involved parameters are (see below)
1021 \ttslashindex{Pictlabelsep}
1022 \ttslashindex{defaultPut}
1023 \ttslashindex{highestlabel}
1024 \begin{Verbatim}[commandchars=\|\[\]]
1025 \Pictlabelsep|{|TIT[distance]|}
1026 \defaultPut|{c|}/\defaultPut|{r|}
1027 \highestlabel|{|TIT[text]|}
1028 \end{Verbatim}
1029 \medskip
1030
1031 In the following example, the red circle (included as an argument in the
1032 \cs{put} command) is at the point
1033 of standard coordinates $(1,-1)$; however, in the case of the
1034 blue circle, coordinates $(1,-1)$ refer to the active reference system.
1035 \begin{exemple}
1036 \begin{center}
1037 \setlength{\unitlength}{0.75cm}
1038 \referencesystem(0,0)(1,-1)(1,1)
1039 \begin{Picture}(-2.5,-2.5)(2.5,2.5)
1040 \cartesiangrid(-2,-2)(2,2)
1041 \pictcolor{red}
1042 \put(1,-1){\circle*{0.25}}
1043 \pictcolor{blue}
1044 \Put(1,-1){\circle*{0.25}}
1045 \end{Picture}
1046 \end{center}
1047 \end{exemple}
1048
1049 Recall that coordinates can be rectangular or polar, and angles may
1050 be measured in radians or in degrees.
1051 \begin{exemple}
1052 \begin{center}
1053 \setlength{\unitlength}{1cm}
1054 \begin{Picture}(-2.5,-2.5)(2.5,2.5)
1055 \cartesiangrid(-2,-2)(2,2)
1056 \polarreference
1057 \pictcolor{blue}
1058 \Put(1,\numberHALFPI){\circle*{0.25}}
1059 \degreesangles
1060 \pictcolor{red}
1061 \Put(1,180){\circle*{0.25}}
1062 \end{Picture}
1063 \end{center}
1064 \end{exemple}
1065 \subsubsection{Accurate positioning of the graphical object}
1066 The \TTT{\TIT{position}} argument allows us to fix the relative position of
1067 \TTT{\TIT{object}} respect to point \TTT{(\TIT{x},\TIT{y})}.
1068 Note that this argument is optional in \cs{Put} and \cs{Put*},
1069 but mandatory in the other commands we are describing.
1070 The purpose of this parameter is to rationalize the disposition of
1071 objects, especially when they are not strictly graphical objects
1072 (but labels, text boxes or mathematical formulas). In these cases,
1073 the appropriate choice of coordinates seems a problem that is not well
1074 solved with standard instructions, despite the special syntax of the
1075 \cs{makebox} command in the \environ{picture} environment.
1076 For example, in this picture (which we made using only the standard
1077 \LaTeX{} commands)
1078 \begin{center}
1079 \setlength{\unitlength}{2cm}
1080
1081 \begin{picture}(7,3)(-0.5,-1.5)
1082
1083 \put(0,0){\line(1,0){7}}
1084 \put(0,-1.5){\line(0,1){3}}
1085 \put(0,-1.5){\line(0,-1){0}}
1086 \multiput(1.570796,-0.1)(1.570796,0){4}{\line(0,1){0.2}}
1087 \multiput(-0.1,-1)(0,1){3}{\line(1,0){0.2}}
1088
1089 \qbezier(0,0)(1,1)(1.570796,1)
1090 \qbezier(1.570796,1)(2.141593,1)(3.141593,0)
1091 \qbezier(3.141593,0)(4.141593,-1)(4.712389,-1)
1092 \qbezier(4.712389,-1)(5.283185,-1)(6.283185,0)
1093
1094 \put(-1.570796,0){%
1095 \qbezier(1.570796,1)(2.141593,1)(3.141593,0)
1096 \qbezier(3.141593,0)(4.141593,-1)(4.712389,-1)
1097 \qbezier(4.712389,-1)(5.283185,-1)(6.283185,0)}
1098 \put(4.712389,0){\qbezier(0,0)(1,1)(1.570796,1)}
1099
1100 \put(2.356194,0.707107){$\sin x$}
1101 \put(6.283185,1){$\cos x$}
1102 \put(-0.15,-1){\makebox(0,0)[r]{$-1$}}
1103 \put(-0.15,0){\makebox(0,0)[r]{$0$}}
1104 \put(-0.15,1){\makebox(0,0)[r]{$1$}}
1105 \put(1.570796,-0.15){\makebox(0,0)[t]{$\pi/2$}}
1106 \put(3.141593,-0.15){\makebox(0,0)[t]{$\pi$}}
1107 \put(4.712389,-0.15){\makebox(0,0)[t]{$3\pi/2$}}
1108 \put(6.283185,-0.15){\makebox(0,0)[t]{$2\pi$}}
1109 \end{picture}
1110 \end{center}
1111 we have located numerical labels ($0$, $1$, $\pi$\ldots) at
1112 \TTT{0.15\cs{unitlength}} of its \emph{natural} position over the axes,
1113 while the reference points of tags
1114 ``$\sin x$'' and ``$\cos x$'' are just in points $(3\pi/4,\sin(3\pi/4))$ and
1115 $(2\pi,1)$, using these instructions:
1116 \begin{Verbatim}
1117 \put(2.356194,0.707107){$\sin x$}
1118 \put(6.283185,1){$\cos x$}
1119 \put(-0.15,-1){\makebox(0,0)[r]{$-1$}}
1120 \put(-0.15,0){\makebox(0,0)[r]{$0$}}
1121 \put(-0.15,1){\makebox(0,0)[r]{$1$}}
1122 \put(1.570796,-0.15){\makebox(0,0)[t]{$\pi/2$}}
1123 \put(3.141593,-0.15){\makebox(0,0)[t]{$\pi$}}
1124 \put(4.712389,-0.15){\makebox(0,0)[t]{$3\pi/2$}}
1125 \put(6.283185,-0.15){\makebox(0,0)[t]{$2\pi$}}
1126 \end{Verbatim}
1127
1128 If we change the value of \cs{unitlength}, then these values become
1129 inappropriate and we need to change several lines of code.
1130 \begin{center}
1131 \setlength{\unitlength}{1cm}
1132
1133 \begin{picture}(7,3)(-0.5,-1.5)
1134
1135 \put(0,0){\line(1,0){7}}
1136 \put(0,-1.5){\line(0,1){3}}
1137 \put(0,-1.5){\line(0,-1){0}}
1138 \multiput(1.570796,-0.1)(1.570796,0){4}{\line(0,1){0.2}}
1139 \multiput(-0.1,-1)(0,1){3}{\line(1,0){0.2}}
1140
1141 \qbezier(0,0)(1,1)(1.570796,1)
1142 \qbezier(1.570796,1)(2.141593,1)(3.141593,0)
1143 \qbezier(3.141593,0)(4.141593,-1)(4.712389,-1)
1144 \qbezier(4.712389,-1)(5.283185,-1)(6.283185,0)
1145
1146 \put(-1.570796,0){%
1147 \qbezier(1.570796,1)(2.141593,1)(3.141593,0)
1148 \qbezier(3.141593,0)(4.141593,-1)(4.712389,-1)
1149 \qbezier(4.712389,-1)(5.283185,-1)(6.283185,0)}
1150 \put(4.712389,0){\qbezier(0,0)(1,1)(1.570796,1)}
1151
1152 \put(2.356194,0.707107){$\sin x$}
1153 \put(6.283185,1){$\cos x$}
1154 \put(-0.15,-1){\makebox(0,0)[r]{$-1$}}
1155 \put(-0.15,0){\makebox(0,0)[r]{$0$}}
1156 \put(-0.15,1){\makebox(0,0)[r]{$1$}}
1157 \put(1.570796,-0.15){\makebox(0,0)[t]{$\pi/2$}}
1158 \put(3.141593,-0.15){\makebox(0,0)[t]{$\pi$}}
1159 \put(4.712389,-0.15){\makebox(0,0)[t]{$3\pi/2$}}
1160 \put(6.283185,-0.15){\makebox(0,0)[t]{$2\pi$}}
1161 \end{picture}
1162 \end{center}
1163
1164 Note that, regarding labels along the $x$ axis, instead of aligning them to a
1165 fixed distance of this axis, there would be better to align the baselines
1166 ($\pi$ and $2\pi$ should go down);
1167 some of these labels should
1168 move slightly to the right or to the left to avoid that it cut the graph.
1169 Finally, the tag ``$\cos x$'' should be vertically centered
1170 (with respect to the curve) and slightly moved to the right.
1171 \medskip
1172
1173 Using the \package{xpicture} package we construct this picture
1174 in the following way:
1175 \begin{Exemple}
1176 \MULTIPLY{3}{\numberQUARTERPI}{\numberTQPI}
1177 \SIN{\numberTQPI}{\sinTQPI}
1178
1179 \begin{center}
1180 \setlength{\unitlength}{2cm}
1181 \begin{Picture}(-0.5,-1.5)(6.5,1.5)
1182 {\referencesystem(0,0)(\numberHALFPI,0)(0,1)
1183 \makenolabels
1184 \renewcommand{\Pictlabelsep}{0.1}
1185 \highestlabel{$-3\pi/2$}
1186 \cartesianaxes(0,-1.5)(4.25,1.5)
1187
1188 \rPut{l}(0,-1){$-1$} % put the y-axis labels at left
1189 \rPut{l}(0,0){$0$}
1190 \rPut{l}(0,1){$1$}
1191 \rPut*{bbl}(1,0){$\pi/2$} % put "\pi/2" at bbl
1192 \rPut*{b}(2,0){$\pi$} % put "\pi" at bottom
1193 \rPut*{bbr}(3,0){$3\pi/2$} % put "3\pi/2" at bbr
1194 \rPut*{b}(4,0){$2\pi$} % put "2\pi" at bottom
1195
1196 \rPut*{b}(0,0){\pictcolor{gray}\xLINE(0.75,0)(4.25,0)}} % \baseline of x-labels
1197
1198 \PlotFunction[8]{\COSfunction}{0}{\numberTWOPI}
1199 \PlotFunction[8]{\SINfunction}{0}{\numberTWOPI}
1200
1201 \Put[NE](\numberTQPI,\sinTQPI){$\sin x$} % put "\sin x" at NorthEast
1202 \Put[E](\numberTWOPI,1){$\cos x$} % put "\cos x" at East
1203 \end{Picture}
1204 \end{center}
1205 \end{Exemple}
1206 Here we used several tools to draw the graphs of the functions.
1207 But aside from this, commands \cs{Put}, \cs{rPut} and \cs{rPut*} have allowed
1208 we to determine the logical position of objects in a much more
1209 reasonable way.\footnote{Regarding to labels on coordinated axes
1210 a better choice would be to use other specific commands,
1211 as \cs{printxlabels}. Here we have chosen \cs{rPut} because we are
1212 illustrating this instruction.}
1213
1214 Argument \TTT{\TIT{position}} supports multiple values:
1215 \begin{description}
1216 \item[An integer or decimal number,] determining the angle (in degrees)
1217 where \TTT{\TIT{object}} is placed,
1218 with respect to the reference point \TTT{(\TIT{x},\TIT{y})}.
1219 \end{description}
1220
1221 \begin{Exemple}
1222 \begin{center}
1223 \setlength{\unitlength}{1cm}
1224 \begin{Picture}(0,-1)(9,1)
1225 \makenolabels
1226 \renewcommand{\axescolor}{lightgray}\renewcommand{\ticscolor}{lightgray}
1227 \cartesiangrid(0,-1)(8,1)
1228 \pictcolor{blue}
1229 \Put[0](0,0){0}
1230 \Put[45](1,0){45}
1231 \Put[90](2,0){90}
1232 \Put[135](3,0){135}
1233 \Put[180](4,0){180}
1234 \Put[225](5,0){225}
1235 \Put[270](6,0){270}
1236 \Put[315](7,0){315}
1237 \Put[360](8,0){360}
1238 \end{Picture}
1239 \end{center}
1240 \end{Exemple}
1241 \begin{description}
1242 \item[Letter \TTT{c}] (from \emph{center}),
1243 which places the center of \TTT{\TIT{object}} at point
1244 \verb+(+\TTT{\TIT{x}}\verb+,+\TTT{\TIT{y}}\verb+)+.
1245 \end{description}
1246 \begin{exemple}
1247 \begin{center}
1248 \setlength{\unitlength}{2cm}
1249 \begin{Picture}(-1,-1)(1,1)
1250 \cartesianaxes(-1,-1)(1,1)
1251 \pictcolor{blue}
1252 \Put[c](0,0){A CENTERED BOX}
1253 \end{Picture}
1254 \end{center}
1255 \end{exemple}
1256 Note that this option is not equivalent to the suppression of the optional
1257 argument, because in that case
1258 the reference point of \TTT{\TIT{object}} is located
1259 in \verb+(+\TTT{\TIT{x}}\verb+,+\TTT{\TIT{y}}\verb+)+.
1260 \begin{exemple}
1261 \begin{center}
1262 \setlength{\unitlength}{2cm}
1263 \begin{Picture}(-1,-1)(1,1)
1264 \cartesianaxes(-1,-1)(1,1)
1265 \pictcolor{blue}
1266 \Put(0,0){A NONCENTERED BOX}
1267 \end{Picture}
1268 \end{center}
1269 \end{exemple}
1270 \begin{description}
1271 \item[Letters or letter combinations \TTT N, \TTT E, \TTT S, \TTT W,
1272 \TTT{NE}, \TTT{SE}, \TTT{SW}, \TTT{NW},
1273 \TTT{NNE}, \TTT{ENE}, \TTT{ESE}, \TTT{SSE}, \TTT{SSW}, \TTT{WSW}, \TTT{WNW},
1274 \TTT{NNW}]\mbox{}
1275
1276 Abbreviation of \emph{North}, \emph{East}\ldots, \emph{North-East}\ldots,
1277 \emph{North-North-East}\ldots
1278
1279 For example, the
1280 \begin{Verbatim}
1281 \Put[NE](0,0){A}
1282 \end{Verbatim}
1283 instruction writes ``\verb+A+'' \emph{at north-east} of point \verb+(0,0)+.
1284 \item[Letters o letter combinations \TTT t, \TTT r, \TTT b, \TTT l,
1285 \TTT{tr}, \TTT{br}, \TTT{bl}, \TTT{tl},
1286 \TTT{ttr}, \TTT{rtr}, \TTT{rbr}, \TTT{bbr}, \TTT{bbl}, \TTT{lbl}, \TTT{ltl},
1287 \TTT{ttl}]\mbox{}
1288
1289 Abbreviation of \emph{top}, \emph{right}\ldots, \emph{top-right}\ldots,
1290 \emph{top-top-right}\ldots
1291
1292 For example,
1293 \begin{Verbatim}
1294 \Put[tr](0,0){A}
1295 \end{Verbatim}
1296 writes ``\verb+A+'' \emph{at top and right} of point \verb+(0,0)+.
1297
1298 Parameter \cs{Pictlabelsep} determines the distance between the graphical
1299 object and the given point.
1300 In the following examples we have made this argument very big to clearly
1301 appreciate the positioning of objects.
1302 \end{description}
1303 \begin{exemple}
1304 \renewcommand{\Pictlabelsep}{1}
1305 \begin{center}
1306 \setlength{\unitlength}{2.5cm}%
1307
1308 \begin{Picture}(-1.5,-1.5)(1.5,1.5)
1309 \Put[N](0,0){N}
1310 \Put[S](0,0){S}
1311 \Put[E](0,0){E}
1312 \Put[W](0,0){W}
1313 \Put[NE](0,0){NE}
1314 \Put[SE](0,0){SE}
1315 \Put[SW](0,0){SW}
1316 \Put[NW](0,0){NW}
1317 %
1318 \Put[NNE](0,0){NNE}
1319 \Put[ENE](0,0){ENE}
1320 \Put[ESE](0,0){ESE}
1321 \Put[SSE](0,0){SSE}
1322 \Put[SSW](0,0){SSW}
1323 \Put[WSW](0,0){WSW}
1324 \Put[WNW](0,0){WNW}
1325 \Put[NNW](0,0){NNW}
1326 \Put(0,0){\Circle{1}}
1327 \xLINE(-1,0)(1,0)
1328 \xLINE(0,-1)(0,1)
1329 \end{Picture}
1330 \end{center}
1331 \end{exemple}
1332 \begin{exemple}
1333 \renewcommand{\Pictlabelsep}{1}
1334 \begin{center}
1335 \setlength{\unitlength}{2.5cm}%
1336
1337 \begin{Picture}(-1.5,-1.5)(1.5,1.5)
1338 \Put[t](0,0){t}
1339 \Put[r](0,0){r}
1340 \Put[b](0,0){b}
1341 \Put[l](0,0){l}
1342 \Put[tr](0,0){tr}
1343 \Put[br](0,0){br}
1344 \Put[bl](0,0){bl}
1345 \Put[tl](0,0){tl}
1346 \Put[ttr](0,0){ttr}
1347 \Put[rtr](0,0){rtr}
1348 \Put[rbr](0,0){rbr}
1349 \Put[bbr](0,0){bbr}
1350 \Put[bbl](0,0){bbl}
1351 \Put[lbl](0,0){lbl}
1352 \Put[ltl](0,0){ltl}
1353 \Put[ttl](0,0){ttl}
1354 \Put(0,0){%
1355 \regularPolygon[45]{\numberSQRTTWO}{4}}
1356 \xLINE(-1,0)(1,0)
1357 \xLINE(0,-1)(0,1)
1358 \end{Picture}
1359 \end{center}
1360 \end{exemple}
1361 \end{description}
1362 \paragraph{Rectangular o circular distance?}
1363 Commands \cs{rPut} and \cs{cPut} differ only in the criterion they use
1364 to determine the distance between the reference point and the graphical object.
1365 Command \cs{rPut} places the object (outside of)
1366 the square centered at the reference point and side \verb+2\Pictlabelsep+,
1367 while \cs{cPut} places it in the cercle of radius \verb+\Pictlabelsep+
1368 (letters \verb+r+ and \verb+c+ mean, respectively,
1369 a \emph{rectangular} and \emph{circular} layout).%
1370 \footnote{For the mathematicians: command \cs{cPut} uses the euclidean norm
1371 (or 2-norm), while \cs{rPut} uses the infinite norm.}
1372 Although, for small values of the \cs{Pictlabelsep} parameter,
1373 the difference is subtle and usually not very significant, it is generally best
1374 to use the circular version (because it corresponds to the natural concept of
1375 distance) and reserve the rectangular version
1376 to objects that are placed on horizontal or vertical lines.
1377 \begin{Exemple}
1378 \begin{center}
1379 \setlength{\unitlength}{1.5cm}
1380 \renewcommand{\Pictlabelsep}{1}
1381
1382 \begin{Picture}(-1.5,-1.5)(2,1.5)
1383 \regularPolygon[45]{\numberSQRTTWO}{4}
1384 \Put(0,0){\circle*{0.1}}
1385 \rPut{45}(0,0){r}
1386 \xLINE(0,0)(0,-1)
1387 \thicklines
1388 \renewcommand{\Pictlabelsep}{0.1}
1389 \xLINE(0,0)(1,1)
1390 \xLINE(0,0)(1,0)
1391 \xtrivVECTOR(0,-1)(1,-1)
1392 \xtrivVECTOR(1,-1)(0,-1)
1393 \rPut{b}(0.5,-1){\footnotesize\textbackslash Pictlabelsep}
1394 \xtrivVECTOR(1,-1)(1,0)
1395 \xtrivVECTOR(1,0)(1,-1)
1396 \rPut{r}(1,-0.5){\footnotesize\textbackslash Pictlabelsep}
1397 \polarreference\degreesangles
1398 \xArc{0.3}{0}{45}
1399 \degreesangles
1400 \Put[22.5](0.3,22.5){$45^{\mathrm o}$}
1401 \end{Picture}
1402 \begin{Picture}(-1.5,-1.5)(2,1.5)
1403 \Put(0,0){\circle*{0.1}}
1404 \cPut{45}(0,0){c}
1405 \Circle{1}
1406 \thicklines
1407 \xLINE(0,0)(\numberCOSXLV,\numberCOSXLV)
1408 \xLINE(0,0)(1,0)
1409 \xtrivVECTOR(0,0)(0,-1)
1410 \xtrivVECTOR(0,-1)(0,0)
1411 \renewcommand{\Pictlabelsep}{0.1}
1412 \rPut{r}(0,-0.5){\footnotesize\textbackslash Pictlabelsep}
1413 \polarreference\degreesangles
1414 \xArc{0.3}{0}{45}
1415 \degreesangles
1416 \Put[22.5](0.3,22.5){$45^{\mathrm o}$}
1417 \end{Picture}
1418 \end{center}
1419 \end{Exemple}
1420
1421 Note that if the commands we use are \cs{rPut} or \cs{cPut}, then the
1422 positioners
1423 \verb+t, r, tr+\ldots are equivalent to the corresponding \verb+N, E, NE+\ldots
1424 However, the \cs{Put} command choose between rectangular or circular layout
1425 following this criteria:
1426 \begin{itemize}
1427 \item Positioners of \emph{compass} type (like \verb+NE+) use the circular
1428 layout.
1429 \item Positioners \verb+t, tr+, et cetera use the rectangular layout.
1430 \item If the positioner is an angle (a number), it uses a default position
1431 which is set using the \cs{defaultPut} declaration:
1432 \verb+\defaultPut{c}+
1433 determines a circular distance, while
1434 \verb+\defaultPut{r}+
1435 determines the rectangular alternative.
1436 \end{itemize}
1437 \begin{exemple}
1438 \renewcommand{\Pictlabelsep}{1}
1439 \begin{center}
1440 \setlength{\unitlength}{2.5cm}%
1441
1442 \begin{Picture}(-1.5,-1.5)(1.5,1.5)
1443 \defaultPut{c}
1444 \Put[45](0,0){c}
1445 \defaultPut{r}
1446 \Put[45](0,0){r}
1447 \regularPolygon[45]{\numberSQRTTWO}{4}
1448 \Put(0,0){\Circle{1}}
1449 \xLINE(-1,0)(1,0)
1450 \xLINE(0,-1)(0,1)
1451 \end{Picture}
1452 \end{center}
1453 \end{exemple}
1454 \paragraph{Alignment by the baseline}
1455 Starred versions \cs{Put*} and \cs{rPut*} allow us to align by the baseline
1456 objects positioned below the reference point.
1457 To use these commands, user must decide which is the higher object to be
1458 positioned, and introduce it as an argument of
1459 the \csdef{highestlabel} declaration. For example, typing
1460 \begin{Verbatim}
1461 \highestlabel{\Huge A}
1462 \end{Verbatim}
1463 we reserve a sufficient vertical space to write the character {\Huge A}.
1464
1465 It should be noted that starred versions behave differently
1466 only when the position of the object stands
1467 under the reference point, with positioners
1468 \verb+bbl+, \verb+b+ or \verb+bbr+, or with an appropiate angle
1469 (as \verb+-90+ or \verb+300+); otherwise (including
1470 \verb$S$, \verb$SSW$, et cetera),
1471 the \cs{Put*} and \cs{rPut*} commands are equivalent
1472 to the non-starred commands
1473 \cs{Put} and \cs{rPut}.
1474 \begin{exemple}
1475 \begin{center}
1476 \setlength{\unitlength}{1cm}
1477
1478 \begin{Picture}(-3.5,-1.5)(3.5,1.5)
1479 \xLINE(-3.5,0)(3.5,0)
1480 \multiPut(-3,-0.1)(1,0){7}{\xLINE(0,0)(0,0.2)}
1481 \highestlabel{\Huge A}
1482 \renewcommand{\Pictlabelsep}{0.2}
1483 \Put*[bbl](-3,0){\small A}
1484 \Put*[b](-2,0){\normalsize A}
1485 \Put*[-100](-1,0){\large A}
1486 \Put*[-90](0,0){\Large A}
1487 \Put*[270](1,0){\LARGE A}
1488 \Put*[300](2,0){\huge A}
1489 \Put*[bbr](3,0){\Huge A}
1490 \Put*[bbl](-3.5,0){%
1491 \pictcolor{gray}\xLINE(0,0)(7,0)}
1492 \end{Picture}
1493 \end{center}
1494 \end{exemple}
1495
1496
1497 When a \environ{Picture} environment starts,
1498 highest label is set to \verb+\normalfont\normalsize$1$+
1499 (i.e., the high of a \emph{normal} $1$).
1500 \subsection{Alternatives to the \cs{multiput} command}
1501 The \package{xpicture} package introduces two families of commands
1502 to generalize the \cs{multiput} command:
1503 \begin{enumerate}
1504 \item The natural generalization, with all versions,
1505 \ttslashindex{multiPut}\ttslashindex{multicPut}\ttslashindex{multirPut}
1506 \begin{Verbatim}[commandchars=\|\{\},commentchar=\%]
1507 \multiPut[|TIT{position}](|TIT{x0},|TIT{y0})(|TIT{|(|Delta|)x},%
1508 |TIT{|(|Delta|)y})|{|TIT{n}|}|{|TIT{object}|}
1509 \multiPut*[|TIT{position}](|TIT{x0},|TIT{y0})(|TIT{|(|Delta|)x}%
1510 ,|TIT{|(|Delta|)y})|{|TIT{n}|}|{|TIT{object}|}
1511 \multicPut|{|TIT{position}|}(|TIT{x0},|TIT{y0})(|TIT{|(|Delta|)x}%
1512 ,|TIT{|(|Delta|)y})|{|TIT{n}|}|{|TIT{object}|}
1513 \multirPut|{|TIT{position}|}(|TIT{x0},|TIT{y0})(|TIT{|(|Delta|)x}%
1514 ,|TIT{|(|Delta|)y})|{|TIT{n}|}|{|TIT{object}|}
1515 \multirPut*|{|TIT{position}|}(|TIT{x0},|TIT{y0})(|TIT{|(|Delta|)x}%
1516 ,|TIT{|(|Delta|)y})|{|TIT{n}|}|{|TIT{object}|}
1517 \end{Verbatim}
1518 These commands compose \TIT{n} copies of \TTT{\TIT{object}}
1519 in $(\TIT{x0},\TIT{y0})$, $(\TIT{x0}+\Delta x,\TIT{y0}+\Delta y)$,
1520 $(\TIT{x0}+2\Delta x,\TIT{y0}+2\Delta y)$,\ldots,
1521 $(\TIT{x0}+(\TIT n-1)\Delta x,\TIT{y0}+(\TIT n-1)\Delta y)$.
1522 \item A new command group,
1523 \ttslashindex{multiPlot}\ttslashindex{multicPlot}\ttslashindex{multirPlot}
1524 \begin{Verbatim}[commandchars=\|\{\},commentchar=\%]
1525 \multiPlot[|TIT{position}]|{|TIT{object}|}(|TIT{x0},|TIT{y0})(|TIT{x1},%
1526 |TIT{y1})...(|TIT{xn},|TIT{yn})
1527 \multiPlot*[|TIT{position}]|{|TIT{object}|}(|TIT{x0},|TIT{y0})(|TIT{x1},%
1528 |TIT{y1})...(|TIT{xn},|TIT{yn})
1529 \multicPlot|{|TIT{position}|}|{|TIT{object}|}(|TIT{x0},|TIT{y0})(|TIT{x1},%
1530 |TIT{y1})...(|TIT{xn},|TIT{yn})
1531 \multirPlot|{|TIT{position}|}|{|TIT{object}|}(|TIT{x0},|TIT{y0})(|TIT{x1},%
1532 |TIT{y1})...(|TIT{xn},|TIT{yn})
1533 \multirPlot*|{|TIT{position}|}|{|TIT{object}|}(|TIT{x0},|TIT{y0})(|TIT{x1},%
1534 |TIT{y1})...(|TIT{xn},|TIT{yn})
1535 \end{Verbatim}
1536 These commands compose the done object in several positions, that are freely
1537 entered as a list of coordinate pairs.
1538 \end{enumerate}
1539 \begin{exemple}
1540 \begin{center}
1541 \setlength{\unitlength}{1cm}
1542 \referencesystem(0,0)(1,-1)(1,1)
1543 \begin{Picture}(-2.5,-2.5)(2.5,2.5)
1544 \cartesiangrid(-2,-2)(2,2)
1545 \pictcolor{blue}
1546 \multiPut(-2,-2)(1,1){5}{\circle*{0.25}}
1547 \pictcolor{red}
1548 \multiPlot{\circle*{0.25}}(-1,-2)(2,1)(-2,2)
1549 \end{Picture}
1550 \end{center}
1551 \end{exemple}
1552 \begin{exemple}
1553 \begin{center}
1554 \setlength{\unitlength}{1cm}
1555 \referencesystem(0,0)(1,-1)(1,1)
1556 \begin{Picture}(-2.5,-2.5)(2.5,2.5)
1557 \cartesiangrid(-2,-2)(2,2)
1558 \pictcolor{blue}
1559 \multiPut[b](-2,-2)(1,1){5}{\circle*{0.25}}
1560 \pictcolor{red}
1561 \multiPlot[NE]{\circle*{0.25}}(-1,-2)(2,1)(-2,2)
1562 \end{Picture}
1563 \end{center}
1564 \end{exemple}
1565 \subsection{Alternatives to \cs{line} and \cs{vector}}
1566 \begin{description}
1567 \item[\csdef{xLINE}] This command draws line segments:
1568 \begin{Verbatim}[commandchars=\|\[\]]
1569 \xLINE(|TIT[x0],|TIT[y0])(|TIT[x1],|TIT[y1])
1570 \end{Verbatim}
1571 draws the line segment between the two points
1572 \verb+(+\TIT{x0}\verb+,+\TIT{y0}\verb+)+ and
1573 \verb+(+\TIT{x1}\verb+,+\TIT{y1}\verb+)+
1574 (Cartesian or polar coordinates, in the active reference system).
1575 This allows us to draw any segment in any direction.
1576 \item[\csdef{xVECTOR}, \csdef{xtrivVECTOR}] plot arrows:
1577 \begin{Verbatim}[commandchars=\|\[\]]
1578 \xVECTOR(|TIT[x0],|TIT[y0])(|TIT[x1],|TIT[y1])
1579 \xtrivVECTOR(|TIT[x0],|TIT[y0])(|TIT[x1],|TIT[y1])
1580 \end{Verbatim}
1581 draw an arrow between points
1582 \verb+(+\TIT{x0}\verb+,+\TIT{y0}\verb+)+ and
1583 \verb+(+\TIT{x1}\verb+,+\TIT{y1}\verb+)+.
1584 The \cs{xtrivVECTOR} command draw an arrow
1585 the end of which simply consists of a pair of segments
1586 (\setlength{\unitlength}{1cm}%
1587 \begin{Picture}(0,-0.1)(0.5,0.1)\xtrivVECTOR(0,0)(0.5,0)\end{Picture}).
1588 length and aperture of the end of arrow are controled by the instruction
1589 \ttslashindex{arrowsize}
1590 \begin{Verbatim}[commandchars=\|\[\]]
1591 \arrowsize{|TIT[xlen]}{|TIT[ylen]}
1592 \end{Verbatim}
1593 where the two parameters are non-negative numbers:
1594 the first one for the length (in points); second
1595 for the half of the aperture. Default is
1596 \begin{Verbatim}
1597 \arrowsize{5}{2}
1598 \end{Verbatim}
1599 \begin{exemple}
1600 \setlength{\unitlength}{0.75cm}
1601 \referencesystem(0,0)(1,0)(0.25,0.75)
1602 \begin{Picture}(-4.5,-4.5)(4.5,4.5)
1603 \cartesiangrid(-4,-4)(4,4)
1604 \thicklines
1605 \pictcolor{blue}
1606 \xLINE(-4,0)(1,4)
1607 \Put(1,-3){\xLINE(0,0)(3,2)}
1608 \pictcolor{red}
1609 \xtrivVECTOR(0,0)(2,3)
1610 \xtrivVECTOR(0,0)(2,0)
1611 \arrowsize{10}{4}
1612 \xtrivVECTOR(0,0)(-2,-1)
1613
1614 \pictcolor{magenta}
1615 \xVECTOR(-3,-3)(-3,3)
1616 \xVECTOR(-3,-3)(-2,-2)
1617 \end{Picture}
1618 \end{exemple}
1619 \item[\csdef{xline}, \csdef{xvector}, \csdef{xtrivvector}]
1620 draw lines and vectors using the standard \LaTeX{} syntax
1621 (but without any restriction in allowed parameters,
1622 that can be integer or decimal numbers, positive, negative or zero).
1623 \begin{Verbatim}[commandchars=\|\[\]]
1624 \xline(|TIT[x],|TIT[y]){|TIT[size]}
1625 \xvector(|TIT[x],|TIT[y]){|TIT[size]}
1626 \xtrivvector(|TIT[x],|TIT[y]){|TIT[size]}
1627 \end{Verbatim}
1628 \begin{exemple}
1629 \setlength{\unitlength}{0.75cm}
1630 \referencesystem(0,0)(1,0)(0.25,0.75)
1631 \begin{Picture}(-4.5,-4.5)(4.5,4.5)
1632 \cartesiangrid(-4,-4)(4,4)
1633 \thicklines
1634 \pictcolor{blue}
1635 \Put(-4,0){\xline(5,4){5}}
1636 \Put(1,-3){\xline(3,2){3}}
1637 \pictcolor{red}
1638 \Put(0,0){\xtrivvector(2,3){2}}
1639 \xtrivvector(1,0){2}
1640 \arrowsize{10}{4}
1641 \Put(0,0){\xtrivvector(2,1){-2}}
1642
1643 \pictcolor{magenta}
1644 \Put(-3,-3){\xvector(0,1){6}}
1645 \Put(-3,-3){\xvector(1,1){1}}
1646 \end{Picture}
1647 \end{exemple}
1648
1649 If you want to draw only an arrowhead (without any line)
1650 you can use either the
1651 \csdef{zerovector}/\csdef{zerotrivvector}
1652 or \cs{xvector}/\cs{xtrivvector} commands:
1653 \begin{Verbatim}[commandchars=\|\[\]]
1654 \zerovector(|TIT[x],|TIT[y])
1655 \zerotrivvector(|TIT[x],|TIT[y])
1656 \xvector(|TIT[x],|TIT[y]){0}
1657 \xtrivvector(|TIT[x],|TIT[y]){0}
1658 \end{Verbatim}
1659 \end{description}
1660 \subsection{Polygons anf polygonal lines}
1661 The \package{pict2e} and \package{curve2e} packages include
1662 specific instructions for drawing polygonal lines and polygons.
1663 We introduce new versions of these
1664 commands in order to refer to the active reference system.
1665 \begin{description}
1666 \item[\csdef{Polyline}] draws polygonal lines.
1667 Logically, we must pass the list of vertices:
1668 \begin{Verbatim}[commandchars=\|\[\]]
1669 \Polyline(|TIT[x0],|TIT[y0])(|TIT[x1],|TIT[y1])...(|TIT[xn],|TIT[yn])
1670 \end{Verbatim}
1671 \item[\csdef{Polygon}] plots polygons, ie, closed polygonal lines:
1672 \begin{Verbatim}[commandchars=\|\[\]]
1673 \Polygon(|TIT[x0],|TIT[y0])(|TIT[x1],|TIT[y1])...(|TIT[xn],|TIT[yn])
1674 \end{Verbatim}
1675 is equivalent to
1676 \begin{Verbatim}[commandchars=\|\[\],commentchar=\%]
1677 \Polyline(|TIT[x0],|TIT[y0])(|TIT[x1],|TIT[y1])...(|TIT[xn],|TIT[yn])%
1678 (|TIT[x0],|TIT[y0])
1679 \end{Verbatim}
1680
1681 \begin{exemple}
1682 \setlength{\unitlength}{0.75cm}
1683 \referencesystem(0,0)(1,0)(0.25,0.75)
1684 \begin{Picture}(-4.5,-4.5)(4.5,4.5)
1685 \externalaxes
1686 \cartesiangrid(-4,-4)(4,4)
1687 \linethickness{1pt}
1688 \pictcolor{blue}
1689 \Polyline(-2,2)(-3,-1)(0,0)(2,3)(2,2)
1690 \pictcolor{red}
1691 \Polygon(0,0)(1,1)(3,1)(1,-1)
1692 \end{Picture}
1693 \end{exemple}
1694 \item[\csdef{regularPolygon}] draws regular polygons:
1695 \begin{Verbatim}[commandchars=\|\(\)]
1696 \regularPolygon[|TIT(initial angle)]{|TIT(radius)}{|TIT(sides)}
1697 \end{Verbatim}
1698 makes the regular polygon with the given radius and sides.
1699 The optional argument (zero, by default) determines
1700 the slope of the first vertex, always measured in degrees.
1701 \begin{exemple}
1702 \begin{center}
1703 \setlength{\unitlength}{0.5cm}
1704 \begin{Picture}(-7.5,-7.5)(7.5,7.5)
1705 \externalaxes
1706 \cartesiangrid(-7,-7)(7,7)
1707 \pictcolor{blue}
1708 \regularPolygon{1}{5}
1709 \Put(-4,0){\regularPolygon{2}{6}}
1710 \Put(3,3){\regularPolygon{2}{4}}
1711 \Put(-4,-4){\regularPolygon[45]{2}{4}}
1712 \Put(4,-4){\regularPolygon[90]{2.5}{11}}
1713 \Put(-4,4){\regularPolygon[90]{3}{3}}
1714 \end{Picture}
1715 \end{center}
1716 \end{exemple}
1717
1718 \end{description}
1719 \section{Drawing curves}
1720 This section highlights the true potentiality of the \package{xpicture}
1721 package.
1722 We will describe the instructions that can be used to easily (and effectively)
1723 represent
1724 several interesting curves: Firstly, conic sections and arcs.
1725 Then, any piecewise regular curve
1726 (including graphs of real variable functions, in rectangular or polar
1727 coordinates,
1728 and ---in a more general way--- curves defined by parametric equations).
1729 \subsection{Conic sections}
1730 The \package{xpicture} package defines new commands to draw conic sections:
1731 ellipses, circles, hyperbolas and parabolas.
1732 \subsubsection{Circles}
1733 We can draw the circle of implicit equation $x^2+y^2=r^2$ typing
1734 \ttslashindex{Circle}
1735 \begin{Verbatim}[commandchars=\|\[\]]
1736 \Circle{|TIT[r]}
1737 \end{Verbatim}
1738 Note than the standard command \cs{circle}
1739 requeres the diameter as mandatory argument, while here we must insert the
1740 radius.
1741 \subsubsection{Ellipses}
1742 To draw the ellipse $\displaystyle\frac{x^2}{a^2}+\frac{y^2}{b^2}=1$ enter the
1743 following instruction:\ttslashindex{Ellipse}
1744 \begin{Verbatim}[commandchars=\|\[\]]
1745 \Ellipse{|TIT[a]}{|TIT[b]}
1746 \end{Verbatim}
1747 \begin{exemple}
1748 \setlength{\unitlength}{0.5cm}
1749 \renewcommand{\axeslabelsize}{\footnotesize}
1750 \begin{Picture}(-5.5,-4.5)(5.5,4.5)
1751 \cartesiangrid(-5,-4)(5,4)
1752 \pictcolor{blue}
1753 \Ellipse{4}{3}
1754 \Circle{2}
1755 \end{Picture}
1756
1757 \referencesystem(0,0)(1,0)(0.5,0.5)
1758 \begin{Picture}(-5.5,-4.5)(5.5,4.5)
1759 \cartesiangrid(-5,-4)(5,4)
1760 \pictcolor{blue}
1761 \Ellipse{4}{3}
1762 \Circle{2}
1763 \end{Picture}
1764 \end{exemple}
1765 \subsubsection{Hyperbolas}
1766 Since the hyperbolas and parabolas are not bounded curves, to define the
1767 portion of the curve that we want to draw we need to specify the
1768 maximum values for the $x$ and $y$ variables.\ttslashindex{Hyperbola}
1769 \begin{Verbatim}[commandchars=\|\[\]]
1770 \Hyperbola{|TIT[a]}{|TIT[b]}{|TIT[xmax]}{|TIT[ymax]}
1771 \end{Verbatim}
1772 draws the hyperbola
1773 $\displaystyle\frac{x^2}{a^2}-\frac{y^2}{b^2}=1$,
1774 where variables $x$ and $y$ are limited, respectively,
1775 to the $\TTT{[-\TIT{xmax}}, \TTT{\TIT{xmax}]}$ and
1776 $\TTT{[-\TIT{ymax}}, \TTT{\TIT{ymax}]}$ intervals.
1777 This curve is well defined if the parameter \TTT{\TIT{xmax}}
1778 is greater than \TTT{\TIT{a}}. Otherwise, \package{xpicture} returns an error
1779 message and does not draw any curve.
1780
1781 In the following example, we show the hyperbola
1782 $\displaystyle\frac{x^2}{5^2}-\frac{y^2}{2^2}=1$
1783 and its asymptotes,
1784 using the \cs{xLINE} command (these asymptotes are lines $2x=\pm5y$,
1785 passing through $(\pm16,\pm6.4)$).
1786 \begin{Exemple}
1787 \begin{center}
1788 \setlength{\unitlength}{0.5cm}
1789 \begin{Picture}(-17,-9)(17,9)
1790 \renewcommand{\axeslabelsize}{\footnotesize}
1791 \cartesiangrid(-16,-8)(16,8)
1792 \pictcolor{blue}
1793 \Hyperbola{5}{2}{16}{8}
1794 \pictcolor{orange}
1795 \xLINE(16,6.4)(-16,-6.4)
1796 \xLINE(-16,6.4)(16,-6.4)
1797 \end{Picture}
1798 \end{center}
1799 \end{Exemple}
1800
1801 Instructions \csdef{lHyperbola} and \csdef{rHyperbola} draw, respectively,
1802 only the \emph{left} or only the \emph{right} branch of the given hyperbola
1803 (here, is interpreted as \emph{right} branch this one that belongs to positive
1804 values of variable $x$).
1805 \begin{exemple}
1806 \begin{center}
1807 \setlength{\unitlength}{0.5cm}
1808 \begin{Picture}(-5.5,-5.5)(5.5,5.5)
1809 \renewcommand{\axeslabelsize}{\footnotesize}
1810 \cartesiangrid(-5,-5)(5,5)
1811 \pictcolor{red}
1812 \lHyperbola{2}{3}{5}{5}
1813 \pictcolor{blue}
1814 \rHyperbola{2}{3}{5}{5}
1815 \end{Picture}
1816 \end{center}
1817 \end{exemple}
1818 \subsubsection{Parabolas}
1819 Instruction\ttslashindex{Parabola}
1820 \begin{Verbatim}[commandchars=\|\[\]]
1821 \Parabola{|TIT[a]}{|TIT[xmax]}{|TIT[ymax]}
1822 \end{Verbatim}
1823 draw the parabola $x=ay^2$, varying $x$, at most, in the interval
1824 $[0,\TTT{\TIT{xmax}}]$
1825 (if \TTT{\TIT{a}} is positive) or in $[-\TTT{\TIT{xmax}},0]$
1826 (for negative values of \TTT{\TIT{a}}),
1827 and $y$ in $[-\TTT{\TIT{ymax}},\TTT{\TIT{ymax}}]$.
1828 Parameters \TTT{\TIT{xmax}} and \TTT{\TIT{ymax}}
1829 must be positive.
1830 \begin{exemple}
1831 \begin{center}
1832 \setlength{\unitlength}{0.5cm}
1833 \begin{Picture}(-5.5,-5.5)(5.5,5.5)
1834 \cartesiangrid(-5,-5)(5,5)
1835 \pictcolor{blue}
1836 \Parabola{2}{5}{5}
1837 \Parabola{0.2}{5}{5}
1838 \pictcolor{orange}
1839 \Parabola{-2}{5}{5}
1840 \Parabola{-0.2}{5}{5}
1841 \end{Picture}
1842 \end{center}
1843 \end{exemple}
1844 \medskip
1845
1846 All commands drawing conic sections or arcs divide the curve in
1847 \csdef{defaultplotdivs} pieces (8, by default). To obtain a greather
1848 accuracy, you can redefine this parameter.
1849
1850 \medskip
1851
1852 Note that all these commands draw conic sections centered
1853 at the coordinate origin, so that their
1854 principal axes coincide with the coordinate axes. If we
1855 want to move his
1856 center to any other point, we can do it moving in advance
1857 the origin of coordinates or simply
1858 including the command as an argument of the \cs{Put} command.
1859 \begin{Exemple}
1860 \begin{center}
1861 \setlength{\unitlength}{0.5cm}
1862 \begin{Picture}(-11,-8)(11,8)
1863 \renewcommand{\axeslabelsize}{\footnotesize}
1864 \cartesiangrid(-10,-7)(11,7)
1865 \pictcolor{blue}
1866 \Put(2,3){\Ellipse{4}{3}}
1867 \Put(2,3){\Circle{0.25}}
1868 \pictcolor{orange}
1869 \Put(2,-3){\Hyperbola{5}{2}{9}{3}}
1870 \Put(2,-3){\Circle{0.25}}
1871 \pictcolor{green}
1872 \translateorigin(-10,2)
1873 \Parabola{0.5}{21}{5}
1874 \Circle{0.25}
1875 \end{Picture}
1876 \end{center}
1877 \end{Exemple}
1878 But, if the symmetry axes of our curve are not parallel to the coordinate
1879 axes,\footnote{That is, in mathematical terms,
1880 if the eigenvectors of the underlying quadratic form are not the canonical
1881 vectors.}
1882 then we will need a rotation of axes.
1883 \begin{Exemple}
1884 \setlength{\unitlength}{0.5cm}
1885 \begin{center}
1886 \begin{Picture}(-10.5,-7.5)(10.5,7.5)
1887 \renewcommand{\axeslabelsize}{\footnotesize}
1888 \cartesiangrid(-10,-7)(10,7)
1889 {%
1890 \pictcolor{blue}
1891 \translateorigin(5,3)
1892 \rotateaxes{\numberSIXTHPI}
1893 \Ellipse{4}{3}
1894 \xLINE(-4,0)(4,0)
1895 \xLINE(0,-3)(0,3)
1896 }
1897 \degreesangles
1898 {%
1899 \pictcolor{orange}
1900 \translateorigin(-3,0)
1901 \rotateaxes{110}
1902 \Hyperbola{3}{2}{6}{4}
1903 \xLINE(-6,-4)(6,4)
1904 \xLINE(6,-4)(-6,4)
1905 }
1906 \pictcolor{green}
1907 \translateorigin(5,-6)
1908 \rotateaxes{72}
1909 \Parabola{1}{4}{3}
1910 \xLINE(0,-2)(0,2)
1911 \xLINE(0,0)(4,0)
1912 \end{Picture}
1913 \end{center}
1914 \end{Exemple}
1915 Note that we made a couple of changes of local reference system (one for each
1916 curve) within the drawing.
1917 We can use the recourse to the change of coordinates also to
1918 draw the hyperbola $\displaystyle\frac{y^2}{a^2}-\frac{x^2}{b^2}=1$ and the
1919 parabola $y=ax^2$.
1920 Note than \verb+\referencesystem(0,0)(0,1)(1,0)+
1921 (or \verb+\symmetrize{\numberQUARTERPI}+)
1922 makes vertical the $x$ axis and horizontal the
1923 $y$ axis.\footnote{We will use this trick later
1924 to plot inverse functions.}
1925 \begin{exemple}
1926 \setlength{\unitlength}{0.5cm}
1927 \begin{center}
1928 \begin{Picture}(-5.5,-5.5)(5.5,5,5)
1929 \renewcommand{\axeslabelsize}{\footnotesize}
1930 \cartesiangrid(-5,-5)(5,5)
1931 \referencesystem(0,0)(0,1)(1,0)
1932 \pictcolor{blue}
1933 \Parabola{0.22}{5}{5}
1934 \pictcolor{red}
1935 \Hyperbola{2}{3}{5}{5}
1936 \end{Picture}
1937 \end{center}
1938 \end{exemple}
1939
1940 \subsection{Arcs (of conic sections)}
1941 The instructions described above allow us to draw whole circles, ellipses
1942 hyperbolas and parabolas. More generally, we can represent any portion of
1943 these curves, ie, circular, elliptic, hyperbolic and parabolic arcs.
1944 \ttslashindex{xArc}\ttslashindex{circularArc}
1945 \begin{Verbatim}[commandchars=\|\[\]]
1946 \xArc{|TIT[r]}{|TIT[angle1]}{|TIT[angle2]}
1947 \circularArc{|TIT[r]}{|TIT[angle1]}{|TIT[angle2]}
1948 \end{Verbatim}
1949 These two instructions are equivalent.
1950 They draw the arc of the circle centered at $(0,0)$
1951 with radius $\TIT{r}$
1952 and limited by the $\TTT{\TIT{angle1}}$ and $\TTT{\TIT{angle2}}$
1953 angles.
1954 \begin{exemple}
1955 \setlength{\unitlength}{0.5cm}
1956 \begin{center}
1957 \begin{Picture}(-5.5,-5.5)(5.5,5,5)
1958 \renewcommand{\axeslabelsize}{\footnotesize}
1959 \cartesianaxes(-5,-5)(5,5)
1960 \pictcolor{gray}
1961 \circularArc{3}{\numberPI}{\numberTWOPI}
1962 \pictcolor{red}
1963 \xLINE(-2,2)(-2,5)
1964 \xLINE(-2,2)(-5,2)
1965 \degreesangles
1966 \Put(-2,2){\circularArc{1}{90}{180}}
1967 \pictcolor{blue}
1968 \polarreference
1969 \Put(1,30){\xLINE(0,0)(4,30)}
1970 \Put(1,30){\xLINE(0,0)(4,60)}
1971 \Put(1,30){\circularArc{2}{30}{60}}
1972 \end{Picture}
1973 \end{center}
1974 \end{exemple}
1975 \begin{exemple}
1976 \SUBTRACT{\numberGOLD}{1}{\midaB}
1977 \COPY{1}{\midaA}
1978 \ADD{\midaA}{\midaB}{\Mida}
1979 \setlength{\unitlength}{5cm}
1980 \newcommand{\espiral}{%
1981 \Put(0,0){\begin{Picture}(0,0)(0,0)
1982 \translateorigin(\midaA,0)
1983 \pictcolor{red}
1984 \circularArc{\midaA}{\numberHALFPI}{\numberPI}
1985 \pictcolor{blue}
1986 \xLINE(0,0)(0,\midaA)
1987 \end{Picture}
1988 }
1989 \COPY{\midaA}{\Mida}
1990 \COPY{\midaB}{\midaA}
1991 \SUBTRACT{\Mida}{\midaA}{\midaB}
1992 \translateorigin(\Mida,\midaB)
1993 \changereferencesystem(0,\midaA)(0,-1)(1,0)
1994 }
1995 \renewcommand{\defaultplotdivs}{2}
1996
1997 \begin{center}
1998 \begin{Picture}(0,0)(\numberGOLD,1)
1999 \Polygon(0,0)(\Mida,0)(\Mida,1)(0,1)
2000 % Plot 8 circular arcs
2001 \espiral\espiral\espiral\espiral
2002 \espiral\espiral\espiral\espiral
2003 \end{Picture}
2004
2005 Golden rectangles and spiral
2006 \end{center}
2007 \end{exemple}
2008 \ttslashindex{ellipticArc}
2009 \begin{Verbatim}[commandchars=\|\[\]]
2010 \ellipticArc{|TIT[a]}{|TIT[b]}{|TIT[angle1]}{|TIT[angle2]}
2011 \end{Verbatim}
2012 This instruction draws the arc of the ellipse centered at
2013 $(0,0)$ with semiaxes $\TIT{a}$
2014 and $\TIT{b}$, $\frac{x^2}{a^2}+\frac{y^2}{b^2}=1$,
2015 limited by angles $\TTT{\TIT{angle1}}$ and $\TTT{\TIT{angle2}}$.
2016 \begin{exemple}
2017 \setlength{\unitlength}{0.5cm}
2018 \begin{center}
2019 \begin{Picture}(-0.5,-3.5)(5.5,3.5)
2020 \degreesangles
2021 \ellipticArc{2}{3}{-90}{90}
2022 \ellipticArc{5}{3}{-90}{90}
2023 \end{Picture}
2024 \end{center}
2025 \end{exemple}
2026 \ttslashindex{lhyperbolicArc}\ttslashindex{rhyperbolicArc}
2027 \begin{Verbatim}[commandchars=\|\[\]]
2028 \rhyperbolicArc{|TIT[a]}{|TIT[b]}{|TIT[y1]}{|TIT[y2]}
2029 \lhyperbolicArc{|TIT[a]}{|TIT[b]}{|TIT[y1]}{|TIT[y2]}
2030 \end{Verbatim}
2031 Draw the arc (of the right or left branch, respectively)
2032 of the hyperbola
2033 $\frac{x^2}{a^2}-\frac{y^2}{b^2}=1$ included between $y=\TTT{\TIT{y1}}$ and
2034 $y=\TTT{\TIT{y2}}$.
2035 \begin{exemple}
2036 \setlength{\unitlength}{0.5cm}
2037 \begin{center}
2038 \begin{Picture}(-5.5,-5.5)(5.5,5,5)
2039 \renewcommand{\axeslabelsize}{\footnotesize}
2040 \cartesianaxes(-5,-5)(5,5)
2041 \pictcolor{red}
2042 \lhyperbolicArc{2}{3}{-4}{0}
2043 \pictcolor{blue}
2044 \rhyperbolicArc{2}{3}{-2}{5}
2045 \end{Picture}
2046 \end{center}
2047 \end{exemple}
2048 \ttslashindex{parabolicArc}
2049 \begin{Verbatim}[commandchars=\|\[\]]
2050 \parabolicArc{|TIT[a]}{|TIT[y1]}{|TIT[y2]}
2051 \end{Verbatim}
2052 Draw the arc of the parabola
2053 $x=ay^2$ included between $y=\TTT{\TIT{y1}}$ and $y=\TTT{\TIT{y2}}$.
2054 \begin{exemple}
2055 \setlength{\unitlength}{1cm}
2056 \begin{center}
2057 \begin{Picture}(-2.5,-2.5)(2.5,2,5)
2058 \renewcommand{\axeslabelsize}{\footnotesize}
2059 \cartesianaxes(-2,-2)(2,2)
2060 \pictcolor{red}
2061 \parabolicArc{-2}{-1}{0}
2062 \pictcolor{blue}
2063 \parabolicArc{0.5}{0}{2}
2064 \end{Picture}
2065 \end{center}
2066 \end{exemple}
2067 \subsection{Real variable functions}\label{subsec:real}
2068 The \package{xpicture} package provides us two commands
2069 to draw the graph of a function:
2070 \csdef{PlotFunction} and \csdef{PlotPointsOfFunction}.
2071 \begin{Verbatim}[commandchars=\|\(\)]
2072 \PlotFunction[|TIT(n)]{\|TIT(functionname)}{\|TIT(tzero)}{\|TIT(tone)}
2073 \PlotPointsOfFunction{|TIT(n)}{\|TIT(functionname)}{\|TIT(tzero)}{\|TIT(tone)}
2074 \end{Verbatim}
2075 Note that the parameter $\TTT{\TIT{n}}$ is optional in one of these
2076 instructions and mandatory in the other one.
2077 In the case of \csdef{PlotFunction},
2078 if we do not use this optional parameter,
2079 a quadratic approximation of the function
2080 \cs{\TIT{functionname}}
2081 in the $[\cs{\TIT{tzero}},\cs{\TIT{tone}}]$ interval is drawn.
2082 \begin{exemple}
2083 \setlength{\unitlength}{1cm}
2084 \begin{Picture}(-2.5,-0.5)(3.5,4.5)
2085 \cartesianaxes(-2,0)(2,4)
2086 \pictcolor{blue}
2087 \PlotFunction{\SQUAREfunction}{-2}{2}
2088 \Put[E](2,4){$f(t)=t^2$}
2089 \end{Picture}
2090 \end{exemple}
2091 Now, this almost never provides a right graphic.
2092 To draw curves with a greater accuracy we should use the parameter,
2093 \TTT{\TIT{n}},
2094 dividing the interval in \TTT{\TIT{n}} subintervals.
2095 \begin{exemple}
2096 \setlength{\unitlength}{1cm}
2097 \CUBE{1.5}{\mymax}
2098 \begin{Picture}(-2,-4)(2,4)
2099 \cartesianaxes(-1.5,-\mymax)(1.5,\mymax)
2100 \pictcolor{blue}
2101 \PlotFunction[8]{\CUBEfunction}{-1.5}{1.5}
2102 \Put[E](1.5,\mymax){$f(t)=t^3$}
2103 \end{Picture}
2104 \end{exemple}
2105
2106 On the other hand, the \csdef{PlotPointsOfFunction} command
2107 plots $\TTT{\TIT{n}}+1$ \emph{points}, uniformly distributed
2108 about the $x$-axis.
2109 \begin{exemple}
2110 \setlength{\unitlength}{1cm}
2111 \CUBE{1.5}{\mymax}
2112 \begin{Picture}(-2,-4)(2,4)
2113 \cartesianaxes(-1.5,-\mymax)(1.5,\mymax)
2114 \pictcolor{blue}
2115 \PlotPointsOfFunction{24}{\CUBEfunction}{-1.5}{1.5}
2116 \Put[E](1.5,\mymax){$f(t)=t^3$}
2117 \end{Picture}
2118 \end{exemple}
2119
2120 By default, \cs{PlotPointsOfFunction} plot \emph{points} as a filled circle
2121 of diameter \verb+0.1\unitlength+. But you can modifie this diameter, by
2122 redefining the \csdef{pointmarkdiam} parameter.
2123 \begin{exemple}
2124 \setlength{\unitlength}{1cm}
2125 \CUBE{1.5}{\mymax}
2126 \renewcommand{\pointmarkdiam}{0.3}
2127 \begin{Picture}(-2,-4)(2,4)
2128 \cartesianaxes(-1.5,-\mymax)(1.5,\mymax)
2129 \pictcolor{blue}
2130 \PlotPointsOfFunction{24}{\CUBEfunction}{-1.5}{1.5}
2131 \Put[E](1.5,\mymax){$f(t)=t^3$}
2132 \end{Picture}
2133 \end{exemple}
2134
2135 Moreover, you can select another symbol for these points, redefining
2136 \csdef{pointmark}.
2137 \begin{exemple}
2138 \setlength{\unitlength}{1cm}
2139 \CUBE{1.5}{\mymax}
2140 \renewcommand{\pointmark}{$\diamond$}
2141 \begin{Picture}(-2,-4)(2,4)
2142 \cartesianaxes(-1.5,-\mymax)(1.5,\mymax)
2143 \pictcolor{blue}
2144 \PlotPointsOfFunction{24}{\CUBEfunction}{-1.5}{1.5}
2145 \Put[E](1.5,\mymax){$f(t)=t^3$}
2146 \end{Picture}
2147 \end{exemple}
2148
2149 Naturally, in order to apply these commands the function must be defined.
2150 \package{xpicture}
2151 loads the \packagedef{calculus} package, which
2152 predefines some of the most common elementary functions
2153 and includes several tools to build new ones.
2154 The predefined functions are the following:
2155 \begin{center}
2156 \begin{tabular}{l>{$}l<{$}>{\qquad}l>{$}l<{$}}
2157 \csdef{ZEROfunction} & f(t)=0 &
2158 \csdef{ONEfunction} & f(t)=1 \\
2159 \csdef{IDENTITYfunction} & f(t)=t &
2160 \csdef{RECIPROCALfunction} & f(t)=1/t \\
2161 \csdef{SQUAREfunction} & f(t)=t^2 &
2162 \csdef{CUBEfunction} & f(t)=t^3 \\
2163 \csdef{SQRTfunction} & f(t)=\sqrt t \\
2164 \csdef{EXPfunction} & f(t)=\exp t &
2165 \csdef{LOGfunction} & f(t)=\log t \\
2166 \csdef{COSfunction} & f(t)=\cos t &
2167 \csdef{SINfunction} & f(t)=\sin t \\
2168 \csdef{TANfunction} & f(t)=\tan t &
2169 \csdef{COTfunction} & f(t)=\cot t \\
2170 \csdef{COSHfunction} & f(t)=\cosh t &
2171 \csdef{SINHfunction} & f(t)=\sinh t \\
2172 \csdef{TANHfunction} & f(t)=\tanh t &
2173 \csdef{COTHfunction} & f(t)=\coth t \\
2174 \csdef{HEAVISIDEfunction} & f(t)=\begin{cases}
2175 0 & \text{si $t<0$} \\
2176 1 & \text{si $t\geq0$}
2177 \end{cases}
2178 \end{tabular}
2179 \end{center}
2180
2181 \begin{Exemple}
2182 \setlength{\unitlength}{1cm}
2183 \linethickness{1.5pt}
2184 \centering
2185 \begin{Picture}(-5,-5)(6,5)
2186 \externalaxes\makenotics
2187 \cartesiangrid(-4.5,-4.5)(4.5,4.5)
2188 \pictcolor{red}
2189 \PlotFunction{\IDENTITYfunction}{-4.5}{4.5}
2190 \Put[tr](4.5,4.5){$y=x$}
2191
2192 \DIVIDE{1}{4.5}{\minx}
2193 \pictcolor{magenta}
2194 \PlotFunction[10]{\RECIPROCALfunction}{\minx}{4.5}
2195 \PlotFunction[10]{\RECIPROCALfunction}{-\minx}{-4.5}
2196 \Put[r](4.5,\minx){$y=1/x$}
2197
2198 \SQRT{4.5}{\maxx}
2199 \pictcolor{cyan}
2200 \PlotFunction[10]{\SQUAREfunction}{-\maxx}{\maxx}
2201 \Put[tr](\maxx,4.5){$y=x^2$}
2202
2203 \pictcolor{blue}
2204 \PlotFunction[10]{\CUBEfunction}{-1.6509}{1.6509}
2205 \Put[t](1.6509,4.5){$y=x^3$}
2206 \end{Picture}
2207 \end{Exemple}
2208
2209 \begin{Exemple}
2210 \setlength{\unitlength}{1cm}
2211 \linethickness{1.5pt}
2212 \centering
2213 \begin{Picture}(-7,-4.5)(7,4.5)
2214 {\makenolabels
2215 \changereferencesystem(0,0)(\numberHALFPI,0)(0,1)
2216 \cartesiangrid(-4,-4)(4,4)
2217 \highestlabel{$2\pi$}
2218 \printylabels{-4}{1}{4}
2219 \printxlabel{-4}{-2\pi}
2220 \printxlabel{-2}{-\pi}
2221 \printxlabel{2}{\pi}
2222 \printxlabel{4}{2\pi}}
2223 \pictcolor{red}
2224 \PlotFunction[16]{\COSfunction}{-\numberTWOPI}{\numberTWOPI}
2225 \pictcolor{blue}
2226 \PlotFunction[16]{\SINfunction}{-\numberTWOPI}{\numberTWOPI}
2227 \pictcolor{magenta}
2228 \PlotFunction[6]{\TANfunction}{-1.3258}{1.3258}
2229 \end{Picture}
2230 \end{Exemple}
2231
2232 From these basic functions we can define many others,
2233 using the following \emph{operations}:
2234 \newcommand{\functoper}{%
2235 \{\cs{\TIT{function1}}\}\{\cs{\TIT{function2}}\}\{\cs{\TIT{newfunction}}\}}
2236 \begin{description}
2237 \item[Constant function:]\mbox{}
2238
2239 \csdef{CONSTANTfunction}\{\TIT{k}\}\{\cs{\TIT{newfunction}}\}
2240
2241 Example: defining the $F(t)=5$ function:
2242
2243 \cs{CONSTANTfunction}\{5\}\{\cs{F}\}
2244
2245 \item[Sum function:]\mbox{}
2246
2247 \csdef{SUMfunction}\functoper
2248
2249
2250 Example: defining the $F(t)=t^2+t^3$ function:
2251
2252 \cs{SUMfunction}\{\cs{SQUAREfunction}\}\{\cs{CUBEfunction}\}\{\cs{F}\}
2253
2254 \item[Difference function:]\mbox{}
2255
2256 \csdef{SUBTRACTfunction}\functoper
2257
2258 Example: defining the $F(t)=t^2-t^3$ function:
2259
2260 \cs{SUBTRACTfunction}\cs{SQUAREfunction}\cs{CUBEfunction}\{\cs{F}\}
2261
2262 \item[Product function:]\mbox{}
2263
2264 \csdef{PRODUCTfunction}\functoper
2265
2266 Example: defining the $F(t)=\mathrm e^t\cos t$ function:
2267
2268 \cs{PRODUCTfunction}\cs{EXPfunction}\cs{COSfunction}\{\cs{F}\}
2269
2270 \item[Quotient function:]\mbox{}
2271
2272 \csdef{QUOTIENTfunction}\functoper
2273
2274 Example: defining the $F(t)=\mathrm e^t/\cos t$ function:
2275
2276 \cs{QUOTIENTfunction}\cs{EXPfunction}\cs{COSfunction}\{\cs{F}\}
2277
2278 \item[Composition of two functions:]\mbox{}
2279
2280 \csdef{COMPOSITIONfunction}\functoper
2281
2282 Example: defining the $F(t)=\mathrm e^{\cos t}$ function:
2283
2284 \cs{COMPOSITIONfunction}\cs{EXPfunction}\cs{COSfunction}\{\cs{F}\}
2285
2286 \item[Scaled function:]\mbox{}
2287
2288 \csdef{SCALEfunction}\{\TIT{k}\}\{\cs{\TIT{function}}\}%
2289 \{\cs{\TIT{newfunction}}\}
2290
2291 Example: defining the $F(t)=3{\cos t}$ function:
2292
2293 \cs{SCALEfunction}\{3\}\cs{COSfunction}\{\cs{F}\}
2294
2295 \item[Scaled variable:]\mbox{}
2296
2297 \csdef{SCALEVARIABLEfunction}\{\TIT{k}\}\{\cs{\TIT{function}}\}%
2298 \{\cs{\TIT{newfunction}}\}
2299
2300 Example: defining the $F(t)=\cos 3t$ function:
2301
2302 \cs{SCALEVARIABLEfunction}\{3\}\cs{COSfunction}\{\cs{F}\}
2303
2304 \item[Power function:] (exponent enter positiu)\mbox{}
2305
2306 \csdef{POWERfunction}\{\cs{\TIT{function}}\}\{\TIT{n}\}%
2307 \{\cs{\TIT{newfunction}}\}
2308
2309 Example: defining the $F(t)=t^5$ function:
2310
2311 \cs{POWERfunction}\cs{IDENTITYfunction}\{5\}\{\cs{F}\}
2312
2313 \item[Linear combination:]\mbox{}
2314
2315 \csdef{LINEARCOMBINATIONfunction}\{\TIT{a}\}\{\cs{\TIT{function1}}\}%
2316 \{\TIT{b}\}\{\cs{\TIT{function2}}\}\{\cs{\TIT{newfunction}}\}
2317
2318 Example: defining the $F(t)=2t-3\cos t$ function:
2319
2320 \cs{LINEARCOMBINATIONfunction}\{2\}\cs{IDENTITYfunction}\{-3\}%
2321 \cs{COSfunction}\{\cs{F}\}
2322 \end{description}
2323
2324 By combining properly these operations, we can draw graphs of many functions.
2325 Some examples are shown in next pages.
2326 \newpage
2327
2328 First, we will draw the function $f(t)=t^3-2t$,
2329 dividing the interval $[-2,2]$ in ten subintervals.
2330 The simplest way to construct this function is as a linear combination of
2331 $f_1(t)=t^3$ and $f_2(t)=t$.
2332
2333 \begin{exemple}
2334 \LINEARCOMBINATIONfunction
2335 {1}{\CUBEfunction}
2336 {-2}{\IDENTITYfunction}
2337 {\Ffunction}
2338 \begin{center}
2339 \setlength{\unitlength}{1cm}
2340 \begin{Picture}(-2.5,-4.5)(2.5,4.5)
2341 \cartesianaxes(-2,-4)(2,4)
2342 \pictcolor{blue}
2343 \PlotFunction[10]{\Ffunction}{-2}{2}
2344 \Put[rbr](2,4){$f(t)=t^3-2t$}
2345 \end{Picture}
2346 \end{center}
2347 \end{exemple}
2348 \newpage
2349
2350 Graph of $g(t)=t\cos t$. We multiply the identity and the cosine functions:
2351
2352 \begin{Exemple}
2353 \setlength{\unitlength}{0.5cm}
2354 \begin{center}
2355 \begin{Picture}(-11,-11)(11,11)
2356 \cartesianaxes(-10,-10)(10,10)
2357 \PRODUCTfunction{\IDENTITYfunction}{\COSfunction}{\Gfunction}
2358 \pictcolor{red}
2359 \PlotFunction[30]{\Gfunction}{-10}{10}
2360 \end{Picture}
2361 \end{center}
2362 \end{Exemple}
2363 \newpage
2364
2365 Graph of $f(t)=(\cos t)^3$.
2366
2367 \begin{Exemple}
2368 \setlength{\unitlength}{1cm}
2369 \begin{center}
2370 \begin{Picture}(-7,-3)(7,3)
2371 \cartesianaxes(-\numberTWOPI,-2)(\numberTWOPI,2)
2372 \POWERfunction{\COSfunction}{3}{\Ffunction}
2373 \pictcolor{blue}
2374 \PlotFunction[50]{\Ffunction}{-\numberTWOPI}{\numberTWOPI}
2375 \end{Picture}
2376 \end{center}
2377 \end{Exemple}
2378 \newpage
2379
2380 Graph of $g(t)=t\cos t\sin t$.
2381 Note that in this case we have two operations:
2382 First, we define the $f(t)=t \cos t$, multiplying the identity and cosine
2383 functions; then, we multiply by the sine function.
2384 \begin{Exemple}
2385 \begin{center}
2386 \setlength{\unitlength}{0.75cm}
2387 \begin{Picture}(-11,-6)(11,6)
2388 \cartesianaxes(-10,-5)(10,5)
2389 \PRODUCTfunction{\IDENTITYfunction}{\COSfunction}{%
2390 \Ffunction}
2391 \PRODUCTfunction{\Ffunction}{\SINfunction}{\Gfunction}
2392 \pictcolor{red}
2393 \PlotFunction[40]{\Gfunction}{-10}{10}
2394 \end{Picture}
2395 \end{center}
2396 \end{Exemple}
2397
2398 Graph of $g(t)=\arcsin t$. The \package{calculus} package
2399 not support, for now, the inverse trigonometric functions; but we can plot
2400 these functions (or any other inverse function)
2401 swapping coordinated axes.
2402
2403 \begin{exemple}
2404 \begin{center}
2405 \setlength{\unitlength}{2cm}
2406 \begin{Picture}(-1.5,-2)(1.5,2)
2407 \makenolabels\makenotics
2408 \cartesianaxes
2409 (-1,-\numberHALFPI)(1,\numberHALFPI)
2410 \printxticslabels{-1}{0.5}{1}
2411 \printyticlabel{-\numberHALFPI}{-\pi/2}
2412 \printyticlabel{-\numberQUARTERPI}{-\pi/4}
2413 \printyticlabel{\numberQUARTERPI}{\pi/4}
2414 \printyticlabel{\numberHALFPI}{\pi/2}
2415 \pictcolor{red}
2416 \symmetrize{\numberQUARTERPI}
2417 \PlotFunction[4]{\SINfunction}
2418 {-\numberHALFPI}{\numberHALFPI}
2419 \end{Picture}
2420 \end{center}
2421 \end{exemple}
2422 \subsubsection{Polynomial functions}
2423 Although polynomial functions can be easily defined as
2424 linear combinations of power functions,
2425 to facilitate our work, the \package{calculus} package predefines
2426 polynomials of
2427 1, 2, and 3 degrees by these commands:
2428 \cs{newlpoly} (new \emph{linear} polynomial), \cs{newqpoly}
2429 (new \emph{quadratic} polynomial),
2430 and \cs{newcpoly} (new \emph{cubic} polynomial):
2431 \begin{description}
2432 \item[\csdef{newlpoly}\{\cs{\TIT{newfunction}}\}\{\TIT a\}\{\TIT b\}]
2433 stores the
2434 $p(t)=\TTT{\TIT{a}}+\TTT{\TIT{b}}t$
2435 function in the
2436 \cs{\TIT{newfunction}} command.
2437 \item[\csdef{newqpoly}%
2438 \{\cs{\TIT{newfunction}}\}\{\TIT a\}\{\TIT b\}\{\TIT c\}]
2439 stores the
2440 $p(t)=\TTT{\TIT{a}}+\TTT{\TIT{b}}t+\TTT{\TIT{c}}t^2$
2441 function in the
2442 \cs{\TIT{newfunction}} command.
2443 \item[\csdef{newcpoly}%
2444 \{\cs{\TIT{newfunction}}\}\{\TIT a\}\{\TIT b\}\{\TIT c\}\{\TIT d\}]
2445 stores the
2446 $p(t)=\TTT{\TIT{a}}+\TTT{\TIT{b}}t+\TTT{\TIT{c}}t^2+\TTT{\TIT{d}}t^3$
2447 function in the
2448 \cs{\TIT{newfunction}} command.
2449 \end{description}
2450 \begin{exemple}
2451 % F(t)=-1+2t
2452 \newlpoly{\poliF}{-1}{2}
2453 % G(t)=-1+2t+t^2
2454 \newqpoly{\poliG}{-1}{2}{1}
2455 % H(t)=-1+2t+t^2-0,5t^3
2456 \newcpoly{\poliH}{-1}{2}{1}{-0.5}
2457
2458 \setlength{\unitlength}{1cm}
2459 \begin{Picture}(-4.5,-5.5)(4.5,5.5)
2460 \cartesianaxes(-4,-5)(4,5)
2461 \pictcolor{blue}
2462 \PlotFunction{\poliF}{-2}{3}
2463 \pictcolor{red}
2464 \PlotFunction{\poliG}{-3.5}{1.5}
2465 \pictcolor{orange}
2466 \PlotFunction[10]{\poliH}{-2}{3.5}
2467 \end{Picture}
2468 \end{exemple}
2469
2470 \subsubsection{Possible errors}
2471 In many cases you get a fairly accurate graph dividing the domain into several
2472 subintervals.
2473 But an indiscriminate use of this method can produce erroneous results.
2474 For example, if inside a subinterval there is
2475 a discontinuity or a point where the function is not differentiable.
2476 Look at the following example.
2477 \medskip
2478
2479 \begin{exemple}
2480 \SUBTRACTfunction{\SQUAREfunction}{\ONEfunction}
2481 {\Ffunction}
2482 \QUOTIENTfunction{\IDENTITYfunction}{\Ffunction}
2483 {\Gfunction}
2484
2485 \setlength{\unitlength}{0.5cm}
2486
2487 \begin{Picture}(-8,-6)(8,6)
2488 \def\xunitdivisions{2}
2489 \def\yunitdivisions{2}
2490 \renewcommand{\axeslabelsize}{\scriptsize}
2491 \cartesianaxes(-7,-5)(7,5)
2492 \Put(3,3){%
2493 $\boxed{\displaystyle g(t)=\frac{t}{t^ 2-1}}$}
2494 \pictcolor{red}
2495 \PlotFunction[10]{\Gfunction}{-7}{7}
2496 \end{Picture}
2497 \end{exemple}
2498
2499 Where is the problem?
2500 Our function is $g(t)=t/(t^2-1)$;
2501 this function has a pair of vertical asymptotes
2502 at $t=\pm1$ (the two zeros of denominator).
2503
2504 We made 10 subdivisions of the $[-7,7]$ interval.
2505 Do, we compute the function in points $-7+(14/10)k=-7+(7/5)k$,
2506 $0\leq k\leq10$, ie,
2507 \[
2508 -7\quad -\frac{28}{5}\quad -\frac{21}{5}\quad -\frac{14}{5}\quad
2509 -\frac{7}{5}\quad 0\quad \frac{7}{5}\quad \frac{14}{5}\quad
2510 \frac{21}{5}\quad \frac{28}{5}\quad 7
2511 \]
2512
2513 Singularities are between $-7/5$ and $0$, and between $0$ and $7/5$,
2514 So, the graph is not correct in these intervals.
2515 \medskip
2516
2517 To avoid this problem, we will
2518 draw the function in three intervals, excluding the points where it is
2519 undefined:
2520 \medskip
2521 \begin{exemple}
2522 \SUBTRACTfunction{\SQUAREfunction}{\ONEfunction}
2523 {\Ffunction}
2524 \QUOTIENTfunction{\IDENTITYfunction}{\Ffunction}
2525 {\Gfunction}
2526 \renewcommand{\axeslabelsize}{\scriptsize}
2527 \setlength{\unitlength}{0.5cm}
2528 \begin{Picture}(-8,-6)(8,6)
2529 \def\xunitdivisions{2}
2530 \def\yunitdivisions{2}
2531 \cartesianaxes(-7,-5)(7,5)
2532 \pictcolor{red}
2533 \PlotFunction[5]{\Gfunction}{-7}{-1.105}
2534 \PlotFunction[5]{\Gfunction}{-0.905}{0}
2535 \PlotFunction[5]{\Gfunction}{0}{0.905}
2536 \PlotFunction[5]{\Gfunction}{1.105}{7}
2537 \end{Picture}
2538 \end{exemple}
2539
2540 (To determine the ends of the ranges of variation
2541 $\pm1.105$ and $\pm0.905$, we solved the equation
2542 $g(t)=5$, to ensure that asymtotic branches are interrupted
2543 at the border of the drawing area).
2544
2545 \subsubsection{Accurate graphs}
2546 In general, to obtain fairly reliable results we must make
2547 a careful analysis of the behavior of the function,
2548 determining the points where it is undefined or not differentiable,
2549 the intervals where it is increasing, its extreme values,
2550 points where graph cuts the coordinate axes and, in general,
2551 all points where the behavior of
2552 function is significant.
2553 From this information, we can chose the appropriate
2554 drawing intervals.
2555 A careful choice of the partition
2556 subintervals in the domain ensures us
2557 that the graph accurately reflects the behavior of the function.
2558
2559 We will see a couple of examples.
2560 First, we draw the sine function in $[-\pi,\pi]$.
2561 This function ant its derivative have no discontinuities,
2562 but it is convenient to choose a number of partitions
2563 being multiple of $4$, to carefully draw
2564 function at the
2565 $k\pi/2$ points.
2566 In fact, a good choice are 24 subdivisions,
2567 to ensure also the well known values of this function
2568 for angles
2569 multiple of $\pi/6$ and $\pi/4$.
2570 \begin{Exemple}
2571 \setlength{\unitlength}{2cm}%
2572
2573 \highestlabel{\normalfont\normalsize$3\pi/2$}
2574 \begin{center}
2575 \begin{Picture}(-3.5,-1.5)(3.5,1.5)
2576 {\referencesystem(0,0)(\numberHALFPI,0)(0,1)
2577 \makenolabels
2578 \cartesianaxes(-2.2,-1.2)(2.2,1.2)}
2579 \printylabels{-1}{1}{1}
2580 \printxlabel{-\numberPI}{-\pi}
2581 \printxlabel{-\numberHALFPI}{-\pi/2}
2582 \printxlabel{\numberHALFPI}{\pi/2}
2583 \printxlabel{\numberPI}{\pi}
2584 \pictcolor{red}
2585 \PlotFunction[24]{\SINfunction}{-\numberPI}{\numberPI}
2586 \renewcommand{\axeslabelcolor}{red}
2587 \printxlabel{\numberSIXTHPI}{\pi/6}
2588 \printylabel{0.5}{1/2}
2589 \Polyline(\numberSIXTHPI,0)(\numberSIXTHPI,0.5)(0,0.5)
2590 \end{Picture}
2591 \end{center}
2592 \end{Exemple}
2593
2594 Our second example is more complex. Let's graph the function
2595 \[
2596 f(t)=(t^3/3-t^2/2-2t+3)/3
2597 \]
2598
2599 This function has three roots, at
2600 $t=3/2$ and $t=\pm\sqrt{6}$.
2601 Its derivative, $f'(t)=(t^2-t-2)/3$, equals zero at
2602 $t=-1$ and $t=2$, where the function has, respectively,
2603 a relative maximum and a relative minimum.
2604 The second derivative, $f''(t)=(2t-1)/3$,
2605 is zero at $t=1/2$, which is an inflexion point.
2606 Interesting points are, then, the following:
2607 \[
2608 -\sqrt{6},-1,0,1/2,3/2,2,\sqrt{6}
2609 \]
2610
2611 We will plot this function in the
2612 $[-3,4]$ interval (because it includes all these points),
2613 but we divide it as
2614 \[
2615 [-3,-\sqrt{6}]\cup
2616 [-\sqrt{6},-1]\cup
2617 [-1,0]\cup
2618 [0,1/2]\cup
2619 [1/2,3/2]\cup
2620 [3/2,2]\cup
2621 [2,\sqrt{6}]\cup
2622 [\sqrt{6},4]
2623 \]
2624 \begin{Exemple}
2625 \SQRT{6}{\SQRTSIX}
2626 \newcpoly{\functionf}{1}{-0.66667}{-0.16667}{0.11111}
2627 \setlength{\unitlength}{2cm}
2628 \begin{center}
2629 \begin{Picture}(-3.5,-2.5)(4.5,3.5)
2630 \renewcommand{\xunitdivisions}{10}
2631 \renewcommand{\yunitdivisions}{10}
2632 \cartesiangrid(-3,-2)(4,3)
2633 \pictcolor{red}
2634 \PlotFunction{\functionf}{-3}{-\SQRTSIX}
2635 \PlotFunction[4]{\functionf}{-\SQRTSIX}{-1}
2636 \PlotFunction[4]{\functionf}{-1}{0}
2637 \PlotFunction[4]{\functionf}{0}{0.5}
2638 \PlotFunction[4]{\functionf}{0.5}{1.5}
2639 \PlotFunction[4]{\functionf}{1.5}{2}
2640 \PlotFunction[4]{\functionf}{2}{\SQRTSIX}
2641 \PlotFunction{\functionf}{\SQRTSIX}{4}
2642 \functionf{-1}{\tempf}{\tempDf}
2643 \xLINE(-1,0)(-1,\tempf)
2644 \functionf{2}{\tempf}{\tempDf}
2645 \xLINE(2,0)(2,\tempf)
2646 \functionf{0.5}{\tempf}{\tempDf}
2647 \xLINE(0.5,0)(0.5,\tempf)
2648 \end{Picture}
2649 \end{center}
2650 \end{Exemple}
2651
2652 \subsection{Polar coordinates curves}
2653 To draw a curve defined in polar form as $\rho =f(t)$, we must
2654 declare it as a polar curve, using the \csdef{POLARfunction}
2655 declaration: writing
2656 \begin{Verbatim}[commandchars=\|\[\]]
2657 \POLARfunction{\|TIT[functionname]}{\|TIT[polarfunction]}
2658 \end{Verbatim}
2659 we declare the new polar curve \cs{\TIT{polarfunction}}
2660 $\rho=\cs{\TIT{functionname}}(t)$.
2661 For example, the \emph{cardioide} curve, $\rho=1+\cos t$,
2662 can be defined in the following way:
2663 \begin{Verbatim}
2664 \SUMfunction{\ONEfunction}{\COSfunction}{\ffunction} % (y=1 + cos t)
2665 \POLARfunction{\ffunction}{\cardioide}
2666 \end{Verbatim}
2667
2668 Curves defined in such a way can be plotted using the
2669 \csdef{PlotParametricFunction} command,
2670 which syntax is analogous to that of \cs{PlotFunction}.
2671
2672 \begin{exemple}
2673 % Cardioide: r = 1+cos t
2674 \SUMfunction{\ONEfunction}{\COSfunction}
2675 {\ffunction}
2676 \POLARfunction{\ffunction}{\cardioide}
2677 \begin{center}
2678 \def\runitdivisions{2}
2679 \setlength{\unitlength}{1.5cm}
2680 \begin{Picture}(-2.5,-2.5)(2.5,2.5)
2681 \polargrid{2}{24}
2682 \pictcolor{blue}\linethickness{1pt}
2683 \PlotParametricFunction[20]{%
2684 \cardioide}{0}{\numberTWOPI}
2685 \end{Picture}
2686 $\rho=1+\cos\phi$
2687 \end{center}
2688 \end{exemple}
2689
2690 \begin{exemple}
2691 % Eight petal rose: r = cos(4t)
2692 \SCALEVARIABLEfunction{4}{\COSfunction}
2693 {\ffunction}
2694 \POLARfunction{\ffunction}{\rose}
2695 \begin{center}
2696 \def\runitdivisions{3}
2697 \MULTIPLY{2}{\numberTWOPI}{\numberFOURPI}
2698 \setlength{\unitlength}{2.5cm}
2699
2700 \begin{Picture}(-1.5,-1.5)(1.5,1.5)
2701 \polargrid{1}{16}
2702 \pictcolor{red}\linethickness{1pt}
2703 \PlotParametricFunction[16]\rose{0}{\numberTWOPI}
2704 \end{Picture}
2705 $\rho=\cos 4\phi$
2706 \end{center}
2707 \end{exemple}
2708
2709 \begin{exemple}
2710 % Archimedean spiral: r=0,5t
2711 \SCALEfunction{0.5}{\IDENTITYfunction}{\ffunction}
2712 \POLARfunction{\ffunction}{\archimedes}
2713
2714 \MULTIPLY{2}{\numberTWOPI}{\numberFOURPI}
2715 \setlength{\unitlength}{0.5cm}
2716 \begin{center}
2717 \begin{Picture}(-7,-7)(7,7)
2718 \pictcolor{red}
2719 \PlotParametricFunction[16]{%
2720 \archimedes}{0}{\numberFOURPI}
2721 \end{Picture}
2722 $2\rho=\phi$
2723 \end{center}
2724 \end{exemple}
2725
2726 \begin{exemple}
2727 \SCALEVARIABLEfunction{3.2}{\SINfunction}{\ffunction}
2728 \SCALEfunction{0.2}{\ffunction}{\gfunction}
2729 \SUMfunction{\ONEfunction}{\gfunction}{\myfunction}
2730 \POLARfunction{\myfunction}{\Rfunction}
2731 \MULTIPLY{10}{\numberPI}{\numberTENPI}
2732 \setlength{\unitlength}{3cm}
2733 \linethickness{2pt}
2734 \begin{center}
2735 \begin{Picture}(-1.2,-1.2)(1.2,1.2)
2736 \pictcolor{orange}
2737 \PlotParametricFunction[120]\Rfunction{0}{\numberTENPI}
2738 \end{Picture}
2739 $\rho=1+2\sin 3.2\phi$
2740 \end{center}
2741 \end{exemple}
2742 \subsection{Parametrically defined curves}\label{subsec:param}
2743 Polar curves are a particular case of parametrically defined curves,
2744 $x=f(t), y=g(t)$. These curves are declared by the
2745 \csdef{PARAMETRICfunction} command:
2746 \begin{Verbatim}[commandchars=\|\[\],commentchar=\%]
2747 \PARAMETRICfunction{\|TIT[Xfunction]}{\|TIT[Yfunction]}%
2748 {\|TIT[parametricfunction]}
2749 \end{Verbatim}
2750
2751 Once we have defined it,
2752 to draw this curve, we use the \csdef{PlotParametricFunction} as described
2753 above.
2754 \begin{Exemple}
2755 \POWERfunction{\IDENTITYfunction}{5}{\xfunction}
2756 \PARAMETRICfunction{\xfunction}{\CUBEfunction}{\myparfunction}
2757 \centering
2758 \setlength{\unitlength}{0.75cm}
2759 \begin{Picture}(-11,-6)(11,6)
2760 \cartesiangrid(-10,-5)(10,5)
2761 \pictcolor{blue}
2762 \PlotParametricFunction[10]{\myparfunction}{-1.5849}{0}
2763 \PlotParametricFunction[10]{\myparfunction}{0}{1.5849}
2764 \Put[E](10,4){$\begin{matrix}x=t^5\\y=t^3\end{matrix}$}
2765 \end{Picture}
2766 \end{Exemple}
2767 \begin{exemple}
2768 % A Lissanjous curve: x=sin 3t, y=sin 4t
2769 \SCALEVARIABLEfunction{3}{\SINfunction}{\ffunction}
2770 \SCALEVARIABLEfunction{4}{\SINfunction}{\gfunction}
2771 \PARAMETRICfunction{\ffunction}{\gfunction}{\myfunction}
2772 \MULTIPLY{10}{\numberPI}{\numberTENPI}
2773 \setlength{\unitlength}{3cm}
2774 \linethickness{2pt}
2775 \begin{center}
2776 \begin{Picture}(-1.2,-1.2)(1.2,1.2)
2777 \pictcolor{red}
2778 \PlotParametricFunction[24]\myfunction{0}{\numberTWOPI}
2779 \end{Picture}
2780
2781 $x=\sin 3t,\ y=\sin 4t$
2782 \end{center}
2783 \end{exemple}
2784
2785 Here, we should also take into account the characteristics of the curve
2786 in order to choose appropriate intervals for
2787 the parameter (typically, the points where the function is not defined,
2788 singularities, cuts with axes,
2789 points where some of the derivatives $x',x'',\ldots$ or $y',y''\ldots$) is
2790 zero\ldots
2791 In the following example, to represent the curve $x=t^2-1$, $y=t^3-t$,
2792 we see that $x$ or $y$ equals zero when $t$ is
2793 $0$, $1$ or $-1$; the first derivatives $x'=2t$, $y'=3t^2-1$,
2794 in $t=0$ and $t=\pm\sqrt3/3$, and second derivative of $y$ in $t=0$.
2795 Thus, we choose an interval containing these values of $t$, such $[-2.2]$,
2796 and this partition of it:
2797 \[
2798 [-2,2]=[-2,-1]\cup[-1,-\sqrt3/3]\cup[-\sqrt3/3,0]\cup[0,\sqrt3/3]\cup[\sqrt3/3,1]\cup[1,2]
2799 \]
2800
2801 This same curve was depicted with a single instruction
2802 \cs{PlotParametricFunction} dividing
2803 the interval $[-2.2]$ into five subintervals.
2804 Note that the obtained picture is almost identical, but the fact that
2805 partition not includes zero
2806 conceals the fact that the vertical tangent occurs at the point
2807 $(-1,0)$.
2808 So, one of the most significant features of the curve is not correctly
2809 displayed.
2810 \begin{Exemple}
2811 \SUBTRACTfunction{\SQUAREfunction}{\ONEfunction}{\Xpart}
2812 \SUBTRACTfunction{\CUBEfunction}{\IDENTITYfunction}{\Ypart}
2813 \PARAMETRICfunction{\Xpart}{\Ypart}{\myparfunction}
2814 \centering
2815 \setlength{\unitlength}{1cm}
2816 \begin{Picture}(-3.5,-6.5)(3.5,6.5)
2817 \cartesiangrid(-3,-6)(3,6)
2818 \pictcolor{blue}
2819 \PlotParametricFunction\myparfunction{-2}{-1}
2820 \PlotParametricFunction\myparfunction{-1}{-0.57735}
2821 \PlotParametricFunction\myparfunction{-0.57735}{0}
2822 \PlotParametricFunction\myparfunction{0}{0.57735}
2823 \PlotParametricFunction\myparfunction{0.57735}{1}
2824 \PlotParametricFunction\myparfunction{1}{2}
2825 \Put[E](3,6){$\begin{matrix}x=t^2-1\\y=t^3-t\end{matrix}$}
2826 \end{Picture}
2827 \qquad
2828 \begin{Picture}(-3.5,-6.5)(3.5,6.5)
2829 \cartesiangrid(-3,-6)(3,6)
2830 \pictcolor{orange}
2831 \PlotParametricFunction[5]\myparfunction{-2}{2}
2832 \Put[E](3,6){$\begin{matrix}x=t^2-1\\y=t^3-t\end{matrix}$}
2833 \end{Picture}
2834 \end{Exemple}
2835 \subsubsection{The curve of the front page}
2836 To conclude this section we will study in detail the example
2837 of the front page of this manual.
2838 This example shows the power,
2839 while the simplicity of the package \package{xpicture}.
2840
2841 It is the transcendent curve named \emph{butterfly},
2842 \begin{gather*}
2843 x=\sin t \left(\mathrm e^{\cos t} - 2 \cos 4t
2844 + \sin^5\left(\frac t{12}\right)\right) \\
2845 y=\cos t \left(\mathrm e^{\cos t} - 2 \cos 4t
2846 + \sin^5\left(\frac t{12}\right)\right)
2847 \end{gather*}
2848
2849 We analyze step by step the code we used:
2850 \begin{itemize}
2851 \item First, we calculated some numbers we'll use later:
2852 \begin{inparaenum}[(a)]
2853 \item $1/12$, that appears in the definition of functions $x$ and $y$;
2854 \item $12\times2\pi$, to plot the curve in $[0,24\pi]$ (twelve laps); and
2855 \item$12\times64$, the number of subdivisions we will use
2856 (64 subintervals for each lap).
2857 \VerbatimInput[numbers=left,firstline=3,lastline=5]{xpicture1.tex}
2858 \end{inparaenum}
2859 \item In the next block we do the important work:
2860 the curve is defined step by step.
2861
2862 \begin{compactitem}
2863 \item Define the function $A(t)=\mathrm e^{\cos t}$
2864 \VerbatimInput[numbers=left,firstline=7,lastline=7]{xpicture1.tex}
2865 \item Define $B(t)=\cos 4t$
2866 \VerbatimInput[numbers=left,firstline=8,lastline=8]{xpicture1.tex}
2867 \item Define $c(t)=\sin t/12$
2868 \VerbatimInput[numbers=left,firstline=9,lastline=9]{xpicture1.tex}
2869 \item Define $C(t)=\sin^5 t/12$
2870 \VerbatimInput[numbers=left,firstline=10,lastline=10]{xpicture1.tex}
2871 \item Define $AB(t)=\mathrm e^{\cos t}-2\cos 4t$
2872 \VerbatimInput[numbers=left,firstline=11,lastline=11]{xpicture1.tex}
2873 \item Define $ABC(t)=\mathrm e^{\cos t}-2\cos 4t+\sin^5 t/12$
2874 \VerbatimInput[numbers=left,firstline=12,lastline=12]{xpicture1.tex}
2875 \item Define the $x$ and $y$ functions
2876 \VerbatimInput[numbers=left,firstline=13,lastline=16]{xpicture1.tex}
2877 \item And, finally, we declare the parametric curve:
2878 \VerbatimInput[numbers=left,firstline=17,lastline=17]{xpicture1.tex}
2879 \end{compactitem}
2880
2881 \item Now, the picture composition is trivial
2882 (note the use of constants
2883 \cs{divisions} and \cs{phione} we previously calculated):
2884 \VerbatimInput[numbers=left,firstline=19,lastline=21]{xpicture1.tex}
2885 \end{itemize}
2886
2887 \subsection{Drawing curves from a table of values}
2888 All instructions to draw curves described here use the
2889 \csdef{qCurve} command, which draws quadratic B\'ezier curves:
2890 \begin{Verbatim}[commandchars=\|\[\],commentchar=\%]
2891 \qCurve(|TIT[x0],|TIT[y0])(|TIT[u0],|TIT[v0])(|TIT[x1],|TIT[y1])(|TIT[u1],%
2892 |TIT[v1])
2893 \end{Verbatim}
2894 draw a smooth curve between the points $(\TTT{\TIT{x0}},\TTT{\TIT{y0}})$
2895 and $(\TTT{\TIT{x1}},\TTT{\TIT{y1}})$, with tangent vectors
2896 $(\TTT{\TIT{u0}},\TTT{\TIT{v0}})$ and $(\TTT{\TIT{u1}},\TTT{\TIT{v1}})$,
2897 respectively.
2898 \begin{exemple}
2899 \setlength{\unitlength}{1cm}
2900 \begin{Picture}(-0.5,-0.5)(5.5,5.5)
2901 \cartesianaxes(0,0)(5,5)
2902 \pictcolor{blue}
2903 \qCurve(1,2)(1,2)(4,3)(-1,1)
2904 \pictcolor{gray}
2905 \Put(1,2){\xtrivVECTOR(0,0)(1,2)}
2906 \Put(4,3){\xtrivVECTOR(0,0)(-1,1)}
2907 \Polyline(1,0)(1,2)(0,2)
2908 \Polyline(4,0)(4,3)(0,3)
2909 \end{Picture}
2910 \end{exemple}
2911
2912 The \csdef{PlotQuadraticCurve} command generalizes \cs{qCurve}
2913 to an arbitrary number of points.
2914 \begin{exemple}
2915 \setlength{\unitlength}{1cm}
2916 \begin{Picture}(-0.5,-0.5)(5.5,3.5)
2917 \cartesianaxes(0,0)(5,3)
2918 \pictcolor{blue}
2919 \PlotQuadraticCurve(0,0)(1,0)%
2920 (1,1)(1,2)%
2921 (3,2)(-1,1)%
2922 (5,2)(0,-1)
2923 \end{Picture}
2924 \end{exemple}
2925 This command supports two alternative syntaxes:
2926 \begin{enumerate}[(a)]
2927 \item
2928 \begin{Verbatim}[commandchars=\|\[\],commentchar=\%]
2929 \PlotQuadraticCurve(|TIT[x0],|TIT[y0])(|TIT[u0],|TIT[v0])(|TIT[x1],|TIT[y1])%
2930 (|TIT[u1],|TIT[v1])...(|TIT[xn],|TIT[yn])(|TIT[un],|TIT[vn])
2931 \end{Verbatim}
2932 draws a curve through the points
2933 $(\TTT{\TIT{x0}},\TTT{\TIT{y0}})$,
2934 $(\TTT{\TIT{x1}},\TTT{\TIT{y1}})$\ldots
2935 $(\TTT{\TIT{xn}},\TTT{\TIT{yn}})$
2936 with tangent vectors
2937 $(\TTT{\TIT{u0}},\TTT{\TIT{v0}})$, $(\TTT{\TIT{u1}},\TTT{\TIT{v1}})$\dots
2938 $(\TTT{\TIT{un}},\TTT{\TIT{vn}})$.%
2939 \footnote{This command draws a
2940 quadratic curve between each pair of adjacent points.
2941
2942 The \cs{Curve} command, introduced by the
2943 \package{curve2e} package, does a similar job,
2944 but using cubic approximations, instead of quadratic.}
2945
2946 \begin{exemple}
2947 \setlength{\unitlength}{2cm}
2948 \begin{center}
2949 \begin{Picture}(1,1)(-1,-1)
2950 \pictcolor{red}
2951 \PlotQuadraticCurve(1,0)(1,0)(0,1)(0,1)%
2952 (-1,0)(-1,0)(0,-1)(0,-1)%
2953 (1,0)(1,0)
2954 \pictcolor{blue}
2955 \referencesystem(0,0)%
2956 (\numberCOSXLV,\numberCOSXLV)%
2957 (-\numberCOSXLV,\numberCOSXLV)
2958 \PlotQuadraticCurve(1,0)(1,0)(0,1)(0,1)%
2959 (-1,0)(-1,0)(0,-1)(0,-1)%
2960 (1,0)(1,0)
2961 \end{Picture}
2962 \end{center}
2963 \end{exemple}
2964 \item
2965 \begin{Verbatim}[commandchars=\|\[\],commentchar=\%]
2966 \PlotQuadraticCurve(|TIT[x0],|TIT[y0]){|TIT[angle0]}(|TIT[x1],|TIT[y1])%
2967 {|TIT[angle1]}...(|TIT[xn],|TIT[yn]){|TIT[anglen]}
2968 \end{Verbatim}
2969 draws a curve through the points
2970 $(\TTT{\TIT{x0}},\TTT{\TIT{y0}})$,
2971 $(\TTT{\TIT{x1}},\TTT{\TIT{y1}})$\ldots
2972 $(\TTT{\TIT{xn}},\TTT{\TIT{yn}})$
2973 the inclination angles of which, with respect to the $x$ axis,
2974 are \TTT{\TIT{angle0}}, \TTT{\TIT{angle1}}\dots,
2975 \TTT{\TIT{angle0}} (always measured in degrees).
2976 \begin{exemple}
2977 \setlength{\unitlength}{2cm}
2978 \begin{center}
2979 \begin{Picture}(1,1)(-1,-1)
2980 \pictcolor{red}
2981 \PlotQuadraticCurve(1,0){0}(0,1){90}
2982 (-1,0){180}(0,-1){270}
2983 (1,0){360}
2984 \pictcolor{blue}
2985 \referencesystem(0,0)%
2986 (\numberCOSXLV,\numberCOSXLV)%
2987 (-\numberCOSXLV,\numberCOSXLV)
2988 \PlotQuadraticCurve(1,0){0}(0,1){90}
2989 (-1,0){180}(0,-1){270}
2990 (1,0){360}
2991 \end{Picture}
2992 \end{center}
2993 \end{exemple}
2994 \end{enumerate}
2995 With the \cs{PlotQuadraticCurve} command you can approximate any smooth curve
2996 passing through a list of points when you know the tangent vectors.
2997 A particular case, particularly interesting (at least in a calculus course)
2998 is the drawing of the graph a function of real variable knowing a table of
2999 values of the function and its derivative.
3000 To facilitate this work \package{xpicture}
3001 includes the \csdef{PlotxyDyData} command:
3002 \begin{Verbatim}[commandchars=\|\[\],commentchar=\%]
3003 \PlotxyDyData(|TIT[x0],|TIT[y0],|TIT[Dy0])(|TIT[x1],|TIT[y1],|TIT[Dy1])...%
3004 (|TIT[xn],|TIT[yn],|TIT[Dyn])
3005 \end{Verbatim}
3006 plots the graph of a function $y=f(x)$ passing through points
3007 $(\TTT{\TIT{x0}},\TTT{\TIT{y0}})$,
3008 $(\TTT{\TIT{x1}},\TTT{\TIT{y1}})$\ldots
3009 $(\TTT{\TIT{xn}},\TTT{\TIT{yn}})$
3010 with derivatives $\TTT{\TIT{Dy0}}$, $\TTT{\TIT{Dy1}}$\ldots
3011 $\TTT{\TIT{Dyn}}$.
3012 \begin{exemple}
3013 \setlength{\unitlength}{1cm}
3014 \begin{Picture}(-1,-1)(5.5,5.5)
3015 \cartesianaxes(0,0)(5,5)
3016 \pictcolor{blue}
3017 \PlotxyDyData(0,0,2)(1,1,0)(2,2,3)
3018 (3,4,0)(5,1,-2)
3019 \pictcolor{gray}
3020 \Put(0,0){\xtrivVECTOR(0,0)(1,2)}
3021 \Put(1,1){\xtrivVECTOR(0,0)(1,0)}
3022 \Put(2,2){\xtrivVECTOR(0,0)(1,3)}
3023 \Put(3,4){\xtrivVECTOR(0,0)(1,0)}
3024 \Put(5,1){\xtrivVECTOR(0,0)(1,-2)}
3025 \end{Picture}
3026 \end{exemple}
3027 \section{Package options and configuration file}
3028 This package is loaded as usual, using the instruction
3029 \cs{usepackage\{\TIT{list of options}\}\{xpicture\}}.
3030 Then, packages \packagedef{pict2e}, \packagedef{curve2e}, \packagedef{xcolor},
3031 \packagedef{calculator}, and \packagedef{calculus} are automatically loaded.
3032 This package is compatible with any system that supports
3033 \packagedef{xcolor} and \packagedef{pict2e} packages.
3034
3035 The only specific option for this package is \optiondef{draft},
3036 which disables all the instructions defined in this package,
3037 replacing each picture set in a \environ{Picture} environment
3038 by a parallelogram circumscribed by a white rectangle (the box that shows
3039 the area reserved for the picture).\footnote{This option is equivalent to
3040 a global use of
3041 the \texttt{\textbackslash draftPictures} declaration.}
3042 This option is very useful throughout the production
3043 of the document,
3044 since the composition of the drawings slows considerably
3045 the compilation time.
3046
3047 All other options are passed directly to packages
3048 \packagedef{pict2e}, \packagedef{curve2e}, and \packagedef{xcolor}.
3049 The most interesting option (from package \package{pict2e})
3050 is \optiondef{pstarrows};
3051 if used, arrowheads in vectors are drawn in PSTricks style (instead of the
3052 standard \LaTeX{} style).
3053 Do not use the \optiondef{hide} or \optiondef{original}
3054 options (from package \package{pict2e}).
3055
3056 You can include your preferred values for configurable \package{xpicture}
3057 parameters
3058 (like axes or labels style, radians or degrees measure for angles,
3059 radians or degrees labels in polar grids, et cetera)
3060 using the file \texttt{xpicture.cfg}\ttindex{xpicture.cfg}, because,
3061 if exists, this local configuration file is loaded.
3062 If you want to use it, copy the file
3063 \texttt{xpicture.cfgxmpl}\ttindex{xpicture.cfgxmpl}
3064 (which is distributed along with package \package{xpicture}),
3065 call your copy as \texttt{xpicture.cfg} and put it in your local
3066 \texttt{texmf} tree.
3067 Initially, this file contains the default values for all parameters, but
3068 you edit it to modify everything agreed.
3069 \section{Compatibility with related packages}
3070 As mentioned earlier, this package loads packages
3071 \packagedef{pict2e}, \packagedef{curve2e}, \packagedef{xcolor},
3072 \packagedef{calculator}, and \packagedef{calculus}. Every command defined in
3073 these packages works fine within a \environ{Picture} environment. The only
3074 restriction to take in account is that colors must be selected with the
3075 \cs{pictcolor} command, because commands \cs{color} and \cs{textcolor}
3076 may cause the appearance of unwanted spaces. Picture commands defined
3077 in \packagedef{pict2e} and \packagedef{curve2e} can be freely used
3078 (had in mind, however, that in this case coordinates
3079 are interpreted as standard),
3080 and you can use all the techniques for defining and manipulating colors
3081 from \packagedef{color} and \packagedef{xcolor} packages.
3082
3083 Although guidelines for defining and operating with functions
3084 explained in subsections~\ref{subsec:real}--\ref{subsec:param}
3085 may be enough to compose a lot of graphics,
3086 in order to take full advantage of this package you must known
3087 packages \packagedef{calculator} and \packagedef{calculus}
3088 with certain depth. Package \package{calculator}
3089 will set you free of many tedious calculations.
3090 \medskip
3091
3092 On the other hand, \package{xpicture} is widely compatible with other packages
3093 related to the graphics inclusion, composition or modification.
3094 This fact gives us a lot of flexibility when using them together.
3095
3096 For example, a picture drawn by \package{xpicture} can include external images
3097 loaded with packages \packagedef{graphics}/\packagedef{graphicx},
3098 and you can also manipulate the whole picture with the aid of these packages.
3099 In a similar way, \texttt{pgf/tikz}\ttindex{pgf}\ttindex{tikz}
3100 pictures can be included inside a
3101 \package{xpicture} draw. If you use \LaTeX{} and \TTT{dvips} to compile your
3102 document, you can combine \package{xpicture} with \packagedef{pstricks}.
3103
3104 \printindex
3105 \end{document}