Debian Codegraph @

texmf-dist/doc/latex/tzplot/tzplot-doc-D-v2.2.tex

raw
1 %!TEX root = tzplot-doc.tex
2 %\begin{document}
3
4 %%%==========================
5 \part{Plotting Graphs}
6 %%%==========================
7 \label{p:plotting}
8
9
10 %%==================================
11 \chapter{Axes}
12 \label{c:axes}
13
14
15
16
17 %%------------------------------------------------------------
18 \section{Draw axes}
19 \label{s:tzaxes}
20
21 \subsection{\protect\cmd{\tzaxes}}
22 \label{ss:tzaxes}
23
24 Basically, \icmd{\tzaxes}|(<x1,y1>)(<x2,y2>)| draws the $x$ axis from |<x1>| to |<x2>| and the $y$ axis from |<y1>| to |<y2>|.
25 The coordinate |(<x1,y1>)| represents the origin and |(<x2,y2>)| represents the opposite corner of the rectangle formed by the two coordinates.
26
27 |\tzaxes| takes only one coordinate |(<x2,y2>)| as a mandatory argument, in which case the coordinate |(<x1,y1>)| is considered as |(0,0)|.
28
29 \begin{tzdef}
30 % syntax: minimal
31 \tzaxes(<x2,y2>){<x-axis label>}{<y-axis label>}
32 % syntax: full
33 \tzaxes[<opt>]<x-shift,y-shift>"<path name>"(<x1,y1>)(<x2,y2>)
34 {<x-axis label>}[<node opt>]{<y-axis label>}[<node opt>]
35 % defaults
36 [->]<0,0>"axes"(0,0)(<m>){}[right]{}[above]
37 % arguments
38 [#1]: line style, arrow type (for x-axis & y-axis)
39 <#2>: axes shift coor %% axes intersect at (#2)
40 "#3": name path=#3 %% default: axes
41 (#4): (x1,y1) %% origin: if omitted, regarded as (0,0)
42 (#5): (x2,y2) %% opposite corner: mandatory
43 {#6}: x-axis label
44 [#7]: x-axis label option %% node option
45 {#8}: y-axis label
46 [#9]: y-axis label option %% node option
47 \end{tzdef}
48
49 Here, |(|\ixxw{<m>}|)| stands for a mandatory argument.
50
51 \begin{tzcode}{.3}
52 % tzaxes
53 \begin{tikzpicture}[scale=.7]
54 \tzhelplines(4,3)
55 \tzaxes(4,3){$x$}{$y$}
56 \end{tikzpicture}
57 \end{tzcode}
58
59
60 \paragraph{Shift}
61 By default, the $x$ and $y$ axes intersect at $(0,0)$.
62 Specifying the option |<x-shift,y-shift>| shifts the axes to intersect at $(\text{\ttfamily<x-shift,y-shift>})$.
63
64 \begin{tzcode}{.3}
65 % tzaxes: intersects at (1,.5)
66 \begin{tikzpicture}[scale=.7]
67 \tzhelplines(4,3)
68 \tzaxes<1,.5>(4,3){$x$}{$y$}
69 \end{tikzpicture}
70 \end{tzcode}
71
72
73 \begin{tzcode}{.3}
74 % \tzaxes: shift
75 \begin{tikzpicture}[scale=.5]
76 \tzhelplines(-1,-1)(7,7)
77 \tzshoworigin*
78 \tzaxes[thick,blue]<1,2>(7,7){$x$}{$y$} %%
79 \tzaxes[-,dashed](7,7){$X$}[below]{$Y$}[left]
80 \tzaxes<6,1>(6,1)(3,6){$a$}[left]{$b$} %%
81 \end{tikzpicture}
82 \end{tzcode}
83
84 \paragraph{name path}
85 With the option |"<path name>"|, you can name the path of |\tzaxes| (by default, |axes|).
86 This makes it easy to find \xem{x-intercepts} and \xem{y-intercepts} of a graph.
87
88 \begin{tzcode}{.3}
89 % tzaxes; name path=axes (by default)
90 \begin{tikzpicture}
91 \tzhelplines(-1,-1)(3,3)
92 \tzaxes(-1,-1)(3,3){$x$}{$y$}
93 \tzline"line"(-1,2)(3,-.5)
94 \tzXpoint{axes}{line}(K) % default: axes
95 \tzdot*(K)
96 \tzdot(K-2)
97 \end{tikzpicture}
98 \end{tzcode}
99
100 The x-intercepts are found first and then the y-intercepts are found, as in the following example.
101
102 \begin{tzcode}{.3}
103 \begin{tikzpicture}[scale=.7]
104 % \tzaxes: name path
105 \tzhelplines(-2,-2)(5,5)
106 \tzaxes"myaxes"(-2,-2)(5,5) % name path = myaxes
107 \tzparabola"curve"(-2,-2)(1,4)(5,-1)
108 \tzXpoint{myaxes}{curve}(K) %%
109 \tzdot*(K){$A$}
110 \tzdot(K-2){$B$}
111 \tzdot(K-3){$C$}
112 \end{tikzpicture}
113 \end{tzcode}
114
115 \subsection{\protect\cmd{\tzaxes*}}
116 \label{ss:tzaxes*}
117
118 The starred version \icmd{\tzaxes*} sets the current state to a \iisw{bounding box} when the macro |\tzaxes| execution is complete. It is recommended for you to use |\tzaxes*| as the first graphics command in |tikzpicture| environment or before any larger graphics.
119
120 \begin{tzcode}{.3}
121 \begin{tikzpicture}[scale=.5]
122 \tzaxes*(8,5){$x$}{$f(x)$} % bounding box
123 \tzhelplines(-2,-1)(10,8)
124 \tzto[out=90,in=-135,dashed](-2,8)(12,-2)
125 \tzbezier[blue](-1,-1)(3,-2)(7,12)(10,10)
126 \end{tikzpicture}
127 \end{tzcode}
128
129
130 %%------------------------------------------------------------
131 \section{\protect\cmd{\tzaxisx} and \protect\cmd{\tzaxisy}}
132 \label{s:tzaxisx}
133
134 \icmd{\tzaxisx} draws only the $x$ axis.
135
136 \begin{tzdef}
137 % syntax
138 \tzaxisx[<opt>]<y-shift>"<path name>"{<from>}{<to>}
139 {<x-axis label>}[<node opt>]
140 % defaults
141 [->]<0>"axisx"{<m>}{<m>}{}[right]
142 % arguments:
143 [#1]: line style, arrow type (for x-axis)
144 <#2>: y-shift of x-axis
145 "#3": name path = #3 %% default: axisx
146 {#4}: x-axis starts from %% <m>
147 {#5}: x-axis runs to %% <m>
148 {#6}: x-axis label
149 [#7]: x-axis label option %% node option
150 \end{tzdef}
151
152 \icmd{\tzaxisy} draws only the $y$ axis.
153
154 \begin{tzdef}
155 % syntax
156 \tzaxisx[<opt>]<x-shift>"<path name>"{<from>}{<to>}
157 {<y-axis label>}[<node opt>]
158 % defaults
159 [->]<0>"axisy"{<m>}{<m>}{}[right]
160 % arguments:
161 [#1]: line style, arrow type (for y-axis)
162 <#2>: x-shift of y axis
163 "#3": name path = #3 %% default: axisy
164 {#4}: y-axis starts from %% <m>
165 {#5}: y-axis runs to %% <m>
166 {#6}: y-axis label
167 [#7]: y-axis label option %% node option
168 \end{tzdef}
169
170
171
172 \begin{tzcode}{.3}
173 % \tzaxisx, \tzaxisy
174 \begin{tikzpicture}[scale=.5]
175 \tzshoworigin
176 \tzhelplines(5,5)
177 \tzaxisx[blue]{-1}{5}{$xx$}
178 \tzaxisy[red] {-1}{5}{$yy$}[green]
179 \end{tikzpicture}
180 \end{tzcode}
181
182
183
184 \begin{tzcode}{.3}
185 % \tzaxisx, \tzaxisy: shift
186 \begin{tikzpicture}[scale=.5]
187 \tzhelplines(7,7)
188 \tzshoworigin
189 \tzaxisx{-1}{7}{$xx$}[very near end,below]
190 \tzaxisy{-1}{7}{$yy$}[midway,sloped,auto]
191 \tzaxisx[-,dashed,red]<2>{-1}{7}{$xx'$}[blue]
192 \tzaxisy[-,dashed,blue]<3>{-1}{7}{$yy'$}
193 \end{tikzpicture}
194 \end{tzcode}
195
196 With the option |"<path name>"|, you can name each path of |\tzaxisx| and |\tzaxisy| (by default, |axisx| and |axisy|, respectively).
197
198 \begin{tzcode}{.3}
199 % name path = axisx, axisy (defaults)
200 \begin{tikzpicture}[scale=.5]
201 \tzhelplines(7,7)
202 \tzshoworigin
203 \tzaxisx{-1}{7}{$xx$}[near start,below]
204 \tzaxisy{-1}{7}{$yy$}[midway,sloped,auto]
205 %\tzaxisx[-,dashed,red]<2>{-1}{7}{$xx'$}[blue]
206 %\tzaxisy[-,dashed,blue]<3>{-1}{7}{$yy'$}
207 \tzLFn"line"(1,3)(5,0)[-1:6]
208 \tzXpoint*{line}{axisx}(A){$A$}
209 \tzXpoint*{line}{axisy}(B){$B$}[0]
210 \end{tikzpicture}
211 \end{tzcode}
212
213 \begin{tzcode}{.3}
214 % name path = axisx, axisy (defaults)
215 \begin{tikzpicture}[scale=.5]
216 \tzhelplines(7,7)
217 \tzshoworigin
218 \tzaxisx{-1}{7}{$xx$}[near start,below]
219 \tzaxisy{-1}{7}{$yy$}[midway,sloped,auto]
220 \tzaxisx[-,dashed,red]<2>{-1}{7}{$xx'$}[blue]
221 \tzaxisy[-,dashed,blue]<3>{-1}{7}{$yy'$}
222 \tzLFn"line"(1,3)(5,0)[-1:6]
223 \tzXpoint*{line}{axisx}(A){$A$}
224 \tzXpoint*{line}{axisy}(B){$B$}[0]
225 \end{tikzpicture}
226 \end{tzcode}
227
228
229 %%------------------------------------------------------------
230 \section{Display the origin}
231 \label{s:tzshoworigin}
232
233 \subsection{\protect\cmd{\tzshoworigin}}
234 \label{ss:tzshoworigin}
235
236
237 \icmd{\tzshoworigin} prints `0' (approximately) at the bottom left of the origin |(0,0)|, by default.
238
239 \begin{tzdef}
240 % syntax
241 \tzshoworigin<shift coor>(<origin>){<text>}[<node opt>]
242 % default
243 <>(0,0){0}[below left,text height=1.25ex,text depth=.25ex]
244 \end{tzdef}
245
246 All arguments of |\tzshoworigin| are optional.
247
248 \begin{tzcode}{.3}
249 % \tzshoworigin
250 \begin{tikzpicture}[scale=.45]
251 \tzhelplines(8,5)
252 \tzshoworigin
253 \tzaxes(8,5)
254 \end{tikzpicture}
255 \end{tzcode}
256
257 You can change the text by specifying the curly brace option |{<text>}|, like, for example, |\tzshoworigin{$O$}|.
258 You can also change the coordinate of origin by the option |(<origin>)|.
259 Specifying the option |<shift coor>| also moves the origin.
260
261
262 \begin{tzcode}{.3}
263 % \tzshoworigin: shift
264 \begin{tikzpicture}[scale=.45]
265 \tzhelplines(-2,-1)(8,6)
266 \tzshoworigin{$O_1$} %%
267 \tzaxes(8,6){$x$}{$y$}
268 \tzshoworigin<2,1>{$O_2$}[red] %%
269 \tzaxes[dashed]<2,1>(8,6)
270 \end{tikzpicture}
271 \end{tzcode}
272
273
274 \subsection{\protect\cmd{\tzshoworigin*}}
275 \label{ss:tzshoworigin*}
276
277
278 \icmd{\tzshoworigin*} prints a node dot at the origin with no text by default.
279 Internally the dot is processed by |\tzdot*|. All arguments are optional.
280
281 \begin{tzdef}
282 % syntax
283 \tzshoworigin*[<dot opt>]<shift coor>(<origin>){<text>}[<node opt>](<dot size>)
284 % default
285 *[]<>(0,0){}[below left,text height=1.25ex,text depth=.25ex](2.4pt)
286 \end{tzdef}
287
288 \begin{tzcode}{.3}
289 % \tzshoworigin*
290 \begin{tikzpicture}[scale=.45]
291 \tzhelplines(-2,-1)(6,4)
292 \tzshoworigin*
293 \tzaxes(-2,-1)(6,4)
294 \end{tikzpicture}
295 \end{tzcode}
296
297 You can add text with the option |{<text>}|.
298 The default size of the dot is |2.4pt|, and it can be changed with the last option |(<dot size>)|. You can change the dot style using the first optional argument |[<dot opt>]|.
299 You can also move the dot by specifying the option |<shift coor>|.
300
301 \begin{tzcode}{.3}
302 % \tzshoworigin*
303 \begin{tikzpicture}[scale=.5]
304 \tzhelplines(-1,-1)(7,7)
305 \tzshoworigin*[blue]{$o_1$}[red](5pt)
306 \tzaxes(-1,-1)(7,7){$x$}{$y$}
307 \tzaxes<6,4>(6,4)(1,1){$x'$}[left]{$y'$}[below]
308 \tzshoworigin*[fill=none]<6,4>{$O'$}[blue,ar](3pt)
309 \end{tikzpicture}
310 \end{tzcode}
311
312 \remark
313 For |\tzshoworigin*|, text for the origin and the dot are placed independently. In other words, the position of node text does not depend on the size of a node dot.
314 (In fact, the node text for the origin should look good with the `ticks labels', so it was not designed as a |label| for the node dot. This also means that the origin text cannot be positioned by an |<angle>|.)
315
316
317 \begin{tzcode}{.3}
318 % \tzshoworigin* (with tick labels)
319 \begin{tikzpicture}[scale=.5]
320 \tzhelplines(-2,1)(6,5)
321 \tzshoworigin*{0}(5pt)
322 \tzaxes(-2,-1)(6,5){$x$}{$y$}
323 \tzticks{1,...,5}{1,...,4}
324 \end{tikzpicture}
325 \end{tzcode}
326
327
328
329 %%------------------------------------------------------------
330 \section{\protect\cmd{\tzaxesL(')}: L-type axes}
331 \label{s:tzaxesL}
332
333 \icmd{\tzaxesL} is similar to |\tzaxes|, but it draws only the `L' type axes with |(<x1,y1>)| as the origin and |(<x2,y2>)| as the opposite corner of the rectangle.
334 Those two coordinates are mandatory.
335
336 \begin{tzdef}
337 % syntax
338 \tzaxesL[<opt>]<shift coor>"<path name>"(<x1,y1>)(<x2,y2>)
339 {<x-axis label>}[<node opt>]{<y-axis label>}[<node opt>]
340 % defaults
341 []<>"axesL"(<m>)(<m>){}[right]{}[above]
342 % arguments:
343 [#1]: line style, arrow type
344 <#2>: shift coordinate
345 "#3": name path=#3 %% default: axesL
346 (#4): (x1,y1) %% mandatory
347 (#5): (x2,y2) %% mandatory
348 {#6}: x-axis label
349 [#7]: x-axis label option %% node option
350 {#8}: y-axis label
351 [#9]: y-axis label option %% node option
352 \end{tzdef}
353
354 The \iisw{swap version} \icmd{\tzaxesL'} swaps |(<x1,y1>)| and |(<x2,y2>)|.
355 That is, |\tzaxesL'(A)(B)| is equivalent to |\tzaxesL(B)(A)|.
356
357 \begin{tzcode}{.3}
358 % \tzaxesL, \tzaxesL'
359 \begin{tikzpicture}[scale=.5]
360 \tzhelplines(8,7)
361 \tzshoworigin
362 \tzaxes(8,7){$x$}{$y$}
363 \tzaxesL[red,thick](2,2)(6,5){$a$}{$b$}
364 \tzaxesL'[blue,dashed,->](2,2)(6,5){$c$}{$d$}
365 \tzaxesL'[->](7,1)(4,7){m}[draw,r]{n}[draw,circle]
366 \end{tikzpicture}
367 \end{tzcode}
368
369 \paragraph{Shift}
370
371 The option |<shift coor>| moves the whole L-type axes.
372 The empty option |<>| is not allowed.
373
374 \begin{tzcode}{.3}
375 % \tzaxesL, \tzaxesL': shift
376 \begin{tikzpicture}[scale=.5]
377 \tzhelplines(8,7)
378 \tzshoworigin
379 \tzaxes(8,7){$x$}{$y$}
380 \tzaxesL[red,thick](2,2)(6,5){$a$}{$b$}
381 \tzaxesL[red,thick]<.5,.5>(2,2)(6,5){$a'$}{$b'$}
382 \tzaxesL'[blue,dashed,->](2,2)(6,5){$c$}{$d$}
383 \tzaxesL'[blue,dashed,->]<-1,-1>(2,2)(6,5){$c'$}{$d'$}
384 \end{tikzpicture}
385 \end{tzcode}
386
387
388 \paragraph{\texttt{name path}}
389
390 With the option |"<path name>"|, you can name the path of |\tzaxesL| (by default, |axesL|). This makes it easy to find the intercepts.
391
392 \begin{tzcode}{.3}
393 % \tzaxesL: name path (by default, axesL)
394 \begin{tikzpicture}[scale=.5]
395 \tzhelplines(8,7)
396 \tzshoworigin
397 \tzaxes(8,7){$x$}{$y$}
398 \tzaxesL[red,thick](2,2)(6,5){$a$}{$b$}
399 \tzaxesL'[blue,dashed,->]<-1,-1>(2,2)(6,5){$c'$}{$d'$}
400 \tzparabola"curve"(1,6)(3,1.5)(6,5)
401 \tzXpoint{axesL}{curve}(K) % default: axesL
402 \tzdot*(K)
403 \tzdot(K-2)
404 \end{tikzpicture}
405 \end{tzcode}
406
407
408
409
410 %%==================================
411 \chapter{Ticks}
412 \label{c:ticks}
413
414
415 %%------------------------------------------------------------
416 \section{\protect\cmd{\tzticks}: Tick labels}
417 \label{s:tzticks}
418
419 By default, \icmd{\tzticks} prints tick labels and draws zero length tick marks, i.e. from |(0pt)| to |(0pt)|.
420
421 \begin{tzdef}
422 % syntax: minimal
423 \tzticks{<x-ticks pos>}{<y-ticks pos>}
424 % syntax: medium
425 \tzticks(<x-from:x-to>){<x-ticks pos/labels>}[<node opt>]
426 (<y-from:y-to>){<y-ticks pos/labels>}[<node opt>]
427 % syntax: full
428 \tzticks[<opt>]<x-shift,y-shift>
429 (<x-from:x-to>){<x-ticks pos/labels>}[<node opt>]
430 (<y-from:y-to>){<y-ticks pos/labels>}[<node opt>]
431 % defaults
432 []<0,0>(0pt:0pt){<m>}[text height=1.25ex,text depth=.25ex,below](0pt:0pt){}[left]
433 \end{tzdef}
434
435 \paragraph{Tick labels}
436 Internally, |\tzticks| uses \Tikz's |foreach| operation.
437 So you need to provide comma separated lists to print tick labels.
438 If only one comma separated list is specified, it is for $x$ tick labels.
439
440 \begin{tzcode}{.3}
441 % \tzticks
442 \begin{tikzpicture}[scale=.4,font=\scriptsize]
443 \tzhelplines(10,10)
444 \tzaxes(-1,-1)(10,10)
445 \tzticks[blue]{1,...,8}{2,...,7}
446 \end{tikzpicture}
447 \end{tzcode}
448
449 You can change the numbered labels to a different format with slashes and other text, as follows: |<number>/<other text>|.
450
451 \begin{tzcode}{.3}
452 % \tzticks: tick labels
453 \begin{tikzpicture}[scale=.4,font=\scriptsize]
454 \tzhelplines(10,10)
455 \tzaxes(-1,-1)(10,10)
456 \tzticks{1/$x_1$,2,5/$x_2$,8/y}[blue]
457 {2/$\sqrt{x}$,3/y,4/m,5,7/$k$}[red]
458 \end{tikzpicture}
459 \end{tzcode}
460
461 \paragraph{Tick marks}
462 By specifying the options |(<x-from:x-to>)| for $x$ ticks and/or |(<y-from:y-to>)| for $y$ ticks, you can print tick marks. (The default is |(0pt:0pt)| for both options.)
463
464 \begin{tzcode}{.3}
465 % \tzticks: tick marks with (<a pt:b pt>)
466 \begin{tikzpicture}[scale=.4,font=\scriptsize]
467 \tzhelplines(10,10)
468 \tzshoworigin
469 \tzaxes(-1,-1)(10,10)
470 \tzticks[draw=red,thick]
471 (-15pt:10pt){1,...,5,6/$k$,7/$\alpha$,8/$\beta$}
472 (0pt:3cm) {2,...,6,7/$\gamma$}
473 \end{tikzpicture}
474 \end{tzcode}
475
476 The position of tick labels does not depend on the length of the tick marks.
477 You can change the position of tick labels using |[<node opt>]|.
478
479 \begin{tzcode}{.3}
480 % \tzticks: position of tick labels
481 \begin{tikzpicture}[scale=.4,font=\scriptsize]
482 \tzhelplines(10,10)
483 \tzshoworigin
484 \tzaxes(-1,-1)(10,10)
485 \tzticks[draw=red,thick]
486 (-15pt:10pt){1,...,6,7/$t$,8/$\alpha$}[b=5pt]
487 (0pt:3cm) {2,...,6,7/$\beta$}
488 \end{tikzpicture}
489 \end{tzcode}
490
491 \paragraph{Shift}
492
493 You can move (or shift) the tick marks and labels together by specifying the optional argument |<x-shift,y-shift>|, where |<x-shift>| is for |y-ticks| and |<y-shift>| is for |x-ticks|.
494
495 \begin{tzcode}{.3}
496 % \tzticks: shift
497 \begin{tikzpicture}[scale=.4,font=\scriptsize]
498 \tzhelplines(10,10)
499 \tzshoworigin
500 \tzaxes(-1,-1)(10,10)
501 \tzaxes[dashed]<4,2>(-1,-1)(10,10)
502 \tzticks[draw=red]<4,2>
503 (-5pt:10pt){5,...,8}
504 (0pt:3cm) {3,...,7}
505 \end{tikzpicture}
506 \end{tzcode}
507
508
509
510
511
512 %%------------------------------------------------------------
513 \section{\protect\cmd{\tzticks*}: Tick marks}
514 \label{s:tzticks*}
515
516 The starred version \icmd{\tzticks*} always ignores all tick labels and draws tick marks from |0pt| to |3pt|, by default.
517
518 \begin{tzdef}
519 % syntax: minimal
520 \tzticks*{<x-ticks pos>}{<y-ticks pos>}
521 % syntax: medium
522 \tzticks*(<x-from:x-to>){<x-ticks pos>}(<y-from:y-to>){<y-ticks pos>}
523 % syntax: full
524 \tzticks*[<opt>]<x-shift,y-shift>
525 (<x-from:x-to>){<x-ticks pos>}(<y-from:y-to>){<y-ticks pos>}
526 % defaults
527 []<0,0>(0pt:3pt){<m>}(0pt:3pt){}
528 % starred(*) version always suppresses tick labels
529 \end{tzdef}
530
531 \begin{tzcode}{.3}
532 % \tzticks*
533 \begin{tikzpicture}[scale=.4,font=\scriptsize]
534 \tzhelplines(10,10)
535 \tzshoworigin
536 \tzaxes(-1,-1)(10,10)
537 \tzticks*[draw=red,thick]
538 {1,...,7,8/$\alpha$} % labels ignored
539 (0pt:3cm){2,...,6,7/$\beta$} % labels ignored
540 \end{tikzpicture}
541 \end{tzcode}
542
543 \begin{tzcode}{.4}
544 % \tzticks(*)
545 \begin{tikzpicture}[scale=.5]
546 \tzhelplines(10,8)
547 \tzaxes(-1,-1)(10,8)
548 \tzticks*
549 {0,0.2,...,8}
550 {0,0.2,...,7} % default (0pt:3pt)
551 \tzticks*
552 (0pt:10pt){1,...,8}
553 (0pt:10pt){1,...,7}
554 \tzticks
555 {1,...,8}
556 {2,...,7} % default (0pt:0pt)
557 \end{tikzpicture}
558 \end{tzcode}
559
560
561 %%------------------------------------------------------------
562 \section{\protect\cmd{\tzticksx(*)} and \protect\cmd{\tzticksy(*)}}
563 \label{s:tzticksx}
564
565 You can handle $x$ ticks and $y$ ticks independently.
566
567 \paragraph{X ticks}
568
569 \icmd{\tzticksx} only prints x-tick labels but not tick marks, by default.
570 To prints tick marks you need to specify |(<x-from>:<x-to>)|.
571
572 \begin{tzdef}
573 % syntax:
574 \tzticksx[<opt>]<y-shift>(<from>:<to>){<x-tick pos/labels>}[<node opt>]
575 % defaults
576 []<>(0pt:0pt){<m>}[text height=1.25ex,text depth=.25ex,below]
577 \end{tzdef}
578
579
580 \icmd{\tzticksx*} only prints x-tick marks from |0pt| to |3pt|, by default, suppressing tick labels.
581
582 \begin{tzdef}
583 % syntax:
584 \tzticksx*[<opt>]<y-shift>(<from>:<to>){<xtick pos>}
585 % defaults
586 *[]<>(0pt:3pt){<m>}
587 % starred(*) version always suppresses tick labels
588 \end{tzdef}
589
590
591 \paragraph{Y ticks}
592
593 \icmd{\tzticksy} only prints y-tick labels but not tick marks, by default.
594 To prints tick marks you need to specify |(<x-from>:<x-to>)|.
595
596 \icmd{\tzticksy*} only prints y-ticks from |0pt| to |3pt| by default, suppressing tick labels.
597
598 \begin{tzdef}
599 % syntax:
600 \tzticksy[<opt>]<x-shift>(<from:to>){<y-ticks pos/labels>}[<node opt>]
601 % defaults
602 []<>(0pt:0pt){<m>}[]
603 \end{tzdef}
604
605 \begin{tzdef}
606 % syntax:
607 \tzticksy*[<opt>]<x-shift>(<from:to>){<yticks pos>}
608 % defaults
609 []<>(0pt:0pt){<m>}
610 % starred(*) version suppresses tick labels
611 \end{tzdef}
612
613
614 \begin{tzcode}{.3}
615 % \tztickx(*), \tzticky(*)
616 \begin{tikzpicture}[scale=.4,font=\scriptsize]
617 \tzhelplines(10,10)
618 \tzshoworigin
619 \tzaxes(-1,-1)(10,10)
620 \tzticksx [draw=red,thick]
621 (-5pt:1cm){1,...,7,8/$\alpha$}
622 \tzticksy*[draw=blue,thick]
623 (0pt:3cm){2,...,6,7/$\beta$} % labels ignored
624 \end{tikzpicture}
625 \end{tzcode}
626
627 \paragraph{Shift}
628 The options |<y-shift>| and |<x-shift>| move x-ticks and y-ticks, respectively.
629
630 \begin{tzcode}{.3}
631 % \tztickx(*), \tzticky(*): shift
632 \begin{tikzpicture}[scale=.4,font=\scriptsize]
633 \tzhelplines(10,10)
634 \tzshoworigin
635 \tzaxes(-1,-1)(10,10)
636 \tzaxes[dashed]<2,1>(-1,-1)(10,10)
637 \tzticksx*[draw=red,thick]
638 <1>(-5pt:10pt){1,...,7,8/$\alpha$} % labels ignored
639 \tzticksy [draw=blue,thick]
640 <2>(0pt:3cm){2,...,6,7/$\beta$}
641 \end{tikzpicture}
642 \end{tzcode}
643
644
645
646
647 %%==================================
648 \chapter{Projections}
649 \label{c:projections}
650
651 %%------------------------------------------------------------
652 \section{\protect\cmd{\tzproj(*)}: Projections on the axes}
653 \label{s:tzproj}
654
655 \icmd{\tzproj} accepts a mandatory coordinate and draws perpendicular lines onto each axis from the coordinate. The lines are |dotted|, by default.
656
657 \begin{tzdef}
658 % syntax: minimum
659 \tzproj(<coor>)
660 % syntax: medium
661 \tzproj*(<coor>){<x-text>}[<node opt>]{<y-text>}[<node opt>]
662 % syntax: full
663 \tzproj*[<opt>]<x-shift,y-shift>(<coor>)
664 {<x-text>}[<node opt>]{<y-text>}[<node opt>](<dot size>)
665 % defaults
666 *[dotted]<0,0>(<m>){}[text height=1.25ex,text depth=.25ex,below]{}[left](2.4pt)
667 \end{tzdef}
668
669 \icmd{\tzproj*} additionally prints a `black node dot' of the size |2.4pt|, by default.
670 Internally, the node dot is processed by |\tzdot*|.
671 The first option |[<opt>]| does not control the node dot.
672
673 \paragraph{Dot size}
674 You can only control the size of dots by the last optional argument |(<dot size>)| or by the \threeways\ on page \pageref{ss:threeways}.
675 If you want to control |fill| or |color| of dots, use |\tzdot*| separately.
676
677 \begin{tzcode}{.3}
678 %\tzproj(*)
679 \begin{tikzpicture}[scale=.5]
680 \tzaxes(8,6)
681 \tzproj[dashed,blue](2,3)
682 \tzcoors(30:7)(A)(50:6)(B);
683 \tzproj*(A)
684 \tzproj*[dashed,text=blue](B)(5pt)
685 \end{tikzpicture}
686 \end{tzcode}
687
688 \paragraph{Adding text}
689 You can also add text around the projection point on each axis by the option |{<text>}|.
690 The position and color of the text is controlled by the option |[<node option>]|.
691 The default position is (approximately) |[below]| for the x axis and |[left]| for the y axis.
692
693
694 \begin{tzcode}{.3}
695 % \tzproj(*): adding text
696 \begin{tikzpicture}[scale=.5]
697 \tzhelplines(8,6)
698 \tzaxes(8,6)
699 \tzproj[dashed,blue](2,3){$x$}{$y$}
700 \tzcoors(30:7)(A)(50:6)(B);
701 \tzproj*[text=blue](A){$a_1$}{$a_2$}
702 \tzproj*[dashed](B){$x^*$}[green]{$y^*$}[red]
703 \end{tikzpicture}
704 \end{tzcode}
705
706 \paragraph{Projection shift}
707 Specifying the option |<x-shift,y-shift>| moves the projection point and text on each axis.
708
709 \begin{tzcode}{.3}
710 % \tzproj(*): projection shift
711 \begin{tikzpicture}[scale=.5]
712 \tzhelplines(8,6)
713 \tzaxes(8,6)
714 \tzproj[dashed,blue](2,3){$x$}{$y$}
715 \tzcoors(30:7)(A)(50:6)(B);
716 \tzaxes[blue]<3,1>(8,6)
717 \tzproj*[dashed,text=blue]<3,1>(A){$a_1$}{$a_2$} %%
718 \end{tikzpicture}
719 \end{tzcode}
720
721
722 %%------------------------------------------------------------
723 \section{\protect\cmd{\tzprojx(*)} and \protect\cmd{\tzprojy(*)}}
724 \label{s:tzprojx}
725
726 \icmd{\tzprojx} draws a dotted line, which is perpendicular to the x axis.
727
728 \icmd{\tzprojx*} additionally prints a `black node dot' of the size |2.4pt|, by default.
729
730
731 \begin{tzdef}
732 % syntax:
733 \tzprojx[<opt>]<x-shift,y-shift>(<coor>){<x-text>}[<node opt>](<dot size>)
734 % defaults
735 []<0,0>(<m>){}[text height=1.25ex,text depth=.25ex,below](2.4pt)
736 \end{tzdef}
737
738
739 \icmd{\tzprojy} draws a dotted line, which is perpendicular to the y axis.
740
741 \icmd{\tzprojy*} additionally prints a `black node dot' of the size |2.4pt|, by default.
742
743 \begin{tzdef}
744 % syntax:
745 \tzprojy[<opt>]<x-shift,y-shift>(<coor>){<y-text>}[<node opt>](<dot size>)
746 % defaults
747 []<0,0>(<m>){}[left](2.4pt)
748 \end{tzdef}
749
750
751 You can only control the size of dots by the last option |(<dot size>)|.
752 If you want to control |fill| or |color| of dots, use |\tzdot*| separately.
753 You can also add text around the projection point on each axis by specifying the option |{<x-text>}| or |{<y-text>}| followed by the option |[<node option>]|.
754
755 \begin{tzcode}{.3}
756 % \tzprojx(*), \tzprojy(*)
757 \begin{tikzpicture}[scale=.5,font=\scriptsize]
758 \tzhelplines(-1,-2)(6,6)
759 \tzshoworigin
760 \tzaxes(-1,-1)(6,6)
761 \tzproj*[dashed](4,5){4}{5}(3pt)
762 \tzprojx*[green,thick,solid](3,4){$x=3$}[blue]
763 \tzprojy*[thick](5,2){2}(5pt)
764 \end{tikzpicture}
765 \end{tzcode}
766
767 Specifying the option |<x-shift,y-shift>| with |\tzprojx(*)| and |\tzprojy(*)| moves the projection point and text accordingly.
768
769 \begin{tzcode}{.3}
770 % \tzprojx(*), \tzprojy(*): shift
771 \begin{tikzpicture}[scale=.5,font=\scriptsize]
772 \tzhelplines(-1,-2)(6,6)
773 \tzshoworigin
774 \tzaxes(-1,-1)(6,6)
775 \tzaxes[blue]<2,1>(-1,-1)(6,6)
776 \tzprojx*[green,thick,solid]<2,1>(3,4){$x=3$}[blue]
777 \tzprojy*[thick]<2,1>(5,2){2}(5pt)
778 \end{tikzpicture}
779 \end{tzcode}
780
781
782
783 %%------------------------------------------------------------
784 \section{\protect\cmd{\tzprojs(*)}: Semicolon versions}
785 \label{s:tzprojs}
786
787 \icmd{\tzprojs} accepts any number of coordinates and draws perpendicular lines onto each axis from the coordinates. The lines are |dotted|, by default.
788 |\tzprojs| is a semicolon version of |\tzproj|, so a semicolon is needed to indicate when the coordinate iteration ends. Its repeating pattern is |(<coor>){<x-text>}[<node opt>]{<y-text>}[<node opt>]|.
789
790 \begin{tzdef}
791 % syntax: minimum
792 \tzprojs(<coor>)(<coor>) ..repeated.. (<coor>) ;
793 % syntax: medium
794 \tzprojs*(<coor>){<x-text>}[<node opt>]{<y-text>}[<node opt>]
795 ..repeated.. (){}[]{}[]
796 % syntax: full
797 \tzprojs*[<opt>]<x-shift,y-shift>
798 (<coor>){<x-text>}[<node opt>]{<y-text>}[<node opt>]
799 ..repeated.. (){}[]{}[] ; (<dot size>)
800 % defaults
801 *[dotted]<0,0>
802 (<m>){}[text height=1.25ex,text depth=.25ex,below]{}[left]
803 ..repeated..(){}[]{}[];(2.4pt)
804 \end{tzdef}
805
806 \icmd{\tzprojs*} additionally prints |\tzdots*| of the |2.4pt| (by default) on the coordinates.
807 The first option |[<opt>]| does not control the node dots.
808
809 \begin{tzcode}{.3}
810 % \tzprojs(*): adding text
811 \begin{tikzpicture}[scale=.5]
812 \tzhelplines(8,6)
813 \tzaxes(8,6)
814 \tzcoors(30:7)(A)(50:6)(B);
815 \tzprojs*[dashed,text=blue]
816 (2,3){$x$}{$y$}
817 (A){$a_1$}{$a_2$}
818 (B){$x^*$}[green]{$y^*$}[red];
819 \end{tikzpicture}
820 \end{tzcode}
821
822 You can move the projection points and text accordingly, using the option |<x-shift,y-shift>| before the first coordinate. The \xem{empty} shift option |<>| is \xem{not allowed}.
823 You can also change the dot size with the last option |(<dot size>)| \xem{after} the semicolon, as in |\tzproj(*)|.
824
825 \begin{tzcode}{.3}
826 % \tzprojs(*): shift and dot size
827 \begin{tikzpicture}[scale=.5]
828 \tzhelplines(8,6)
829 \tzaxes(8,6)
830 \tzaxes[blue]<1,1>(8,6)
831 \tzcoors(30:7)(A)(50:6)(B);
832 \tzprojs*[dashed,text=blue]<1,1> %%
833 (2,3){$x$}{$y$}
834 (A){$a_1$}{$a_2$}
835 (B){$x^*$}[green]{$y^*$}[red];(4pt) %%
836 \end{tikzpicture}
837 \end{tzcode}
838
839
840 %%------------------------------------------------------------
841 \section{\protect\cmd{\tzprojsx(*)} and \protect\cmd{\tzprojsy(*)}: Semicolon versions}
842 \label{s:tzprojsx}
843
844 \icmd{\tzprojsx} is a semicolon versions of |\tzprojx|. It draws dotted lines, which are perpendicular to the x axis from the specified coordinates, by default.
845
846 \icmd{\tzprojsx*} additionally prints |\tzdots*| of the size |2.4pt|, by default.
847
848
849 \begin{tzdef}
850 % syntax:
851 \tzprojsx*[<opt>]<x-shift,y-shift>
852 (<coor>){<x-text>}[<node opt>]..repeated..(){}[];(<dot size>)
853 % defaults
854 *[]<0,0> (<m>){}[text height=1.25ex,text depth=.25ex,below]
855 ..repeated..(){}[];(2.4pt)
856 \end{tzdef}
857
858
859 \icmd{\tzprojsy} and \icmd{\tzprojsy*} work simililarly as |\tzprojsx| and |\tzprojsx*| do but to the y axis.
860
861 \begin{tzdef}
862 % syntax:
863 \tzprojsy*[<opt>]<x-shift,y-shift>
864 (<coor>){<y-text>}[<node opt>]..repeated..(){}[];(<dot size>)
865 % defaults
866 []<0,0> (<m>){}[left]..repeated..(){}[];(2.4pt)
867 \end{tzdef}
868
869
870 \begin{tzcode}{.3}
871 % \tzprojsx(*), \tzprojsy(*)
872 \begin{tikzpicture}[scale=.5,font=\scriptsize]
873 \tzhelplines(-1,-2)(6,6)
874 \tzshoworigin
875 \tzaxes(-1,-1)(6,6)
876 \tzprojsx*[thick]
877 (4,5){4}
878 (3,4){$x=3$}[blue]
879 (5,2){2};(5pt)
880 \end{tikzpicture}
881 \end{tzcode}
882
883 Specifying the option |<x-shift,y-shift>| moves the projection points and text accordingly.
884
885 \begin{tzcode}{.3}
886 % \tzprojsx(*), \tzprojsy(*): shift
887 \begin{tikzpicture}[scale=.5,font=\scriptsize]
888 \tzhelplines(-1,-2)(6,6)
889 \tzshoworigin
890 \tzaxes(-1,-1)(6,6)
891 \tzaxes[blue]<2,1>(-1,-1)(6,6)
892 \tzprojsy*[red,solid]<2,1>
893 (3,4){$x=3$}[blue]
894 (5,2){2};
895 \end{tikzpicture}
896 \end{tzcode}
897
898
899
900 %%==================================
901 \chapter{Plot Functions}
902 \label{c:functions}
903
904
905 %%------------------------------------------------------------
906 \section{\protect\cmd{\tzfn} and \protect\cmd{\tzfn'}: Plot functions and inverse functions}
907 \label{s:tzfn}
908
909 \subsection{\protect\cmd{\tzfn}}
910 \label{ss:tzfn}
911
912 \icmd{\tzfn} plots a function of |\x|.
913
914 \begin{tzdef}
915 % syntax: minimum
916 \tzfn{<fn of \x>}[<domain>]
917 % syntax: medium
918 \tzfn{<fn of \x>}[<domain>]{<text>}[<pos>]
919 % syntax: full
920 \tzfn[<opt>]<shift coor>"<path name>"
921 {<fn of \x>}[<domain>]{<text>}[<node opt>]<code.append>
922 % [<domain>] should be of the form [<from num:to num>]
923 % defaults
924 [samples=201]<>""{<m>}[<m>]{}[]<>
925 \end{tzdef}
926
927 |\tzfn| takes two mandatory arguments: |{<fn of \x>}| and |[<domain>]|.
928 The domain should be of the form |[<from num:to num>]|, like |[1:5]|.
929
930 \begin{tztikz}
931 \tzfn{.5*(\x)^2-1}[1:5] % works like:
932 \draw [samples=201,domain=1:5] plot (\x,{.5*(\x)^2-1});
933 \end{tztikz}
934
935 \begin{tzcode}{.3}
936 % \tzfn : simple example
937 \begin{tikzpicture}[scale=.5]
938 \tzhelplines(-2,-2)(5,5)
939 \tzaxes*(-2,-2)(5,5)
940 \tzfn{.5*(\x)^2-1}[0:3.5]
941 \end{tikzpicture}
942 \end{tzcode}
943
944
945 %%------------------------------------------------------------
946 \subsection{Inverse functions: \protect\cmd{\tzfn'}}
947 \label{ss:tzfn'}
948
949 The \iisw{swap version} \icmd{\tzfn'} draws the \iisw{inverse function} of |\tzfn|.
950
951 \begin{tztikz}
952 \tzfn'{.5*(\x)^2-1}[1:5] % works like:
953 \draw [samples=201,domain=1:5] plot ({.5*(\x)^2-1},\x);
954 \end{tztikz}
955
956 \begin{tzcode}{.3}
957 % \tzfn' : inverse function (with text)
958 \begin{tikzpicture}[scale=.5]
959 \tzhelplines(-2,-2)(5,5)
960 \tzaxes*(-2,-2)(5,5)
961 \tzfn{.5*(\x)^2-1}[0:3.5]
962 \tzfn'[red]{.5*(\x)^2-1}[0:3.5]{inversed}[r] %%
963 \end{tikzpicture}
964 \end{tzcode}
965
966 You can add text at the end of the graph,
967 by specifying |{<text>}| and |[<node opt>]| immediately after the domain.
968
969 \begin{tzcode}{.3}
970 % \tzfn(')
971 \begin{tikzpicture}[scale=.5]
972 \tzhelplines(8,8)
973 \tzaxes(8,8){$Q$}{$P$}
974 \tzfn{5-5/7*\x}[0:7]{demand}[a=5mm]
975 \tzfn'[blue]{5-5/7*\x}[0:7]
976 {inverse\\demand}[r=5mm,align=center]
977 \tzticks{5,7}{5,7}
978 \end{tikzpicture}
979 \end{tzcode}
980
981
982 \subsection{Define and name functions}
983
984 To use |\tzfn| you need to express a function as a function of |\x|.
985
986 \begin{tzcode}{.3}
987 % \tzfn
988 \begin{tikzpicture}[scale=.5]
989 \tzhelplines(8,8)
990 \tzaxes(8,8)
991 \def\Dx{7-\x} % define
992 \tzfn{\Dx}[0:7]{$D$}[ar]
993 \tzfn{1+\x}[0:7]{$S$}[blue,r]
994 \end{tikzpicture}
995 \end{tzcode}
996
997 You can also use the predefined functions of \Tikz\ such as |sin|, |cos|, |ln|, |log10|, |log2|, |exp|, |sqrt|, and so on. (See \Tikz\ manual.)
998
999 \begin{tzcode}{.3}
1000 % \tzfn
1001 \begin{tikzpicture}[scale=.5]
1002 \tzhelplines(-2,-2)(8,6)
1003 \tzaxes*(-2,-2)(8,6)
1004 \def\Fx{sin(\x r)+3}
1005 \def\Gx{exp(\x)}
1006 \def\Hx{ln(\x)}
1007 \tzfn\Fx[-2:2*pi]{$\sin\,x+3$}[blue,r]
1008 \tzfn[blue]\Gx[-2:2]{$e^x$}[red,r]
1009 \tzfn[dashed]\Hx[.2:7]{$\ln\,x$}[r]
1010 \end{tikzpicture}
1011 \end{tzcode}
1012
1013 \subsection{Name paths: \texttt{name path}}
1014 \label{ss:tzfn:namepath}
1015
1016 You can name the path of |\tzfn| by specifying the option |"<path name>"| \xem{immediately before} the mandatory argument |{<fn of \x>}|. You can use the path names to find intersection points.
1017
1018 \begin{tztikz}
1019 \tzfn"mypath"\Fx[1:5] % works like:
1020 \draw [samples=201,,domain=1:5,name path=mypath] plot (\x,{\Fx});
1021 \end{tztikz}
1022
1023 \remark Advantage of defining functions:
1024
1025 Suppose that the function's expression |<fn of \x>| consists \xem{only of a macro name}, say, |\Fx|. Then
1026
1027 \begin{itemize}\firmlist
1028 \item The macro name |Fx| (\xem{without the backslash}) is
1029 \xem{automatically assigned} to |<path name>|,
1030 unless you give another name.
1031 \item That is, |\tzfn\Fx| is equivalent to |\tzfn"Fx"\Fx|.
1032 (\xem{You don't need to type the same thing twice}.)
1033 \end{itemize}
1034
1035 \begin{tztikz}
1036 \tzfn\Fx[1:5] % works like:
1037 \draw [samples=201,domain=1:5,name path=Fx] plot (\x,{\Fx});
1038 \end{tztikz}
1039
1040 \begin{tzcode}{.3}
1041 % \tzfn: name path: intersection point
1042 \begin{tikzpicture}[scale=.5]
1043 \tzhelplines(8,8)
1044 \tzaxes(8,8)
1045 \def\Dx{7-\x}
1046 \def\Sx{1+\x}
1047 \tzfn"Dx"\Dx[0:7]{$D$}[ar] % name path = Dx
1048 \tzfn \Sx[0:7]{$S$}[blue,r] % name path = Sx
1049 \tzXpoint*{Dx}{Sx}(E){E} % intersection
1050 \end{tikzpicture}
1051 \end{tzcode}
1052
1053
1054
1055 \subsection{Move graphs: \texttt{shift}}
1056
1057 You can move the graph of |\tzfn| by specifying the option |<shift coor>| \xem{before} the mandatory argument |{<fn of \x>}| or \xem{immediately before} the option |"<path name>"|, if it exists.
1058 The \xem{empty} shift option |<>| is \xem{not allowed}.
1059
1060 \begin{tzcode}{.3}
1061 % \tzfn: shift
1062 \begin{tikzpicture}[scale=.6]
1063 \tzhelplines(8,8)
1064 \def\Dx{7-\x}
1065 \def\Sx{1+\x}
1066 \tzfn \Dx[0:7]{$D$}[right] % name path = Dx
1067 \tzfn"supply"\Sx[0:7]{$S$}[right] % name path = supply
1068 \tzXpoint*{Dx}{supply}(E){$E$}
1069 \tzfn[dashed]<1,1>"demandA"\Dx[0:7]{$D'$}[r]
1070 \tzfn[dashed]<1,-1>"supplyA"\Sx[0:7]{$S'$}[r]
1071 \tzXpoint*{demandA}{supplyA}(E1){$E'$}
1072 \end{tikzpicture}
1073 \end{tzcode}
1074
1075
1076 \subsection{Extend paths: \texttt{<code.append>}, \protect\cmd{\tzfnAtBegin}, \protect\cmd{\tzfnAtEnd}}
1077 \label{ss:tzfn:atbegin}
1078
1079 \paragraph{\texttt{<code.append>}}
1080 You can extend the path of |\tzfn|, by writing \Tikz\ code in the \xem{last optional argument} |<code.append>|. Internally it adds the \Tikz\ code to the path \xem{after} the options |{<text>}| and |[<node opt>]|.
1081
1082 \begin{tzcode}{.3}
1083 % \tzfn: <code.append>
1084 \begin{tikzpicture}[scale=.5]
1085 \tzhelplines(-2,-2)(8,6)
1086 \tzaxes*(-2,-2)(8,6)
1087 \def\Fx{sin(\x r)+3}
1088 \tzfn[->]\Fx[-2:2*pi]{$\sin\,x+3$}[blue,r]
1089 < to [bend right] ++(2,-2) node [b] {End!} >
1090 \end{tikzpicture}
1091 \end{tzcode}
1092
1093 \paragraph{\texttt{\bs tzfnAtEnd}}
1094 You can also extend the path of |\tzfn| at the end using \icmd{\tzfnAtEnd}.
1095 Internally it adds \Tikz\ code immediately \xem{before} the options |{<text>}| and |[<node opt>]|. But you have to use |\tzfnAtEnd| (immediately) \xem{before each} |\tzfn|.
1096
1097 \begin{tzcode}{.3}
1098 % \tzfnAtEnd (before \tzfn)
1099 \begin{tikzpicture}[scale=.5]
1100 \tzhelplines(-2,-2)(8,6)
1101 \tzaxes*(-2,-2)(8,6)
1102 \def\Fx{sin(\x r)+3}
1103 \tzfnAtEnd{to [bend right] ++(2,-2) node [b] {End!}}
1104 \tzfn[->]\Fx[-2:2*pi]{$\sin\,x+3$}[blue,r]
1105 \end{tikzpicture}
1106 \end{tzcode}
1107
1108 Specifying the option |<code.append>| extends the path after |\tzfnEnd| if it exists.
1109
1110 \begin{tzcode}{.3}
1111 % \tzfnAtEnd (before \tzfn)
1112 \begin{tikzpicture}[scale=.5]
1113 \tzhelplines(-2,-2)(8,6)
1114 \tzaxes*(-2,-2)(8,6)
1115 \def\Fx{sin(\x r)+3}
1116 \tzfnAtEnd{to [bend right] ++(2,-2) node [b] {End!}}
1117 \tzfn[->]\Fx[-2:2*pi]{$\sin\,x+3$}[blue,r]
1118 < arc (0:90:4cm) node [draw,red,left] {Here!!} >
1119 \end{tikzpicture}
1120 \end{tzcode}
1121
1122
1123 \paragraph{\texttt{\bs tzfnAtBegin}}
1124 You can use \icmd{\tzfnAtBegin} (immediately) \xem{before each} |\tzfn| to insert \Tikz\ code at the beginning of the path of |\tzfn|.
1125
1126 \begin{tzcode}{.3}
1127 % \tzfnAtBegin (before \tzfn)
1128 \begin{tikzpicture}[scale=.5]
1129 \tzhelplines(-2,-2)(8,6)
1130 \tzaxes*(-2,-2)(8,6)
1131 \def\Fx{sin(\x r)+3}
1132 \tzfnAtBegin{ (1,1) -| }
1133 \tzfn[->]\Fx[-2:2*pi]{$\sin\,x+3$}[blue,r]
1134 \end{tikzpicture}
1135 \end{tzcode}
1136
1137
1138
1139
1140 \remark
1141 \begin{itemize}\firmlist
1142 \item |\tzfn| is based on the |plot| operation of \Tikz.
1143 \item Appending \Tikz\ code at the beginning of |\tzfn| may cause a problem when you use some operations (such as |to| or \verb+-|+ or \verb+|-+) that expect a coordinate to link.
1144 \item In the version 2 of the |tzplot| package, this issue is internally taken care of by using
1145 |(|\ixxw{current subpath start}|)|, which is a special coordinate pre-defined in \Tikz. (See \Tikz\ manual for more details.)
1146 \end{itemize}
1147
1148
1149
1150 \section{\protect\cmd{\tzfnofy} and \protect\cmd{\tzfnofy'}: Functions of variable $y$}
1151 \label{ss:tzfnofy}
1152
1153 \icmd{\tzfnofy} plots a function of |\y|.
1154 Define a function with the (predefined) variable |\y|.
1155
1156 |\tzfnofy| works just like |\tzfn| but as a function of |\y|.
1157
1158 \begin{tzdef}
1159 % syntax: minimum
1160 \tzfnofy{<fn of \y>}[<domain>]
1161 % syntax: medium
1162 \tzfnofy{<fn of \y>}[<domain>]{<text>}[<pos>]
1163 % syntax: full
1164 \tzfnofy[<opt>]<shift coor>"<path name>"
1165 {<fn of \y>}[<domain>]{<text>}[<node opt>]<code.append>
1166 % [<domain>] should be of the form [<from num:to num>]
1167 % defaults
1168 [samples=201]<>""{<m>}[<m>]{}[]<>
1169 \end{tzdef}
1170
1171
1172
1173 \begin{tztikz}
1174 \tzfnofy{2*\y+1}[1:5] % works like:
1175 \draw [samples=201,domain=1:5,variable=\y] plot ({2*\y+1},\y);
1176 \end{tztikz}
1177
1178 The \iisw{swap version} \icmd{\tzfnofy'} plots the \iisw{inverse function} of |\tzfnofy|.
1179
1180 \begin{tztikz}
1181 \tzfnofy'{2*\y+1}[1:5] % works like:
1182 \draw [samples=201,domain=1:5,variable=\y] plot (\y,{2*\y+1});
1183 \end{tztikz}
1184
1185
1186 \begin{tzcode}{.3}
1187 % \tzfnofy('): variable = \y
1188 \begin{tikzpicture}[scale=.5]
1189 \tzhelplines(8,8)
1190 \tzaxes(8,8){$x$}{$y$}
1191 \tzfnofy{5-5/7*\y}[0:7]{$f(y)$}[r=5mm]
1192 \tzfnofy'[blue]{5-5/7*\y}[0:7]
1193 {$f^{-1}(y)$}[a=5mm,align=center]
1194 \tzticks{5,7}{5,7}
1195 \end{tikzpicture}
1196 \end{tzcode}
1197
1198 \begin{tzcode}{.3}
1199 % \tzfnofy: shift: intersections
1200 \begin{tikzpicture}[scale=.6]
1201 \tzhelplines(8,8)
1202 \def\Fy{7-\y}
1203 \def\Gy{1+\y}
1204 \tzfnofy\Fy[0:7]{$f(y)$}[right] % name path = Fy
1205 \tzfnofy\Gy[0:7]{$g(y)$}[right] % name path = Gy
1206 \tzXpoint*{Fy}{Gy}(E){$E$}
1207 \tzfnofy[dashed]<1,1>"Fyy"\Fy[0:7]{shifted}[r]
1208 \tzfnofy[dashed]<1,-1>"Gyy"\Gy[0:7]{shifted}[r]
1209 \tzXpoint*{Fyy}{Gyy}(E1){$E'$}
1210 \end{tikzpicture}
1211 \end{tzcode}
1212
1213 You can also extend the path of |\tzfnofy| using the option |<code.append>| or the macros \icmd{\tzfnofyAtBegin} and \icmd{\tzfnofyAtEnd}.
1214
1215
1216 \begin{tzcode}{.3}
1217 % \tzfnofy: shift: intersections
1218 \begin{tikzpicture}[scale=.5]
1219 \tzhelplines(8,8)
1220 \def\Fy{7/\y}
1221 \tzfnofyAtBegin{(6,3) node [a] {Start} to[bend left]}
1222 \tzfnofyAtEnd{ -| ++(3,-1) }
1223 \tzfnofy[->]\Fy[1:7]
1224 < to[bend right] ++(3,2) node [draw,r] {End!} >
1225 \end{tikzpicture}
1226 \end{tzcode}
1227
1228
1229
1230
1231 %%%\section{\protect\cmd{\tzdeffn} and \protect\cmd{\tzdeffnofy}}
1232 %%%\label{ss:tzdeffn}
1233 %%%
1234 %%%\icmd{\tzdeffn} defines a functions of |\x|.
1235 %%%
1236 %%%\icmd{\tzdeffnofy} defines a function of |\y|.
1237 %%%%%
1238 %%%%%These are redundant, since one can use |\def|.
1239 %%%%%
1240
1241
1242
1243
1244
1245 %%------------------------------------------------------------
1246 \section{Horizontal lines}
1247 \label{s:tzhfn}
1248
1249 \subsection{\protect\cmd{\tzhfnat}}
1250 \label{ss:tzhfnat}
1251
1252 \icmd{\tzhfnat} draws a horizontal line at a specified value of $y$.
1253
1254
1255 \begin{tzdef}
1256 % syntax: minimal
1257 \tzhfnat{<y-val>}[<domain>]
1258 % syntax: full
1259 \tzhfnat[<opt>]<shift coor>"<path name>"
1260 {<y-val>}[<domain>]{<text>}[<node opt>]<code.append>
1261 % defaults
1262 []<>""{<m>}[west:east (of current bounding box)]{}[]<>
1263 \end{tzdef}
1264
1265
1266 |\tzhfnat| accepts only one mandatory argument |{<y-val>}|.
1267 The domain is optional and should be of the form |[<from num:to num>]|.
1268 The default domain is from left to right of the \ixxw{current bounding box}.
1269
1270 \remark Internally, the default domain of |\tzhfnat| depends on the \ixxw{current bounding box}.
1271 \begin{itemize}
1272 \item Each |\tzhfnat| may draw a line with a (slightly) different length.
1273 \item If an appropriate |current bounding box| is not formed before |\tzhfnat| is executed, you will probably get an unexpected result.
1274 \item In that case, you can fix a |bounding box| in the beginning of the |tikzpicture| environment using macros such as \icmd{\tzbbox}, \icmd{\tzhelplines*}, \icmd{\tzaxes*}, or \Tikz's \icmd{\useasboundingbox}.
1275 \end{itemize}
1276
1277
1278 \begin{tzcode}{.3}
1279 % \tzhfnat
1280 \begin{tikzpicture}
1281 \tzhelplines(4,3)
1282 \tzhfnat[blue,thick]{0}
1283 \tzhfnat[red,thick]{1}[1:3]{line A}[r]
1284 \tzhfnat[blue]{2}{line B}[r]
1285 \tzhfnat[red]{3}[0:3]{line C}[draw=blue,red,r]
1286 \end{tikzpicture}
1287 \end{tzcode}
1288
1289 You can name the path of |\tzhfnat| by the option |"<path name>"|.
1290 You can move the line by the option |<shift coor>|.
1291 You can also extend the path from the end of the line by writing \Tikz\ code in the last optional argument |<code.append>|.
1292
1293 \begin{tzcode}{.3}
1294 % \tzhfnat: shift, <code.append>
1295 \begin{tikzpicture}
1296 \tzhelplines*(4,4) % bounding box
1297 \tzfn"XX"{\x}[0:4]
1298 \tzhfnat[blue,thick]{0}
1299 \tzhfnat[red,thick]<-.5,.5>"AA"{1}[1:3]{line A'}[r]
1300 \tzXpoint*{AA}{XX}
1301 \tzhfnat[blue,->]{2}{line B}[r]
1302 < arc (0:120:1.5) node [b,draw] {End!} >
1303 \end{tikzpicture}
1304 \end{tzcode}
1305
1306 You can also use \icmd{\tzhfnatAtBegin} and \icmd{\tzhfnatAtEnd} to extend the path of |\tzhfnat| at the beginning and at the end. Specifying the option |<code.append>| extends the path after |\tzhfnatAtEnd| if it exists.
1307 (See other examples of using |\tz<..>AtBegin| and |\tz<...>AtEnd|.)
1308
1309
1310 \subsection{\protect\cmd{\tzhfn}}
1311 \label{ss:tzhfn}
1312
1313 \icmd{\tzhfn} accepts a coordinate as a mandatory argument and draws a horizontal line at the $y$ value of the coordinate.
1314 For example, |\tzhfn(<x>,3)|, ignoring |<x>|, is equivalent to |\tzhfnat{3}|.
1315
1316 \xem{Everything else is the same as in} |\tzhfnat|.
1317
1318 \begin{tzdef}
1319 % syntax: minimal
1320 \tzhfn(<coor>)[<domain>]
1321 % syntax: full
1322 \tzhfn[<opt>]<shift coor>"<path name>"
1323 (<coor>)[<domain>]{<text>}[<node opt>]<code.append>
1324 % defaults
1325 []<>""(<m>)[west:east (of current bounding box)]{}[]<>
1326 \end{tzdef}
1327
1328 \begin{tzcode}{.3}
1329 % \tzhfn: shift, <code.append>
1330 \begin{tikzpicture}
1331 \tzhelplines*(4,4) % bounding box
1332 \tzcoors(0,1)(A)(0,2)(B);
1333 \tzfn"XX"{\x}[0:4]
1334 \tzhfn[blue,thick](5,0) % x=5 ignored
1335 \tzhfn[red,thick]<-.5,.5>"AA"(A)[1:3]{line A'}[r]
1336 \tzXpoint*{AA}{XX}
1337 \tzhfn[blue,->](B){line B}[r]
1338 < arc (0:120:1.5) node [b,draw] {End!} >
1339 \end{tikzpicture}
1340 \end{tzcode}
1341
1342 You can also use \icmd{\tzhfnAtBegin} and \icmd{\tzhfnAtEnd} to extend the path of |\tzhfn| at the beginning and at the end. Specifying the option |<code.append>| extends the path after |\tzhfnAtEnd| if it exists.
1343 (See other examples of using |\tz<..>AtBegin| and |\tz<...>AtEnd|.)
1344
1345
1346 %%------------------------------------------------------------
1347 \section{Vertical lines}
1348 \label{s:tzvfn}
1349
1350 \subsection{\protect\cmd{\tzvfnat}}
1351 \label{ss:tzvfnat}
1352
1353 \icmd{\tzvfnat} draws a vertical line at a specified value of $x$.
1354
1355 \begin{tzdef}
1356 % syntax: minimal
1357 \tzvfnat{<x-val>}[<domain>]
1358 % syntax: full
1359 \tzvfnat[<opt>]<shift coor>"<path name>"
1360 {<x-val>}[<domain>]{<text>}[<node opt>]<code.append>
1361 % defaults
1362 []<>""{<m>}[south:north (of current bounding box)]{}[]<>
1363 \end{tzdef}
1364
1365 |\tzvfnat| accepts only one mandatory argument |{<x-val>}|.
1366 The domain is optional and should be of the form |[<from num:to num>]|.
1367 The default domain is from bottom to top of the \ixxw{current bounding box}.
1368
1369
1370 \begin{tzcode}{.3}
1371 % \tzvfnat
1372 \begin{tikzpicture}
1373 \tzhelplines(4,4)
1374 \tzvfnat[blue,thick]{0}
1375 \tzvfnat[red,thick]{1}[1:3]{line A}[a]
1376 \tzvfnat[blue]{2}{line B}[a]
1377 \tzvfnat[red]{3}[0:3]{line C}[draw=blue,red,a]
1378 \end{tikzpicture}
1379 \end{tzcode}
1380
1381 You can name the path of |\tzvfnat| by the option |"<path name>"|.
1382 You can move the line by the option |<shift coor>|.
1383 You can also extend the path from the end of the line by writing \Tikz\ code in the last optional argument |<code.append>|.
1384
1385 \begin{tzcode}{.3}
1386 % \tzvfnat: shift, <code.append>
1387 \begin{tikzpicture}
1388 \tzhelplines*(4,4) % bounding box
1389 \tzfn"XX"{\x}[0:4]
1390 \tzvfnat[blue,thick]{0}
1391 \tzvfnat[red,thick]<.5,-.5>"AA"{1}[1:3]{line A'}[a]
1392 \tzXpoint*{AA}{XX}
1393 \tzvfnat[blue,->]{2}{line B}[a]
1394 < arc (90:-30:1.5) node [b,draw] {End!} >
1395 \end{tikzpicture}
1396 \end{tzcode}
1397
1398 In the previous example, |\tzhelplines*| is used to fix a bounding box. (See Section \ref{s:tzhelplines} on page \pageref{s:tzhelplines}, for more details.)
1399
1400 You can also use \icmd{\tzvfnatAtBegin} and \icmd{\tzvfnatAtEnd} to extend the path of |\tzvfnat| at the beginning and at the end. Specifying the option |<code.append>| extends the path after |\tzvfnatAtEnd| if it exists.
1401 (See other examples of using |\tz<..>AtBegin| and |\tz<...>AtEnd|.)
1402
1403 \subsection{\protect\cmd{\tzvfn}}
1404 \label{ss:tzvfn}
1405
1406 \icmd{\tzvfn} accepts a coordinate as a mandatory argument and draws a horizontal line at the $x$ value of the coordinate.
1407 For example, |\tzvfn(3,<y>)|, ignoring |<y>|, is equivalent to |\tzvfnat{3}|.
1408
1409 \xem{Everything else is the same as in} |\tzvfnat|.
1410
1411 \begin{tzdef}
1412 % syntax: minimal
1413 \tzvfn(<coor>)[<domain>]
1414 % syntax: full
1415 \tzvfn[<opt>]<shift coor>"<path name>"
1416 (<coor>)[<domain>]{<text>}[<node opt>]<code.append>
1417 % defaults
1418 []<>""(<m>)[south:north (of current bounding box)]{}[]<>
1419 \end{tzdef}
1420
1421 \begin{tzcode}{.3}
1422 % \tzvfn: shift, <code.append>
1423 \begin{tikzpicture}
1424 \tzhelplines*(4,4) % bounding box
1425 \tzcoors(1,0)(A)(2,0)(B);
1426 \tzfn"XX"{\x}[0:4]
1427 \tzvfn[blue,thick](0,5) % y=5 ignored
1428 \tzvfn[red,thick]<.5,-.5>"AA"(A)[1:3]{line A'}[a]
1429 \tzXpoint*{AA}{XX}
1430 \tzvfn[blue,->](B){line B}[a]
1431 < arc (90:-30:1.5) node [b,draw] {End!} >
1432 \end{tikzpicture}
1433 \end{tzcode}
1434
1435 You can also use \icmd{\tzvfnAtBegin} and \icmd{\tzvfnAtEnd} to extend the path of |\tzvfn| at the beginning and at the end. Specifying the option |<code.append>| extends the path after |\tzvfnAtEnd| if it exists.
1436 (See other examples of using |\tz<..>AtBegin| and |\tz<...>AtEnd|.)
1437
1438
1439
1440
1441
1442 %%==================================
1443 \chapter{Plot Linear Functions}
1444 \label{c:linearfunctions}
1445
1446
1447 %%------------------------------------------------------------
1448 \section{\protect\cmd{\tzLFn}: Plot linear functions}
1449 \label{s:tzLFn}
1450
1451 \subsection{\protect\cmd{\tzLFn} and \protect\cmd{\tzLFn'}}
1452
1453 Knowing two coordinates or one coordinate with a slope, you can draw a linear function with the macro \icmd{\tzLFn}, \xem{without writing the explicit definition of a linear function}.
1454
1455 \begin{itemize}%\firmlist
1456 \item
1457 |\tzLFn(<coor1>)(<coor2>)| is prepared for when you know two coordinates on a line.
1458 \begin{itemize}
1459 \item
1460 If you provide two points $(x_1,y_1)$ and $(x_2,y_2)$, |\tzLFnofy(x1,x2)(y1,y2)| draws the graph of $f(x)=\frac{y_2-y_1}{x_2-x_1}(x-x_1)+y_1$.
1461 \end{itemize}
1462
1463 \item
1464 |\tzLFn(<coor1>){<slope>}| is used when you know one coordinate and the slope of a line.
1465 \item
1466 If you specify all the three arguments |(<coor1>)(<coor2>){<slope>}|, then the slope is ignored.
1467 \end{itemize}
1468
1469 For example, |\tzLFn(1,1)(2,3)[0:4]| draws a line passing through two points: $(1,1)$ and $(2,3)$, over $0\leq x\leq 4$.
1470 |\tzLFn(1,1){.5}[0:4]| draws a line passing through a point $(1,1)$ with a slope |.5|, over $0\leq x\leq 4$.
1471
1472 |\tzLFn| accepts two mandatory arguments: |(<coor1>)| and |[<domain>]|.
1473 \begin{itemize}%\firmlist
1474 \item The \xem{domain} should be of the form |[<from num:to num>]|.
1475 \item If just one coordinate is specified without a slope, the slope is regarded as |1|, by default.
1476 \end{itemize}
1477
1478 \begin{tzdef}
1479 % syntax: minimum
1480 \tzLFn(<coor1>)(<coor2>)[<domain>] % two coordinates
1481 \tzLFn(<coor1>){<slope>)[<domain>] % one coordinate and slope
1482 % syntax: full
1483 \tzLFn[<opt>]<shift coor>"<path name>"
1484 (<coor1>)(<coor2>){<slope>}[<domain>]{<text>}[<node opt>]<code.append>
1485 % defaults
1486 []<>""(<m>)(){1}[<m>]{}[]<>
1487 \end{tzdef}
1488
1489
1490
1491 You can add text at the end of the line of |\tzLFn| by the options |{<text>}| and |[<node opt>]|. You can also name the path of |\tzLFn| by specifying the option |"<path name>"| \xem{immediately before} the mandatory coordinate.
1492
1493 \begin{tzcode}{.3}
1494 % \tzLFn: two coordinates
1495 \begin{tikzpicture}
1496 \tzhelplines(4,3)
1497 \tzcoors*(1,1)(A)(1,2)(B)(3,1)(C);
1498 \tzLFn[blue]"Gx"(B)(C)[0:4]{$g(x)$}[r]
1499 \end{tikzpicture}
1500 \end{tzcode}
1501
1502
1503 \begin{tzcode}{.3}
1504 % \tzLFn: one coordinate and slope
1505 \begin{tikzpicture}
1506 \tzhelplines(4,3)
1507 \tzcoors*(1,1)(A)(1,2)(B)(3,1)(C);
1508 \tzLFn[red]"Fx"(A){.5}[0:4]{$f(x)$}[a]
1509 \end{tikzpicture}
1510 \end{tzcode}
1511
1512 \remark If you inadvertently try an \xem{infinite slope}, you will get an \iisw{error message}.
1513
1514 \paragraph{Inverse function} The \iisw{swap version} \icmd{\tzLFn'} draws the \iisw{inverse function} of |\tzLFn|.
1515
1516 \begin{tzcode}{.3}
1517 % \tzLFn' : inverse function : intersection
1518 \begin{tikzpicture}[scale=.8]
1519 \tzhelplines(4,4)
1520 \tzcoors*(1,1)(A)(1,2)(B)(3,1)(C);
1521 \tzLFn'[red]"Fx"(A){.5}[0:4]{$f(x)$}[a]
1522 \tzLFn'[blue]"Gx"(B)(C)[0:4]{$g(x)$}[r]
1523 \tzXpoint*[fill=none]{Fx}{Gx}(E){$E$}(3pt)
1524 \end{tikzpicture}
1525 \end{tzcode}
1526
1527
1528 You can move the line of |\tzLFn| by specifying the option |<shift coor>| immediately before the option |"<path name>"|. (The \xem{empty} shift option |<>| is \xem{not allowed}.)
1529 You can also extend the path of |\tzLFn| by writing \Tikz\ code in the last optional argument |<code.append>|.
1530
1531 \begin{tzcode}{.3}
1532 % \tzLFn: shift, extending path
1533 \begin{tikzpicture}[scale=.8]
1534 \tzhelplines(4,4)
1535 \tzcoors*(1,1)(A)(1,2)(B)(3,1)(C);
1536 \tzLFn[blue]"Gx"(B)(C)[0:4]{$g(x)$}[r]
1537 \tzLFn[dashed,red,->]<1,1>"Gx"(B)(C)[0:4]{$g(x)$}[r]
1538 < arc (0:140:2) node [below] {End!} >
1539 \end{tikzpicture}
1540 \end{tzcode}
1541
1542 \icmd{\tzLFnAtBegin} and \icmd{\tzLFnAtEnd} are available to extend a path of |\tzLFn| at the beginning and and the end, respectively.
1543 Specifying the option |<code.append>| extends the path after |\tzLFnAtEnd|, if it exist.
1544
1545 \begin{tzcode}{.3}
1546 % \tzLFnAtBegin and \tzLFnAtEnd
1547 \begin{tikzpicture}[scale=.8]
1548 \tzhelplines*(4,4)
1549 \tzcoors*(1,1)(A)(1,2)(B)(3,1)(C);
1550 \tzLFn[blue]"Gx"(B)(C)[0:4]{$g(x)$}[r]
1551 \tzLFnAtBegin{(1,0) to [bend left] }
1552 \tzLFnAtEnd{ arc (0:140:2) }
1553 \tzLFn[dashed,red,->]<1,1>"Gx"(B)(C)[0:4]{$g(x)$}[r]
1554 \end{tikzpicture}
1555 \end{tzcode}
1556
1557
1558
1559 \subsection{\protect\cmd{\tzLFnofy} and \protect\cmd{\tzLFnofy'}}
1560
1561 \icmd{\tzLFnofy} draws a line as a function of |\y|.
1562 |\tzLFnofy| works just like |\tzLFn| but for the variable $y$.
1563 If you provide two points $(x_1,y_1)$ and $(x_2,y_2)$, |\tzLFnofy(x1,x2)(y1,y2)| draws the graph of $f(y)=\frac{x_2-x_1}{y_2-y_1}(y-y_1)+x_1$.
1564
1565 Everything else is the same as |\tzLFn|.
1566
1567 \begin{tzdef}
1568 % syntax: minimum
1569 \tzLFnofy(<coor1>)(<coor2>)[<domain>]
1570 \tzLFnofy(<coor1>){<slope>)[<domain>]
1571 % syntax: full
1572 \tzLFnofy[<opt>]<shift coor>"<path name>"
1573 (<coor1>)(<coor2>){<slope>}[<domain>]{<text>}[<node opt>]<code.append>
1574 % defaults
1575 []<>""(<m>)(){1}[<m>]{}[]<>
1576 \end{tzdef}
1577
1578 \begin{tzcode}{.3}
1579 % \tzLFnofy
1580 \begin{tikzpicture}[scale=.8]
1581 \tzhelplines(4,4)
1582 \tzcoors*(1,1)(A)(1,2)(B)(3,1)(C);
1583 \tzLFnofy[red]"Fx"(A){.5}[0:4]{$f(y)$}[a]
1584 \tzLFnofy[blue]"Gx"(B)(C)[.5:2.5]{$g(y)$}[a]
1585 \tzXpoint*[fill=none]{Fx}{Gx}(E){$E$}(3pt)
1586 \end{tikzpicture}
1587 \end{tzcode}
1588
1589 \remark If you inadvertently try an \xem{infinite slope}, you will get an \xem{error message}.
1590
1591 \paragraph{Inverse function}
1592 The \iisw{swap version} \icmd{\tzLFnofy'} draws the \iisw{inverse function} of |\tzLFnofy|.
1593
1594 \begin{tzcode}{.3}
1595 % \tzLFnofy'
1596 \begin{tikzpicture}[scale=.8]
1597 \tzhelplines(4,4)
1598 \tzcoors*(1,1)(A)(1,2)(B)(3,1)(C);
1599 \tzLFnofy'[red]"Fx"(A){.5}[0:4]{$f(y)$}[a]
1600 \tzLFnofy'[blue]"Gx"(B)(C)[.5:2.5]{$g(y)$}[r]
1601 \tzXpoint*[fill=none]{Fx}{Gx}(E){$E$}(3pt)
1602 \end{tikzpicture}
1603 \end{tzcode}
1604
1605
1606 You can use \icmd{\tzLFnofyAtBegin} and \icmd{\tzLFnofyAtEnd} to extend the path of |\tzLFnofy| at the beginning and at the end. Specifying the optional argument |<code.append>| extends the path after |\tzLFnofyAtEnd| if it exists.
1607 (See other examples of using |\tz<..>AtBegin| and |\tz<...>AtEnd|.)
1608
1609
1610 \section{\protect\cmd{\tzdefLFn}}
1611 \label{s:tzdefLFn}
1612
1613 \icmd{\tzdefLFn} simply defines a linear function $ax+b$ and saves it to a macro.
1614 You can use |\tzdefLFn| together with |\tzfn| to graph a linear function, \xem{without writing an explicit definition} of a linear function.
1615 (Of course, you can directly use |\tzLFn|.)
1616
1617 \begin{tzdef}
1618 % syntax
1619 \tzdefLFn{<fn csname>}(<coor1>)(<coor2>){<slope>}
1620 % defaults
1621 {<m>}(<m>)(){1}
1622 \end{tzdef}
1623
1624 If |(<coor2>)| is specified, |{<slope>}| is ignored.
1625 If |(<coor2>)| is missing |<slope>| is considered as the slope of the line (by default 1).
1626
1627 For example, |\tzdefLFn{\Gx}(1,1){.5}| defines as |\Gx| a linear function passing through the point $(1,2)$ with a slope |.5|.
1628 That is, it defines a function as $f(x)=.5(x-1)+1$.
1629 Knowing two coordinates, linear function |\Gx| passing through the two points can be defined, for example, by |\tzdefLFn{\Gx}(1,2)(3,1)|.
1630 That is, it defines a function as $g(x)=\frac{1-2}{3-1}(x-1)+2$.
1631
1632
1633 \begin{tztikz}
1634 \tzdefLFn{\Fx}(1,2)(3,1) % works like
1635 \def\Fx{-1/2*(\x-1)+2}
1636 \end{tztikz}
1637
1638 \remark If you inadvertently try an \xem{infinite slope}, you will get an \iisw{error message}.
1639
1640
1641 \begin{tzcode}{.3}
1642 % \tzdefLFn and \tzfn
1643 \begin{tikzpicture}
1644 \tzhelplines(4,4)
1645 \tzaxes(4,4){$x$}{$y$}
1646 \tzticks{1,2,3,4}{1,2,3,4}
1647 \tzcoors*(1,1)(A){A}[-90](1,2)(B){B}(3,1)(C){C}[45];
1648 \tzdefLFn\Fx(A){.5}
1649 \tzdefLFn\Gx(B)(C)
1650 \tzfn[red]\Fx[0:4]{$f(x)$}[r]
1651 \tzfn[blue]\Gx[0:4]{$g(x)$}[r]
1652 \end{tikzpicture}
1653 \end{tzcode}
1654
1655 \remark The swap version |\tzfn'| simply draws the graph of the inverse function of |\tzfn|.
1656 So |\tzfn'(A)(B)| and |\tzfn'(A){.5}| do not guarantee passing through the coordinate |(A)| or |(B)|.
1657
1658 \begin{tzcode}{.3}
1659 % \tzdefLFn and \tzfn'
1660 \begin{tikzpicture}
1661 \tzhelplines(4,4)
1662 \tzaxes(4,4){$x$}{$y$}
1663 \tzticks{1,2,3,4}{1,2,3,4}
1664 \tzcoors*(1,1)(A){A}[-90](1,2)(B){B}(3,1)(C){C}[45];
1665 \tzdefLFn\Fx(A){.5}
1666 \tzdefLFn\Gx(B)(C)
1667 \tzfn'[red]\Fx[0:4]{$f(x)$}[r]
1668 \tzfn'[blue]\Gx[0:4]{$g(x)$}[r]
1669 \end{tikzpicture}
1670 \end{tzcode}
1671
1672
1673
1674
1675
1676 %%------------------------------------------------------------
1677 \section{\protect\cmd{\tzdefLFnofy}}
1678 \label{s:tzdefLFnofy}
1679
1680 \icmd{\tzdefLFnofy} defines a function of |\y|.
1681
1682 \begin{tzdef}
1683 % syntax
1684 \tzdefLFnofy{<fn csname>}(<coor1>)(<coor2>){<slope>}
1685 % defaults
1686 {<m>}(<m>)(){1}
1687 \end{tzdef}
1688
1689 If |(<coor2>)| is specified, |{<slope>}| is ignored.
1690 If |(<coor2>)| is missing |<slope>| is considered as the slope of the line (by default 1).
1691
1692
1693 \begin{tztikz}
1694 \tzdefLFnofy\Fy(1,1){.5} % works like
1695 \def\Fy{.5*(\y-1)+1}
1696 \end{tztikz}
1697
1698 \begin{tztikz}
1699 \tzdefLFnofy\Gy(1,2)(3,1) % works like
1700 \def\Gy{-2*(\y-2)+1}
1701 \end{tztikz}
1702
1703
1704 \remark If you inadvertently try an \xem{infinite slope}, you will get an \xem{error message}.
1705
1706 You can use |\tzdefLFnofy| together with |\tzFnofy| to graph a linear function of $y$.
1707 (Of course, you can directly use |\tzLFnofy|.)
1708
1709
1710 \begin{tzcode}{.3}
1711 % \tzdefLFnofy and \tzLFnofy
1712 \begin{tikzpicture}
1713 \tzhelplines(4,4)
1714 \tzaxes*(4,4){$x$}{$y$}
1715 \tzticks{1,2,3,4}{1,2,3,4}
1716 \tzcoors*(1,1)(A){A}[-90](1,2)(B){B}(3,1)(C){C}[45];
1717 \tzdefLFnofy\Fy(A){.5}
1718 \tzdefLFnofy\Gy(B)(C)
1719 \tzfnofy[red]\Fy[0:4]{$f(y)$}[r]
1720 \tzfnofy[blue]\Gy[0:4]{$g(y)$}[a]
1721 \end{tikzpicture}
1722 \end{tzcode}
1723
1724 \remark The swap version |\tzfnofy'| simply draws the graph of the inverse function of |\tzfnofy|.
1725 So |\tzfnofy'(A)(B)| and |\tzfnofy'(A){.5}| do not guarantee passing through the coordinate |(A)| or |(B)|.
1726
1727 \begin{tzcode}{.3}
1728 % \tzdefLFnofy and \tzLFnofy'
1729 \begin{tikzpicture}
1730 \tzhelplines(4,4)
1731 \tzaxes*(4,4){$x$}{$y$}
1732 \tzticks{1,2,3,4}{1,2,3,4}
1733 \tzcoors*(1,1)(A){A}[-90](1,2)(B){B}(3,1)(C){C}[45];
1734 \tzdefLFnofy\Fy(A){.5}
1735 \tzdefLFnofy\Gy(B)(C)
1736 \tzfnofy'[red]\Fy[0:4]{$f(y)$}[r]
1737 \tzfnofy'[blue]\Gy[0:4]{$g(y)$}[r]
1738 \end{tikzpicture}
1739 \end{tzcode}
1740
1741
1742
1743 %%==================================
1744 \chapter{Some More Functions}
1745 \label{c:more-fn}
1746
1747 %%------------------------------------------------------------
1748 \section{\texttt{\bs tzpdfN(*)} and \texttt{\bs tzpdfZ}: Normal distributions}
1749 \label{s:normaldistributions}
1750
1751
1752 |\tzpdfN|, |\tzpdfN*| and |\tzpdfZ| are predefined functions to plot the \iisw{probability density function} (pdf) of a \iisw{normal distribution} $N(\mu,\sigma^2)$.
1753
1754 \paragraph{Normal distributions}
1755 \icmd{\tzpdfN} accepts two mandatory arguments, |{<mean>}| $\mu$ and |{<variance>}| $\sigma^2$, to define the pdf function:
1756 \[
1757 \frac{1}{\sigma\sqrt{2\pi}} e^{-\frac12\big(\frac{x-\mu}{\sigma}\big)^2}
1758 \]
1759
1760 \icmd{\tzpdfN*} uses a standard deviation $\sigma$ instead of a variance.
1761
1762 With these predefined functions together with |\tzfn| you can plot the pdf of normal distributions.
1763
1764 \begin{tzcode}{.3}
1765 % \tzpdfN, \tzpdfN*
1766 \begin{tikzpicture}[xscale=0.5,yscale=5,font=\scriptsize]
1767 \tzhelplines[ystep=0.1](-4,0)(6,.5)
1768 \tzaxes(-4,0)(6,.5)
1769 \tzticks{1,...,5}{0.1,0.2,0.3,0.4}
1770 \tzfn[blue]{\tzpdfN{0}{1.5}}[-4:4] % \tzpdfN
1771 \tzfn[red]{\tzpdfN*{2}{sqrt(1.5)}}[-2:6] % \tzpdfN*
1772 \end{tikzpicture}
1773 \end{tzcode}
1774
1775
1776
1777 \begin{tzcode}{.3}
1778 % \tzpdfN, \tzpdfN*
1779 \begin{tikzpicture}[x=0.5cm,y=5cm,font=\scriptsize]
1780 \tzhelplines[step=.5cm](-4,0)(6,.5)
1781 \tzaxes(-4,0)(6,.5)
1782 \tzticks{1,2,3}{0.1,0.2,0.3,0.4}
1783 \tzfn[blue]{\tzpdfN{0}{1.5}}[-4:4]
1784 \tzfn[red]{\tzpdfN*{2}{sqrt(1.5)}}[-2:6]
1785 \end{tikzpicture}
1786 \end{tzcode}
1787
1788 \remark
1789 If |tikzpicture| is scaled when plotting the inverse function using |\tzfn'|, you may want to change the scale accordingly.
1790
1791 \begin{tzcode}{.3}
1792 % \tzpdfN and \tzfn'
1793 \begin{tikzpicture}[x=0.5cm,y=5cm,,font=\scriptsize]
1794 \tzhelplines[step=0.5cm](-4,-.3)(6,.5)
1795 \tzaxes(-4,-.3)(6,.5)
1796 % scale change
1797 \begin{scope}[xscale={1/0.5*5},yscale={1/5*0.5}]
1798 \tzfn'[blue]{\tzpdfN{0}{1.5}}[-4:4]
1799 \tzfn'[red]{\tzpdfN*{2}{sqrt(1.5)}}[-2:6]
1800 \end{scope}
1801 \end{tikzpicture}
1802 \end{tzcode}
1803
1804 \paragraph{Standard normal distributions}
1805 \icmd{\tzpdfZ} (with no arguments) represents the pdf of the \xem{standard normal distribution}.
1806
1807 \begin{tzcode}{.3}
1808 % \tzpdfZ: shift
1809 \begin{tikzpicture}[x=0.5cm,y=5cm,font=\scriptsize]
1810 \tzhelplines[step=0.5cm](-4,0)(6,.5)
1811 \tzaxes(-4,0)(6,.5)
1812 \tzticks{1,...,5}{0.1,0.2,0.3,0.4}
1813 \tzfn[blue]{\tzpdfZ}[-3:3] % \tzpdfZ
1814 \tzfn[red]<2,0>{\tzpdfZ}[-3:3] % shift
1815 \tzfn[dashed]<3,.1>{\tzpdfZ}[-3:3] % shift
1816 \end{tikzpicture}
1817 \end{tzcode}
1818
1819
1820
1821
1822 %%------------------------------------------------------------
1823 \section{\protect\cmd{\tzfnarea(*)}: Fill under the graph}
1824
1825
1826 \subsection{\protect\cmd{\tzfnarea(*)}}
1827
1828 \icmd{\tzfnarea} fills the area between the graph of a function and the x axis, with a color or pattern, on the |behind| layer by default.
1829 With \icmd{\settzfnarealayer}, you can change the layer of |\tzfnarea|.
1830
1831 |\tzfnarea| accepts two mandatory arguments: |{<fn of \x>}| and |[<domain>]|, like |\tzfn|.
1832
1833 \begin{tzdef}
1834 % syntax: minimum
1835 \tzfnarea{<fn of \x>}[<domain>]
1836 % syntax: full
1837 \tzfnarea[<opt>]{<fn of \x>}[<domain>]{<fill opacity>}<code.append>
1838 % defaults
1839 []{<m>}[<m>]{.3}<>
1840 \end{tzdef}
1841
1842 \begin{tzcode}{.3}
1843 % \tzfnarea
1844 \begin{tikzpicture}
1845 \tzhelplines(0,-1)(4,2)
1846 \tzaxes(0,-1)(4,2)
1847 \def\Fx{.5*(\x-1)^2-1}
1848 \tzfn[very thick]\Fx[0:3.5]
1849 \tzfnarea[fill=red]\Fx[1:3] %
1850 \end{tikzpicture}
1851 \end{tzcode}
1852
1853 \begin{tzcode}{.3}
1854 % \tzfnarea: layer: comparison
1855 \begin{tikzpicture}
1856 \tzhelplines(0,-1)(4,2)
1857 \settzfnarealayer{main} %%
1858 \tzaxes(0,-1)(4,2)
1859 \def\Fx{.5*(\x-1)^2-1}
1860 \tzfn[very thick]\Fx[0:3.5]
1861 \tzfnarea[fill=red]\Fx[1:3] %
1862 \end{tikzpicture}
1863 \end{tzcode}
1864
1865
1866 The starred version \icmd{\tzfnarea*} fills the area with |fill=black!50| and |fill opacity=.3|, and |text opacity=1|, by default. The default values can be changed by |\settzfillcolor|, |\settzfillopacity|, and the option |{<fill opacity>}|.
1867
1868 \begin{tzcode}{.3}
1869 % \tzfnarea*
1870 \begin{tikzpicture}[x=0.5cm,y=5cm,font=\scriptsize]
1871 \tzhelplines[step=.5cm](-4,-.1)(6,.5)
1872 \tzaxes(-4,-.1)(6,.5)
1873 \tzfn[blue]{\tzpdfZ}[-3:3]
1874 \tzfnarea*{\tzpdfZ}[-3:1]
1875 \tzfn"AA"{\tzpdfN21}[-1:5]
1876 \tzfnarea*[pattern=north east lines]{\tzpdfN21}[1:3]
1877 \end{tikzpicture}
1878 \end{tzcode}
1879
1880
1881 \begin{tzcode}{.3}
1882 % \tzfnarea*: default change and <code.append>
1883 \begin{tikzpicture}
1884 \settzfnarealayer{main} %
1885 \tzhelplines(0,-1)(4,2)
1886 \tzaxes(0,-1)(4,2)
1887 \def\Fx{.5*(\x-1)^2-1}
1888 \tzfn\Fx[0:3.5]
1889 \tzfnarea*[red]\Fx[1:3]{.1}
1890 <(2,-1) node[black]{Area}>
1891 \end{tikzpicture}
1892 \end{tzcode}
1893
1894
1895 \begin{tzcode}{.3}
1896 % \tzfnarea*
1897 \begin{tikzpicture}
1898 \tzhelplines(0,-2)(4,3)
1899 \tzaxes(0,-2)(4,3){$x$}{$y$}
1900 \def\Fx{.5*(\x-1)^2-1}
1901 \tzfn\Fx[0:3.5]{$f(x)$}[a]
1902 \tzfnarea*[red]\Fx[1:3]
1903 \tzvXpointat{Fx}{1}(A)
1904 \tzvXpointat{Fx}{3}(B)
1905 \tzline[blue,thick](A)(A|-0,0)
1906 \tzline[very thick](B)(B|-0,0)
1907 \end{tikzpicture}
1908 \end{tzcode}
1909
1910
1911 \subsection{\protect\cmd{\tzfnarealine(')}}
1912
1913 \icmd{\tzfnarealine} draws one or two boundary lines of |\tzfnarea| using |\tzto|, on the |behind| layer by default. The layer can be changed by \icmd{\settzfnarealayer}.
1914 It takes two mandatory arguments: |{<path>}| and |{<x1>}|.
1915 \begin{itemize}\firmlist
1916 \item |\tzfnarealine{<path>}{<x1>}| draws a vertical line to the $x$ axis at |<x1>|.
1917 \item |\tzfnarealine{<path>}{<x1>}{<x2>}| draws two vertical lines at |<x1>| and |<x2>|.
1918 \end{itemize}
1919
1920 The first option |[<opt>]| controls both lines and is overwritten by each of |[<opt1>]| (for the line at |<x1>|) and |[<opt2>]| (for the line at |<x2>|).
1921 The line width is |very thin| by default, which can be changed by \icmd{\settzfnarealinestyle}.
1922
1923 You can also change the length of lines by specifying |(<coor1>)| and |(<coor2>)|.
1924
1925 \begin{tzdef}
1926 % syntax: minimum
1927 \tzfnarealine{<path>}{<x1>}
1928 % syntax: minimal
1929 \tzfnarealine{<path>}{<x1>}{<x2>}
1930 % syntax: medium
1931 \tzfnarealine{<path>}{<x1>}[<opt1>]{<x2>}[<opt2>]
1932 % syntax: full
1933 \tzfnarealine[<opt>]{<path>}{<x1>}[<opt1>](<coor1>)
1934 {<x2>}[<opt2>](<coor2>)
1935 % defaults:
1936 [very thin]{<m>}{<m>}[](0,0){}[](0,0)
1937 \end{tzdef}
1938
1939
1940 \begin{tzcode}{.3}
1941 % \tzfnarealine
1942 \begin{tikzpicture}[x=0.5cm,y=5cm,font=\scriptsize]
1943 \tzhelplines[step=.5cm](-4,-.1)(6,.5)
1944 \tzaxes(-4,-.1)(6,.5)
1945 \tzfn"AA"{\tzpdfN21}[-1:5]
1946 \tzfnarea*[pattern=north east lines]{\tzpdfN21}[1:3]
1947 \tzfnarealine[red]{AA}{1}{3} %%
1948 \end{tikzpicture}
1949 \end{tzcode}
1950
1951 \begin{tzcode}{.3}
1952 % \tzfnarealine: one line
1953 \begin{tikzpicture}
1954 \tzhelplines(0,-1)(4,2)
1955 \tzaxes(0,-1)(4,2)
1956 \def\Fx{.5*(\x-1)^2-1}
1957 \tzfn\Fx[0:3.5]
1958 \tzfnarea*[red]\Fx[1:3]{.1}<(2,-1) node[black]{Area}>
1959 \tzfnarealine[blue]{Fx}{3}
1960 \end{tikzpicture}
1961 \end{tzcode}
1962
1963 \begin{tzcode}{.3}
1964 % \tzfnarealine: two lines
1965 \begin{tikzpicture}
1966 \tzhelplines(0,-1)(4,2)
1967 \tzaxes(0,-1)(4,2)
1968 \def\Fx{.5*(\x-1)^2-1}
1969 \tzfn\Fx[0:3.5]
1970 \tzfnarea*[red]\Fx[1:3]{.1}<(2,-1) node[black]{Area}>
1971 \tzfnarealine[blue,thick]{Fx}{1}{3}[very thick,red]
1972 \end{tikzpicture}
1973 \end{tzcode}
1974
1975 The \xem{swap version} \icmd{\tzfnarealine'} draws one or two horizontal lines from the point $(x_i,f(x_i))$ to the $y$ axis.
1976 Everything else is the same as in |\tzfnarealine|.
1977
1978 \begin{tzcode}{.3}
1979 % \tzfnarealine'
1980 \begin{tikzpicture}
1981 \tzhelplines(0,-1)(4,2)
1982 \settzfnarealinestyle{thick}
1983 \tzaxes(0,-1)(4,2)
1984 \def\Fx{.5*(\x-1)^2-1}
1985 \tzfn\Fx[0:3.5]
1986 \tzfnarea*[blue]\Fx[1:3]{.1}<(2,-1) node[black]{Area}>
1987 \tzfnarealine'[->,red]{Fx}{2}{3}
1988 \end{tikzpicture}
1989 \end{tzcode}
1990
1991
1992 %%------------------------------------------------------------
1993 \section{Envelope curves}
1994 \label{s:evelopecurves}
1995
1996
1997 %%------------------------------------------------------------
1998 \subsection{\protect\cmd{\tzfnmax}: Upper envelope curves}
1999 \label{ss:tzfnmax}
2000
2001 \icmd{\tzfnmax} plots the maximum of a list of functions, that is, an \xem{upper} \iisw{envelope curve}. The first mandatory argument should be a comma separated list of functions.
2002 The second mandatory argument |[<domain>]| should be colon separated.
2003
2004 The default line width of |\tzfnmax| is |thick|.
2005
2006 \begin{tzdef}
2007 % syntax: minimum
2008 \tzfnmax{<fn list>}[<domain>]
2009 % syntax: full
2010 \tzfnmax[<opt>]<shift coor>"<path name>"
2011 {<fn list>}[<domain>]{<text>}[<node opt>]<code.append>
2012 % remark:
2013 - {<fn list>} should be comma separated
2014 - [<domain>] should be of the form [<from num:to num>]
2015 % defaults
2016 [thick,samples=201]<>""{<m>}[<m>]{}[]<>
2017 \end{tzdef}
2018
2019
2020 \begin{tzcode}{.3}
2021 % \tzfnmax
2022 \begin{tikzpicture}
2023 \tzhelplines*(4,4)
2024 \def\Fx{\x}
2025 \def\Gx{.5*\x+.5}
2026 \def\Hx{-.25*\x+2}
2027 \tzfn{\Fx}[0:4] \tzfn{\Gx}[0:4] \tzfn{\Hx}[0:4]
2028 \tzfnmax[blue]{\Fx,\Gx,\Hx}[0:4]{upper envelope}[l]
2029 \end{tikzpicture}
2030 \end{tzcode}
2031
2032 \remark If you want sharp corners at kinked points, you may need to select an appropriate number of sample points, which is |samples=201|, by default. You can try an odd number.
2033 \remarkafterskip
2034
2035 If you want, you can shift and extend path using the option |<shift coor>| and |<code.append>|, respectively.
2036 You can also use \icmd{\tzfnmaxAtBegin} and \icmd{\tzfnmaxAtEnd} to extend the path of |\tzfnmax| at the beginning and at the end, respectively.
2037
2038 \begin{tzcode}{.3}
2039 % shift, <code.append>
2040 \begin{tikzpicture}
2041 \tzhelplines*(4,5)
2042 \def\Fx{\x}
2043 \def\Gx{.5*\x+.5}
2044 \def\Hx{-.25*\x+2}
2045 \tzfn{\Fx}[0:4] \tzfn{\Gx}[0:4] \tzfn{\Hx}[0:4]
2046 \tzfnmax[blue,thick]{\Fx,\Gx,\Hx}[0:4]
2047 \tzfnmaxAtBegin{ (-1,0) -- }
2048 \tzfnmax[dashed]<0,.5>{\Fx,\Gx,\Hx}[0:4]
2049 < to[bend left] ++ (1,-1) >
2050 \end{tikzpicture}
2051 \end{tzcode}
2052
2053
2054 %%------------------------------------------------------------
2055 \subsection{\protect\cmd{\tzfnmin}: Lower envelope curves}
2056 \label{ss:tzfnmin}
2057
2058 \icmd{\tzfnmin} plots the minimum of a list of functions.
2059 |\tzfnmin| works just like |\tzfnmax|, but it draws a \xem{lower} \iisw{envelope curve}.
2060
2061 \begin{tzdef}
2062 % syntax: minimum
2063 \tzfnmin{<fn list>}[<domain>]
2064 % syntax: full
2065 \tzfnmin[<opt>]<shift coor>"<path name>"
2066 {<fn list>}[<domain>]{<text>}[<node opt>]<code.append>
2067 % remark:
2068 - {<fn list>} should be comma separated
2069 - [<domain>] should be of the form [<from num:to num>]
2070 % defaults
2071 [thick,samples=201]<>""{<m>}[<m>]{}[]<>
2072 \end{tzdef}
2073
2074
2075 \begin{tzcode}{.3}
2076 % \tzfnmin, \tzfnmax: name path: intersection
2077 \begin{tikzpicture}
2078 \tzhelplines(4,6)
2079 \def\Fx{\x}
2080 \def\Gx{.5*(\x)^2}
2081 \def\Hx{-.25*\x+2}
2082 \tzfn{\Fx}[0:4]{$f(x)$}[r]
2083 \tzfn{\Gx}[0:3]{$g(x)$}[r]
2084 \tzfn{\Hx}[0:4]{$h(x)$}[r]
2085 \tzfnmin[samples=2001,blue,thick]"XX" %%
2086 {\Fx,\Gx,\Hx}[0:4]{lower evelope}[bl]
2087 \tzvXpointat*{XX}{3}
2088 \tzfnmax[samples=201,red,thick]"YY" %%
2089 {\Fx,\Gx,\Hx}[0:3]{upper envelope}[bl]
2090 \tzvXpointat*[fill=none]{YY}{2.5} %%
2091 \end{tikzpicture}
2092 \end{tzcode}
2093
2094 \remark If you want sharp corners at kinked points, you may need to select appropriate number of sample points. Try odd number.
2095
2096 To extend the path of |\tzfnmin|, you can use the option |<code.append>| or the macros \icmd{\tzfnminAtBegin} and \icmd{\tzfnminAtEnd}.
2097
2098
2099
2100
2101
2102
2103 %%==================================
2104 \chapter{Intersections}
2105 \label{c:intersections}
2106
2107 %%------------------------------------------------------------
2108 \section{\protect\cmd{\tzXpoint(*)}: Intersection points}
2109 \label{s:intersections}
2110
2111 \icmd{\tzXpoint} finds \iisw{intersection} points of two paths and saves them as coordinate names for later use.
2112
2113 \begin{tzdef}
2114 % syntax: minimal
2115 \tzXpoint{<path>}{<path>}(<coor name>)
2116 % syntax: medium
2117 \tzXpoint{<path>}{<path>}(<coor name>){<label>}[<angle>]
2118 % syntax: full
2119 \tzXpoint[<opt>]{<path>}{<path>}(<coor name>)[<nth>]{<label>}[<[label opt]angle>]
2120 % defaults
2121 []{<m>}{<m>}(intersection)[1]{}[]
2122 \end{tzdef}
2123
2124 For example, |\tzXpoint{path1}{path2}(A)| determines an intersection of the two paths and names the point |(A)| or |(A-1)|. (By default, the name is |(intersection)| as in \Tikz.)
2125 If there are two or more intersection points, they are named as follows: |(A)=(A-1)|, |(A-2)|, |(A-3)|, etc.
2126
2127 You can determine which intersection point is named directly by specifying the option |[<nth>]|. If you select the second intersection point to be named |(A)| out of multiple intersections, they are named as follows: |(A-1)|, |(A)=(A-2)|, |(A-3)|, |(A-4)|, etc.
2128 You can label intersection points by specifying the option |{<label>}| and |[<angle>]|.
2129
2130
2131 \begin{tzcode}{.3}
2132 % \tzXpoint
2133 \begin{tikzpicture}[scale=.5]
2134 \tzhelplines(8,8)
2135 \tzaxes(8,8)
2136 \tzto[red,bend right]"AA"(1,8)(8,1)
2137 \tzto[blue,bend right]"BB"(0,2)(8,6)
2138 \tzXpoint{AA}{BB}(A)
2139 \tzdot*(A)
2140 \end{tikzpicture}
2141 \end{tzcode}
2142
2143 \warning When using |\tzXpoint|, the intersection of two paths must actually exist.Otherwise, an error will occur when using coordinates.
2144
2145 \paragraph{\icmd{\tzXpoint*}} The starred version |\tzXpoint*| simply adds a node dot to |\tzXpoint|.
2146 The default dot size is |2.4pt| and it can be changed by the last option |(<dot size>)| or the \threeways\ (on page \pageref{ss:threeways}).
2147
2148 \begin{tzdef}
2149 % syntax: minimum
2150 \tzXpoint*{<path>}{<path>}
2151 % syntax: medium
2152 \tzXpoint*{<path>}{<path>}(<coor name>){<label>}[<angle>]
2153 % syntax:
2154 \tzXpoint*[<opt>]{<path>}{<path>}
2155 (<coor name>)[<nth>]{<label>}[<[label opt]angle>](<dot size>)
2156 % defaults
2157 [tzdot=2.4pt]{<m>}{<m>}(intersection)[1]{}[](2.4pt)
2158 \end{tzdef}
2159
2160
2161 \begin{tzcode}{.3}
2162 % \tzXpoint*
2163 \begin{tikzpicture}[scale=.5]
2164 \tzhelplines(10,10)
2165 \tzaxes(10,10)
2166 \def\bgt{8-\x}
2167 \def\Fx{\x}
2168 \def\IC{7/\x}
2169 \tzfn\bgt[0:8] % name path=bgt
2170 \tzfn\Fx[0:8]{ray}[red,ar] % name path=Fx
2171 \tzfn"IC"\IC[.8:8]{$u$}[r] % name path=IC
2172 \tzXpoint*{bgt}{Fx}(A){A}[[draw,red] r] % <angle> or % abb
2173 \tzproj[dashed](A){$x$}{$y$}
2174 \tzXpoint*[fill=none,red]{bgt}{IC}(B){B}[0](4pt)
2175 \tzdot*[blue](B-2){B2}[[red]45](4pt)
2176 \end{tikzpicture}
2177 \end{tzcode}
2178
2179
2180 %%------------------------------------------------------------
2181 \section{Vertical intersection points}
2182 \label{s:tzvXpointat}
2183
2184 \subsection{\protect\cmd{\tzvXpointat(*)}}
2185 \label{ss:tzvXpointat}
2186
2187 \icmd{\tzvXpointat} determines \iisw{vertical intersection} points of a path at a specified value of $x$.
2188 So it takes |{<path>}| and |{<x-val>}| as mandatory arguments.
2189
2190 \remark
2191 Internally, |\tzvXpointat| depends on the |current bounding box|, which generally does not cause a problem because it is used after paths to be intersected are formed.
2192 In case of any problem of no intersection point, you may want to fix a bounding box using |\tzbbox| or |\tzaxes*| or \Tikz's |\useasboundingbox|.
2193
2194 \begin{tzdef}
2195 % syntax: minimal
2196 \tzvXpointat{<path>}{<x-val>}(<coor name>)
2197 % syntax: medium
2198 \tzvXpointat{<path>}{<x-val>}(<coor name>){<label>}[<angle>]
2199 % syntax: full
2200 \tzvXpointat[<opt>]{<path>}{<x-val>}(<coor name>)[<n>]
2201 {<label>}[<[label opt]angle>]
2202 % defaults
2203 []{<m>}{<m>}(intersection)[1]{}[]
2204 \end{tzdef}
2205
2206 The starred version \icmd{\tzvXpointat*} additionally prints a node dot of the size |2.4pt|, by default, at the (first) intersection point.
2207
2208 \begin{tzdef}
2209 % syntax: minimum
2210 \tzvXpointat*{<path>}{<x-val>}
2211 % syntax: medium
2212 \tzvXpointat*{<path>}{<x-val>}(<coor name>){<label>}[<angle>]
2213 % syntax: full
2214 \tzvXpointat*[<opt>]{<path>}{<x-val>}(<coor name>)[<n>]
2215 {<label>}[<[label opt]angle>](<dot size>)
2216 % defaults
2217 [tzdot=2.4pt]{<m>}{<m>}(intersection)[1]{}[](2.4pt)
2218 \end{tzdef}
2219
2220 \begin{tzcode}{.3}
2221 % \tzvXpointat(*)
2222 \begin{tikzpicture}
2223 \tzhelplines(4,3)
2224 \def\Fx{.5*(\x-2)^2}
2225 \tzfn\Fx[0:4] % name path=Fx
2226 \tzvfnat[dashed]{1}
2227 \tzvXpointat{Fx}{1}(A)
2228 \tzdot(A){A}[45]
2229 \tzvXpointat*{Fx}{3.2}{B}[[red,draw]br]
2230 \end{tikzpicture}
2231 \end{tzcode}
2232
2233
2234 %%------------------------------------------------------------
2235 \subsection{\protect\cmd{\tzvXpoint(*)}}
2236 \label{ss:tzvXpoint}
2237
2238 \icmd{\tzvXpoint} accepts |{<path>}| and |(<coor>)| as mandatory arguments to find \iisw{vertical intersection} points of a path at the $x$ value of the coordinate, ignoring the $y$ value.
2239 For example, |\tzvXpoint{mypath}(3,<y>)|, ignoring |<y>|, is equivalent to |\tzvXpointat{mypath}{3}|.
2240
2241 \xem{Everything else is the same as in} |\tzvXpointat|.
2242
2243 \begin{tzdef}
2244 % syntax
2245 \tzvXpoint[<opt>]{<path>}(<coor>)(<coor name>)[<n>]
2246 {<label>}[<[label opt]angle>]
2247 % defaults
2248 []{<m>}(<m>)(intersection)[1]{}[]
2249 \end{tzdef}
2250
2251 The starred version \icmd{\tzvXpoint*} just adds a node dot to |\tzvXpoint|.
2252
2253 \begin{tzdef}
2254 % syntax
2255 \tzvXpoint*[<opt>]{<path>}(<coor>)(<coor name>)[<n>]
2256 {<label>}[<[<opt>]angle>](<dot size>)
2257 % defaults
2258 [tzdot=2.4pt]{<m>}(<m>)(intersection)[1]{}[](2.4pt)
2259 \end{tzdef}
2260
2261 |\tzvXpoint*| prints, at the first intersection point, a node dot of the size 2.4pt by default.
2262
2263 \begin{tzcode}{.3}
2264 % \tzvXpoint(*)
2265 \begin{tikzpicture}
2266 \tzhelplines(4,3)
2267 \def\Fx{.5*(\x-2)^2}
2268 \tzfn\Fx[0:4] % name path=Fx
2269 \tzcoors(1,0)(A)(3.2,0)(B);
2270 \tzvfn[dashed](1,0)
2271 \tzvXpoint{Fx}(A)(Ax)
2272 \tzdot(Ax){Ax}[45]
2273 \tzvXpoint*{Fx}(B){B}[[red,draw]br] % abb
2274 \end{tikzpicture}
2275 \end{tzcode}
2276
2277
2278
2279 %%------------------------------------------------------------
2280 \section{Horizontal intersection points}
2281 \label{s:tzhXpointat}
2282
2283 \subsection{\protect\cmd{\tzhXpointat(*)}}
2284 \label{ss:tzhXpointat}
2285
2286 \icmd{\tzhXpointat} determines \iisw{horizontal intersection} points of a path at a specified value of $y$.
2287 So it takes |{<path>}| and |{<y-val>}| as mandatory arguments.
2288
2289 \begin{tzdef}
2290 % syntax: minimal
2291 \tzhXpointat{<path>}{<y-val>}(<coor name>)
2292 % syntax: medium
2293 \tzhXpointat{<path>}{<y-val>}(<coor name>){<label>}[<angle>]
2294 % syntax: full
2295 \tzhXpointat[<opt>]{<path>}{<y-val>}(<coor name>)[<n>]{<label>}[<[label opt]angle>]
2296 % defaults
2297 []{<m>}{<m>}(intersection)[1]{}[]
2298 \end{tzdef}
2299
2300
2301 The starred version \icmd{\tzhXpointat*} additionally prints a node dot of the size 2.4pt, by default, at the intersection point.
2302
2303 \begin{tzdef}
2304 % syntax: minimum
2305 \tzhXpointat*{<path>}{<y-val>}
2306 % syntax: medium
2307 \tzhXpointat*{<path>}{<y-val>}(<coor name>){<label>}[<angle>]
2308 % syntax: full
2309 \tzhXpointat*[<opt>]{<path>}{<y-val>}(<coor name>)[<n>]
2310 {<label>}[<[label opt]angle>](<dot size>)
2311 % defaults
2312 [tzdot=2.4pt]{<m>}{<m>}(intersection)[1]{}[](2.4pt)
2313 \end{tzdef}
2314
2315 \begin{tzcode}{.3}
2316 % \tzhXpointat(*)
2317 \begin{tikzpicture}
2318 \tzhelplines*(4,3)
2319 \def\Fx{.5*(\x-2)^2}
2320 \tzfn\Fx[0:4] % name path=Fx
2321 \tzhXpointat{Fx}{1}(A)
2322 \tzdot(A){A}[0]
2323 \tzhfnat[dashed]{1.5}
2324 \tzhXpointat*{Fx}{1.5}(X){X}[45]
2325 \tzdot*(X-2){Y}[[red,draw]al] % abb
2326 \end{tikzpicture}
2327 \end{tzcode}
2328
2329 %%------------------------------------------------------------
2330 \subsection{\protect\cmd{\tzhXpoint(*)}}
2331 \label{ss:tzhXpoint}
2332
2333 \icmd{\tzhXpoint} accepts |{<path>}| and |(<coor>)| as mandatory arguments to find \iisw{horizontal intersection} points of a path at the $y$ value of the coordinate, ignoring the $x$ value.
2334 For example, |\tzhXpoint{mypath}(<x>,3)|, ignoring |<x>|, is equivalent to |\tzhXpointat{mypath}{3}|.
2335
2336 \xem{Everything else is the same as in} |\tzhXpointat|.
2337
2338 \begin{tzdef}
2339 % syntax
2340 \tzhXpoint[<opt>]{<path>}(<coor>)(<coor name>)[<n>]{<label>}[<[label opt]angle>]
2341 % defaults
2342 []{<m>}(<m>)(intersection)[1]{}[]
2343 \end{tzdef}
2344
2345 The starred version \icmd{\tzhXpoint*} just adds a node dot to |\tzhXpoint|.
2346
2347 \begin{tzdef}
2348 % syntax
2349 \tzhXpoint*[<opt>]{<path>}(<coor>)(<coor name>)[<n>]
2350 {<label>}[<[label opt]angle>](<dot size>)
2351 % defaults
2352 [tzdot=2.4pt]{<m>}(<m>)(intersection)[1]{}[](2.4pt)
2353 \end{tzdef}
2354
2355 |\tzhXpoint*| prints, at the (first) intersection point, a node dot of the size |2.4pt|, by default.
2356
2357 \begin{tzcode}{.3}
2358 % \tzhXpoint(*)
2359 \begin{tikzpicture}
2360 \tzhelplines*(4,3)
2361 \def\Fx{.5*(\x-2)^2}
2362 \tzfn\Fx[0:4] % name path=Fx
2363 \tzcoors(0,1)(A)(0,1.5)(B);
2364 \tzhXpoint{Fx}(A)(A)
2365 \tzdot(A){A}[0]
2366 \tzhfn[dashed](0,1.5)
2367 \tzhXpoint*{Fx}(X){X}[45]
2368 \tzdot*(X-2){Y}[ [red,draw] al ] % abb
2369 \end{tikzpicture}
2370 \end{tzcode}
2371
2372
2373 %%------------------------------------------------------------
2374 \section{\protect\cmd{\tzLFnXpoint(*)}: Intersection point of linear functions}
2375 \label{s:tzLFnXpoint}
2376
2377 Sometimes you may want to \xem{quickly} find intersection point of two linear functions \xem{without specifying path names}.
2378
2379 \icmd{\tzLFnXpoint} finds the solution of two linear functions without printing anything by default.
2380 You can name it and use it.
2381
2382 \begin{tzdef}
2383 % syntax: minimum
2384 \tzLFnXpoint{<\fn>}{<\fn>}
2385 % syntax: medium
2386 \tzLFnXpoint{<\fn>}{<\fn>}(<coor name>){<label>}[<[<label opt>]angle>]
2387 % syntax: full
2388 \tzLFnXpoint[<opt>]{<\fn>}{<\fn>}(<coor name>)
2389 {<label>}[<[<label opt>]angle>](<dot size>)
2390 % defaults
2391 [tzdot=2.4pt,draw=none,mimumum size=0pt]{<m>}{<m>}[0](){}[](2.4pt)
2392 \end{tzdef}
2393
2394
2395 \begin{tzcode}{.3}
2396 % \tzLFnXpoint
2397 \begin{tikzpicture}[scale=.8]
2398 \tzhelplines(4,3)
2399 \tzfn[yellow]{\x}[0:3]
2400 \tzfn[yellow]{3-\x}[0:3]
2401 \tzLFnXpoint{\x}{3-\x}(A) % invisible
2402 \tzto+[->,bend left](A)(2,-1)
2403 \end{tikzpicture}
2404 \end{tzcode}
2405
2406 The starred version \icmd{\tzLFnXpoint*} additionally print a filled node dot at the solution of two linear functions of |\x|.
2407
2408 \begin{tzdef}
2409 % syntax: minimum
2410 \tzLFnXpoint*{<\fn>}{<\fn>}
2411 % syntax: medium
2412 \tzLFnXpoint*{<\fn>}{<\fn>}(<coor name>){<label>}[<[<label opt>]angle>]
2413 % syntax: full
2414 \tzLFnXpoint*[<opt>]{<\fn>}{<\fn>}(<coor name>)
2415 {<label>}[<[<label opt>]angle>](<dot size>)
2416 % defaults
2417 *[tzdot=2.4pt,fill]{<m>}{<m>}[0](){}[](2.4pt)
2418 \end{tzdef}
2419
2420 \begin{tzcode}{.3}
2421 % \tzLFnXpoint*
2422 \begin{tikzpicture}[scale=.8]
2423 \tzhelplines(4,3)
2424 \tzLFnXpoint*{\x}{3-\x}(A){A}[[red,draw]90] %%
2425 \tzline+[blue](A)(2,-1)
2426 \end{tikzpicture}
2427 \end{tzcode}
2428
2429
2430
2431 %%==================================
2432 \chapter{Secant and Tangent Lines}
2433 \label{c:tangent}
2434
2435 %%------------------------------------------------------------
2436 \section{Secant lines}
2437 \label{s:secant}
2438
2439 \subsection{\protect\cmd{\tzsecantat}}
2440 \label{ss:tzsecantat}
2441
2442 \icmd{\tzsecantat} draws a line segment or a \iisw{secant} line of a curve, on the |behind| layer by default.
2443 |\tzsecantat| accepts three mandatory arguments.
2444 Three mandatory arguments are a path name and two values of $x$: |{<path>}|, |{<from-x>}|, and |{<to-x>}|.
2445 With \icmd{\settzsecantlayer}, you can change the layer, like |\settzsecantlayer{main}|.
2446
2447 \begin{tzdef}
2448 % syntax: minium
2449 \tzsecantat{<path>}{<from-x>}{<to-x>}
2450 % syntax: medium
2451 \tzsecantat{<path>}{<from-x>}{<to-x>}[<domain>]{<text>}[<node opt>]
2452 % syntax: full
2453 \tzsecantat[<opt>]<shift coor>"path name"
2454 {<path>}{<from-x>}{<to-x>}[<domain>]{<text>}[<node opt>]<code.append>
2455 % defaults
2456 []<>""{<m>}{<m>}{<m>}[]{}[]<>
2457 \end{tzdef}
2458
2459
2460 \paragraph{Domain}
2461 The domain of the form |[<from num:to num>]| is optional.
2462 Without specifying the optional domain, |\tzsecantat| draws a line segment connecting two points on the (curved) path.
2463
2464 \begin{tzcode}{.3}
2465 % \tzsecantat
2466 \begin{tikzpicture}[scale=.5]
2467 \tzhelplines(8,6)
2468 \tzaxes(-1,-1)(8,6){$x$}{$y$}
2469 \tzbezier+"curve"(.5,1)(1,6)(-1,-4)(7,5)
2470 \tzsecantat[thick,red]{curve}{1}{3}
2471 \tzsecantat[thick,red]{curve}{1}{4}
2472 \tzsecantat[thick,red]{curve}{1}{7}
2473 \end{tikzpicture}
2474 \end{tzcode}
2475
2476 Specifying the option |[<domain>]|, you can extend (or shorten) the line of |\tzsecantat|.
2477
2478 \begin{tzcode}{.3}
2479 % \tzsecantat: domain
2480 \begin{tikzpicture}[scale=.5]
2481 \tzhelplines(8,6)
2482 \tzaxes(-1,-1)(8,6){$x$}{$y$}
2483 \tzbezier+"curve"(.5,1)(1,6)(-1,-4)(7,5){curve}[ar]
2484 \tzsecantat[blue]{curve}{1}{3}[0:5]{secant line}[a]
2485 \tzsecantat[thick,red]{curve}{1}{4}
2486 \tzsecantat[blue,dashed]{curve}{1}{7}[0:8]
2487 \end{tikzpicture}
2488 \end{tzcode}
2489
2490 \paragraph{Shift}
2491 You can move |\tzsecantat| by specifying the option |<shift coor>|.
2492
2493 \begin{tzcode}{.3}
2494 % \tzsecantat: domain
2495 \begin{tikzpicture}[scale=.5]
2496 \tzhelplines(8,6)
2497 \tzaxes(-1,-1)(8,6){$x$}{$y$}
2498 \tzbezier+"curve"(.5,1)(1,6)(-1,-4)(7,5){curve}[ar]
2499 \tzsecantat[thick,red]{curve}{1}{4}
2500 \tzsecantat[blue]{curve}{1}{3}[0:5]{secant line}[a]
2501 \tzsecantat[blue]<1,-1>{curve}{1}{3}[0:5]{shifted}[r]
2502 \end{tikzpicture}
2503 \end{tzcode}
2504
2505 \paragraph{Naming paths}
2506 By specifying the option |"<path name>"| you can name a path of |\tzsecantat|, and use it to find intersection points.
2507
2508 \begin{tzcode}{.3}
2509 % \tzsecantat: shift, name path (intersection)
2510 \begin{tikzpicture}[scale=.5]
2511 \tzhelplines(8,6)
2512 \tzaxes(-1,-1)(8,6){$x$}{$y$}
2513 \tzbezier+"curve"(.5,1)(1,6)(-1,-4)(7,5){curve}[ar]
2514 \tzsecantat[thick,red]{curve}{1}{4}
2515 \tzsecantat[blue]{curve}{1}{3}[0:5]{secant line}[a]
2516 \tzsecantat[blue]<1,-1>"shift"{curve}{1}{3}[0:5] %%
2517 \tzvXpointat*{shift}{3}{X}[-45]
2518 \tzticksx(-1mm:2mm){3/$x=3$}[scale=.7]
2519 \end{tikzpicture}
2520 \end{tzcode}
2521
2522 \paragraph{\texttt{<code.append>}}
2523 You can extend the path of |\tzsecantat| by writing \Tikz\ code in the last optional argument |<code.append>|.
2524
2525 \begin{tzcode}{.3}
2526 % \tzsecantat: <code.append>
2527 \begin{tikzpicture}[scale=.5]
2528 \tzhelplines(8,6)
2529 \tzaxes(-1,-1)(8,6){$x$}{$y$}
2530 \tzbezier+"curve"(.5,1)(1,6)(-1,-4)(7,5){curve}[ar]
2531 \tzsecantat[blue]{curve}{1}{3}[0:5]{secant line}[a]
2532 \tzsecantat[blue,->]<1,-1>"shift"{curve}{1}{3}[0:5] %%
2533 < --++(1,-3) node [red,b] {Ends!} >
2534 \tzvXpointat*{shift}{3}{X}[-45]
2535 \end{tikzpicture}
2536 \end{tzcode}
2537
2538
2539
2540 \subsection{\protect\cmd{\tzsecant}}
2541 \label{ss:tzsecant}
2542
2543 \icmd{\tzsecant} uses two \xem{coordinates instead of two values of $x$} to draw a line segment or a \iisw{secant} line of a curve, on the |behind| layer by default.
2544 You need to specify a path name and two coordinates, then |\tzsecant| uses the $x$ values of the two coordinates.
2545
2546 \xem{Everything else is the same as in} |\tzsecantat|.
2547
2548 You can change the layer with \icmd{\settzsecantlayer}.
2549
2550 \begin{tzdef}
2551 % syntax: minium
2552 \tzsecant{<path>}(<coor>)(<coor>)
2553 % syntax: medium
2554 \tzsecant{<path>}(<coor>)(<coor>)[<domain>]{<text>}[<node opt>]
2555 % syntax: full
2556 \tzsecant[<opt>]<shift coor>"path name"
2557 {<path>}(<coor>)(<coor>)[<domain>]{<text>}[<node opt>]<code.append>
2558 % defaults
2559 []<>""{<m>}(<m>)(<m>)[]{}[]<>
2560 \end{tzdef}
2561
2562 The domain should be of the form |[<from num:to num>]|.
2563 Without specifying the optional domain, |\tzsecant| draws a line segment connecting two points on the (curved) path.
2564
2565 \begin{tzcode}{.3}
2566 % \tzsecant: domain
2567 \begin{tikzpicture}[scale=.5]
2568 \tzhelplines(8,6)
2569 \tzaxes(-1,-1)(8,6){$x$}{$y$}
2570 \tzbezier+"curve"(.5,1)(1,6)(-1,-4)(7,5){curve}[ar]
2571 \tzcoor(1,0)(K)
2572 \tzsecant[blue]{curve}(K)(3,0)[0:5]{secant line}[a]
2573 \tzsecant[thick,red]{curve}(K)(4,0)
2574 \tzsecant[blue,dashed]{curve}(K)(7,0)[0:8]
2575 \end{tikzpicture}
2576 \end{tzcode}
2577
2578 With the last option |<code.append>| you can extend the path of |\tzsecantat|.
2579
2580 \begin{tzcode}{.3}
2581 % \tzsecant: shift, <code.append>
2582 \begin{tikzpicture}[scale=.5]
2583 \tzhelplines(8,6)
2584 \tzaxes(-1,-1)(8,6){$x$}{$y$}
2585 \tzbezier+"curve"(.5,1)(1,6)(-1,-4)(7,5){curve}[ar]
2586 \tzcoor(1,0)(K)
2587 \tzsecant[blue]{curve}(K)(3,0)[0:5]{secant line}[a]
2588 \tzsecant[blue,->]<1,-1>"shift"{curve}(K)(3,0)[0:5] %%
2589 < --++(1,-3) node [red,b] {Ends!} >
2590 \tzvXpointat*{shift}{3}{X}[-45]
2591 \end{tikzpicture}
2592 \end{tzcode}
2593
2594
2595
2596 %%------------------------------------------------------------
2597 \section{Tangent lines}
2598 \label{s:tangent}
2599
2600 \subsection{\protect\cmd{\tztangentat}}
2601 \label{ss:tztangentat}
2602
2603 \icmd{\tztangentat} draws a \iisw{tangent} line to a curve at a specified value of $x$. Three mandatory arguments are a curve name, a value of $x$, and a domain: |{<path>}|, |{<x-val>}|, and |[domain]|.
2604 By default, the tangent line is drawn on the |behind| layer, which can be changed by \icmd{\settztangentlayer}, like |\settztangentlayer{main}|.
2605
2606 \remark
2607 To calculate the slope at $x$, $x$ varies over the interval $(x-\varepsilon_1,x+\varepsilon_2)$ and $\varepsilon_1=\varepsilon_2=0.01$, by default.
2608 So the slope of tangent line is only \xem{approximate}.
2609
2610 \begin{tzdef}
2611 % syntax: minimum
2612 \tztangentat{<path>}{<x-val>}[<domain>]
2613 % syntax: medium
2614 \tztangentat{<path>}{<x-val>}[<domain>]{<text>}[<node opt>]
2615 % syntax: full
2616 \tztangentat[<opt>]<shift coor>"<path name>"
2617 {<path>}{<x-val>}(<epsilon1>,<epsilon2>)[<domain>]
2618 {<text>}[<node opt>]<code.append>
2619 % The domain should be of the form [<from:to>]
2620 % defaults
2621 []<>""{<m>}{<m>}(.01,.01)[<m>]{}[]<>
2622 \end{tzdef}
2623
2624
2625 \paragraph{Domain}
2626 The mandatory argument |[<domain>]| should be of the form |[<from num:to num>]|.
2627
2628 \begin{tzcode}{.3}
2629 % \tztangentat
2630 \begin{tikzpicture}[scale=.5]
2631 \tzhelplines(9,8)
2632 \tzaxes(9,8)
2633 \tzplotcurve"AA"(1,7)(3,3)(8,1);
2634 \tztangentat{AA}{2}[.5:4]
2635 \tztangentat[blue]{AA}{4}[1:7]{tangent}[red,b]
2636 \tzvXpointat*{AA}{4}
2637 \tzticksx{1,7}
2638 \end{tikzpicture}
2639 \end{tzcode}
2640
2641
2642 \paragraph{Shift}
2643 You can move the tangent line by specifying the option |<shift coor>|.
2644
2645 \begin{tzcode}{.3}
2646 % \tztangentat: shift
2647 \begin{tikzpicture}[scale=.5]
2648 \tzhelplines(9,8)
2649 \tzaxes(9,8)
2650 \tzplotcurve"AA"(1,7)(3,3)(8,1);
2651 \tztangentat{AA}{2}[.5:4]
2652 \tztangentat[blue]{AA}{4}[1:7]{tangent}[red,b]
2653 \tztangentat[blue]<2,1>{AA}{4}[1:7]{tangent'}[r]
2654 \tzvXpointat*{AA}{4}
2655 \tzticksx{1,7}
2656 \end{tikzpicture}
2657 \end{tzcode}
2658
2659 \paragraph{Naming paths}
2660 By specifying the option |"<path name>"|, you can name the path of |\tztangentat| and use it to find intersection points.
2661
2662 \begin{tzcode}{.3}
2663 % \tztangentat: name path (intersection)
2664 \begin{tikzpicture}[scale=.5,font=\footnotesize]
2665 \tzhelplines(9,8)
2666 \tzaxes(9,8)
2667 \tzplotcurve"AA"(1,7)(3,3)(8,1);
2668 \tztangentat{AA}{2}[.5:4]
2669 \tztangentat[blue]{AA}{4}[1:7]{tangent}[red,b]
2670 \tzvXpointat*{AA}{4}
2671 \tztangentat[blue]
2672 <2,1>"BB"{AA}{4}[1:7]{tangent'}[r]
2673 \tzvXpointat*[blue]{BB}{5}(X){$x$}[45](3pt)
2674 \tzproj(X){$x_1$}{$x_2$}
2675 \end{tikzpicture}
2676 \end{tzcode}
2677
2678 \paragraph{\texttt{<code.append>}}
2679 You can extend the path of |\tztangentat| by writing \Tikz\ code in the last optional argument |<code.append>|.
2680
2681 \begin{tzcode}{.3}
2682 % \tztangentat: <code.append>
2683 \begin{tikzpicture}[scale=.5,font=\footnotesize]
2684 \tzhelplines(9,8)
2685 \tzaxes(9,8)
2686 \tzplotcurve"AA"(1,7)(3,3)(8,1);
2687 \tztangentat{AA}{2}[.5:4]
2688 \tztangentat[blue]{AA}{4}[1:7]{tangent}[red,b]
2689 \tzvXpointat*{AA}{4}
2690 \tztangentat[blue,->]<2,1>"BB"{AA}{4}[1:7]
2691 < to [bend right] ++(-1,3) node [a] {Ends!} >
2692 \tzvXpointat*[blue]{BB}{5}(X){$x$}[45](3pt)
2693 \tzproj(X){$x_1$}{$x_2$}
2694 \end{tikzpicture}
2695 \end{tzcode}
2696
2697
2698
2699 \paragraph{Variations}
2700 Since the slope of the tangent line is \xem{approximate}, sometimes you may want to change the variation interval to get better results.
2701 You can change $\varepsilon_1$ and $\varepsilon_2$ by specifying the option |(<epsilon1,epsilon2>)| \xem{immediately after} the mandatory argument |{<x-val>}|.
2702 Or you can change the variations by the macro \icmd{\settztangentepsilon},
2703 like |\settztangentepsilon{|$\varepsilon_1$|}{|$\varepsilon_2$|}|. The effect remains until the end of |tikzpicture| environment unless changed again.
2704
2705 \begin{tzcode}{.3}
2706 % \tztangentat: variations, shift
2707 \begin{tikzpicture}[scale=.5,font=\footnotesize]
2708 \tzhelplines(9,8)
2709 \tzaxes(9,8)
2710 \tzplotcurve"AA"(1,7)(3,3)(8,1);
2711 \tztangentat[blue!50,dashed]{AA}{4}[1:7]
2712 \settztangentepsilon{0.005}{0.01} %%
2713 \tztangentat[blue]{AA}{4}[1:7]{corrected}[r]
2714 \tztangentat[red]<0,1>{AA}{4}[1:7]{shifted}[r] %%
2715 \end{tikzpicture}
2716 \end{tzcode}
2717
2718
2719
2720
2721 \subsection{\protect\cmd{\tztangent}}
2722 \label{ss:tztangent}
2723
2724
2725 \icmd{\tztangent} uses a \xem{coordinate instead of a value} of $x$ to draw a \iisw{tangent} line to a curve.
2726 |\tztangent| accepts three mandatory arguments: |{<path>}|, |(<coor>)|, and |[<domain>]|.
2727
2728 The value of $y$ in |(<coor>)| is ignored.
2729 For example, |\tztangent{curve}(4,|$y$|)| is equivalent to |\tztangentat{curve}{4}| for any $y$.
2730
2731 \xem{Everything else is the same as in} |\tztangentat|.
2732
2733 \begin{tzdef}
2734 % syntax: minimum
2735 \tztangent{<path>}(<coor>)[<domain>]
2736 % syntax: medium
2737 \tztangent{<path>}(<coor>)[<domain>]{<text>}[<node opt>]
2738 % syntax: full
2739 \tztangent[<opt>]<shift coor>"<path name>"
2740 {<path>}(<coor>)(<epsilon1>,<epsilon2>)[<domain>]
2741 {<text>}[<node opt>]<code.append>
2742 % The domain should be of the form [<from:to>]
2743 % defaults
2744 []<>""{<m>}(<m>)(.01,.01)[<m>]{}[]<>
2745 \end{tzdef}
2746
2747
2748
2749 \begin{tzcode}{.3}
2750 % \tztangent
2751 \begin{tikzpicture}[scale=.5]
2752 \tzhelplines(9,8)
2753 \tzaxes(9,8)
2754 \tzplotcurve"AA"(1,7)(3,3)(8,1);
2755 \tzcoors(2,0)(K2)(4,0)(K4);
2756 \tztangent{AA}(K2)[.5:4]
2757 \tztangent[blue]{AA}(K4)[1:7]{tangent}[red,b]
2758 \tzvXpoint*{AA}(K4)
2759 \tzticksx{1,7}
2760 \end{tikzpicture}
2761 \end{tzcode}
2762
2763 You can shift the tangent line and extend its path.
2764
2765 \begin{tzcode}{.3}
2766 % \tztangent: shift, <code.append>
2767 \begin{tikzpicture}[scale=.5,font=\footnotesize]
2768 \tzhelplines(9,8)
2769 \tzaxes(9,8)
2770 \tzplotcurve"AA"(1,7)(3,3)(8,1);
2771 \tzcoors(2,0)(K2)(4,0)(K4);
2772 \tztangent{AA}(K2)[.5:4]
2773 \tztangent[blue]{AA}(K4)[1:7]{tangent}[red,b]
2774 \tzvXpoint*{AA}(K4)
2775 \tztangent[blue,->]<2,1>"BB"{AA}(K4)[1:7]
2776 < to [bend right] ++(-1,3) node [a] {Ends!} >
2777 \tzvXpoint*[blue]{BB}(5,0)(X){$x$}[45](3pt)
2778 \tzproj(X){$x_1$}{$x_2$}
2779 \end{tikzpicture}
2780 \end{tzcode}
2781
2782 You can control the interval of variations of $x$ by the option |(<epsilon1,epsion2>)| or the marcro |\settztangentepsilon|.
2783
2784 \begin{tzcode}{.3}
2785 % \tztangent: variations, shift
2786 \begin{tikzpicture}[scale=.5,font=\footnotesize]
2787 \tzhelplines(9,8)
2788 \tzaxes(9,8)
2789 \tzplotcurve"AA"(1,7)(3,3)(8,1);
2790 \tztangent[blue!50,dashed]{AA}(4,0)[1:7]
2791 \settztangentepsilon{0.005}{0.01} %%
2792 \tztangent[blue]{AA}(4,0)[1:7]{corrected}[r]
2793 \tztangent[red]<0,1>{AA}(4,0)[1:7]{shifted}[r] %%
2794 \end{tikzpicture}
2795 \end{tzcode}
2796
2797
2798
2799 %%------------------------------------------------------------
2800 \section{Slope lines and normal lines}
2801 \label{s:slopes}
2802
2803 \subsection{\protect\cmd{\tzslopeat}}
2804 \label{ss:tzslopeat}
2805
2806 \icmd{\tzslopeat} draws a slope line to a path with a specified length.
2807 The mandatory arguments are |{<path>}|, |{<x>}|, and |{<length>}|.
2808 The tangent point is the middle point of the slope line.
2809
2810 By default, the slope lines are drawn on the |behind| layer.
2811 You can change the layer, like \icmd{\settztslopelayer}|{main}|.
2812
2813 \remark The slope is \xem{approximate} and you can manipulate the slope by changing the variation interval with the option |(<epsilon1,epsilon2>)|. The default is $(\varepsilon_1,\varepsilon_2)=(0.01,0.01)$.
2814 You can also use
2815 \icmd{\settzslopeepsilon}|{<epsilon1>}{<epsilon2>}| \xem{before} the macro |\tzslopeat|, which is valid until the end of the |tikzpicture| environment, unless changed again.
2816
2817
2818 \begin{tzdef}
2819 % syntax: minimum
2820 \tzslopeat{<path>}{<x-val>}{<length>}
2821 % syntax: minimum (for normal line)
2822 \tzslopeat{<path>}{<x-val>}{<length>}[90] % or [-90]
2823 % syntax: full
2824 \tzslopeat[<opt>]{<path>}{<x-val>}(<epsilon1>,<epsilon2>){<length>}[<rotate>]
2825 {<text>}[<node opt>]<code.append>
2826 % defaults
2827 []{<m>}{<m>}(.01,.01){<m>}[0]{}[]<>
2828 \end{tzdef}
2829
2830 \begin{tzcode}{.3}
2831 % \tzslopeat
2832 \begin{tikzpicture}
2833 \tzhelplines*(5,4)
2834 \tzcoors*(0,0)(A)(2,2)(B){B}[b](3.5,1)(C)(5,3)(D);
2835 \tztos[thick]"AA"(A)[out=0,in=180]
2836 (B)[out=0,in=180]
2837 (C)[out=0,in=255]
2838 (D);
2839 \tzslopeat[->,red,thick]{AA}{1}{3cm}
2840 \tzslopeat[blue]{AA}{2}{2cm}
2841 \tzslopeat{AA}{4}{2cm}{$f'(4)$}[r]
2842 \end{tikzpicture}
2843 \end{tzcode}
2844
2845
2846 \begin{tzcode}{.3}
2847 % \tzslopeat: repeated
2848 \begin{tikzpicture}
2849 \tzhelplines(1,1)(5,4)
2850 \tzcoors*(0,1)(A)(2,3)(B)(4,2)(C);
2851 \tzparabola"AA"(A)(B)(C)
2852 \foreach \x in {1,1.5,...,3.5}
2853 { \tzslopeat[thick,red]{AA}{\x}{2cm} }
2854 \end{tikzpicture}
2855 \end{tzcode}
2856
2857
2858
2859
2860 \paragraph{Normal lines}
2861 With the option |[<rotate>]| \xem{immediately after} the last mandatory argument |{<length>}|, you can draw a \iisw{normal line} to a curve by rotating the slope lines |90|\textdegree or |-90|\textdegree.
2862
2863 \begin{tzcode}{.3}
2864 % \tzslopeat: slopes and normals
2865 \begin{tikzpicture}
2866 \tzhelplines*(5,4)
2867 \tzcoors*(0,0)(A)(2,2)(B){B}[b](3.5,1)(C)(5,3)(D);
2868 \tztos[thick]"AA"(A)[out=0,in=180]
2869 (B)[out=0,in=180]
2870 (C)[out=0,in=255]
2871 (D);
2872 \tzslopeat[red]{AA}{1}{3cm}
2873 \tzslopeat[blue]{AA}{2}{2cm}
2874 \tzslopeat{AA}{4}{2cm}{$f'(4)$}[r]
2875 % normal lines: rotate: [90] or [-90]
2876 \tzslopeat[->,blue]{AA}{1}{1cm}[90]
2877 \tzslopeat[->,red]{AA}{2}{2cm}[90]
2878 \tzslopeat[->,red]{AA}{4}{1cm}[-90]{normal}[b]
2879 \end{tikzpicture}
2880 \end{tzcode}
2881
2882
2883 \subsection{\protect\cmd{\tzslopeat'}}
2884 \label{ss:tzslopeat'}
2885
2886 The \iisw{swap version} \icmd{\tzslopeat'} draws a slope line with the opposite direction of |\tzslopeat|.
2887
2888 \begin{tzcode}{.3}
2889 % \tzslopeat'
2890 \begin{tikzpicture}
2891 \tzhelplines*(5,4)
2892 \tzcoors*(0,0)(A)(2,2)(B){B}[b](3.5,1)(C)(5,3)(D);
2893 \tztos[thick]"AA"(A)[out=0,in=180]
2894 (B)[out=0,in=180]
2895 (C)[out=0,in=255]
2896 (D);
2897 \tzslopeat'[->,red,thick]{AA}{1}{3cm} %%
2898 \tzslopeat[->,blue]{AA}{2}{2cm}
2899 \tzslopeat'[->]{AA}{4}{2cm}{$f'(4)$}[r] %%
2900 \end{tikzpicture}
2901 \end{tzcode}
2902
2903 \remark
2904 |\tzslopeat{AA}{2}{2cm}[-180]| is equivalent to |\tzslopeat'{AA}{2}{2cm}|.
2905
2906 \begin{itemize}
2907 \item Without the arrows, |\tzslopeat| and |\tzslopeat'| give the same result except where the labels are placed.
2908 \item
2909 The swap version |\tzslopeat'| does not change its direction with the option |[<rotate>]|.
2910 \end{itemize}
2911
2912
2913
2914 \subsection{\protect\cmd{\tzslope}}
2915 \label{ss:tzslope}
2916
2917 \icmd{\tzslope} is the same as |\tzslopeat|, except for one thing.
2918 |\tzslope| uses a coordinate instead of a value of $x$ to draw slope lines.
2919 So the mandatory arguments of |\tzslope| is |{<path>}|, |(<coor>)|, and |{<length>}|. The $y$ value of |(<x,y>)| is ignored.
2920
2921 \begin{tzdef}
2922 % syntax
2923 \tzslope[<opt>]{<path>}(<x,y>)(<epsilon1>,<epsilon2>){<length>}[<angle>]
2924 {<text>}[<pos,opt>]<code.append>
2925 % defaults
2926 []{<m>}(<m>)(.01,.01){<m>}[0]{}[]<>
2927 \end{tzdef}
2928
2929
2930
2931 \begin{tzcode}{.3}
2932 % \tzslope: slopes and normals
2933 \begin{tikzpicture}
2934 \tzhelplines*(5,4)
2935 \tzcoors*(0,0)(A)(2,2)(B){B}[b](3.5,1)(C)(5,3)(D);
2936 \tztos[thick]"AA"(A)[out=0,in=180]
2937 (B)[out=0,in=180]
2938 (C)[out=0,in=255]
2939 (D);
2940 \tzslope[red]{AA}(1,0){3cm}
2941 \tzgetxyval(B){\Bx}{\By}
2942 \tzslopeat[blue]{AA}{\Bx}{2cm}
2943 \tzslope{AA}(4,0){2cm}{$f'(4)$}[r]
2944 % normal lines: rotate: [90] or [-90]
2945 \tzslope[->,blue]{AA}(1,0){1cm}[90]
2946 \tzslope[->,red]{AA}(B){2cm}[90]
2947 \tzslope[->,red]{AA}(4,0){1cm}[-90]{normal}[b]
2948 \end{tikzpicture}
2949 \end{tzcode}
2950
2951
2952 \begin{tzcode}{.3}
2953 % \tzslope: repeated
2954 \begin{tikzpicture}
2955 \tzhelplines(1,1)(5,4)
2956 \tzcoors*(0,1)(A)(2,3)(B)(4,2)(C);
2957 \tzparabola"AA"(A)(B)(C)
2958 \foreach \x in {1,1.5,...,3.5}
2959 { \tzslope[thick,red]{AA}(\x,0){2cm} }
2960 \end{tikzpicture}
2961 \end{tzcode}
2962
2963 You can add \Tikz\ code with the last option |<code.append>|.
2964
2965 \begin{tzcode}{.3}
2966 % \tztangent, \tzslope: extend/shorten lines
2967 \begin{tikzpicture}[scale=.5]
2968 \tzhelplines(9,8)
2969 \tzaxes(9,8)
2970 \tzplotcurve"AA"(1,7)(3,3)(8,1);
2971 \tzcoors(2,0)(K2)(4,0)(K4);
2972 \tzslope[red,tzextend={1cm}{2cm}]{AA}(K2){1cm} %%
2973 \tztangent[blue]{AA}(K4)[1:7]{tangent}[red,b]
2974 \tzslope[->]{AA}(K4){0.1pt}[90]
2975 <--([turn]0:2cm) node [r] {gradient} > %%
2976 \tzvXpoint*{AA}(K4)
2977 \tzticksx{1,7}
2978 \end{tikzpicture}
2979 \end{tzcode}
2980
2981
2982 \subsection{\protect\cmd{\tzslope'}}
2983 \label{ss:tzslope'}
2984
2985 The \iisw{swap version} \icmd{\tzslope'} draws a slope line with the opposite direction of |\tzslope|.
2986
2987 \begin{tzcode}{.3}
2988 % \tzslope'
2989 \begin{tikzpicture}
2990 \tzhelplines*(5,4)
2991 \tzcoors*(0,0)(A)(2,2)(B){B}[b](3.5,1)(C)(5,3)(D);
2992 \tztos[thick]"AA"(A)[out=0,in=180]
2993 (B)[out=0,in=180]
2994 (C)[out=0,in=255]
2995 (D);
2996 \tzslope'[->,red,thick]{AA}(1,0){3cm}
2997 \tzslope[->,blue]{AA}(B){2cm}
2998 \tzslope'[->]{AA}(4,0){2cm}{$f'(4)$}[r]
2999 \end{tikzpicture}
3000 \end{tzcode}
3001
3002 \remark
3003 |\tzslope{AA}{2}{2cm}[-180]| is equivalent to |\tzslope'{AA}{2}{2cm}|.
3004
3005 \begin{itemize}
3006 \item Without the arrows, |\tzslope| and |\tzslope'| give the same result except where the labels are placed.
3007 \item
3008 The swap version |\tzslope'| does not change its direction with the option |[<rotate>]|.
3009 \end{itemize}
3010
3011
3012 %%------------------------------------------------------------
3013 \section{Normal lines}
3014 \label{s:normals}
3015
3016 \subsection{\protect\cmd{\tznormalat}}
3017 \label{ss:tznormalat}
3018
3019 \icmd{\tznormalat} draws a normal line \xem{from a point} on a graph at $x=\mbox{\texttt{<x-val>}}$.
3020 The mandatory arguments are |{<path>}|, |{<x-val>}|, and |{<length>}|.
3021
3022 By default, the normal lines are drawn on the |behind| layer.
3023 You can change the layer, like \icmd{\settztnormallayer}|{main}|.
3024
3025 \remark The slope of a normal \xem{perpendicular to the slope line} is \xem{approximate} and can be changed by changing the variation interval with the option |(<epsilon1,epsilon2>)|. The default is $(\varepsilon_1,\varepsilon_2)=(0.01,0.01)$.
3026 You can also use
3027 \icmd{\settznormalepsilon}|{<epsilon1>}{<epsilon2>}| \xem{before} the macro |\tznormalat|, which is valid until the end of the |tikzpicture| environment, unless changed again.
3028
3029
3030 \begin{tzdef}
3031 % syntax: minimum
3032 \tznormalat{<path>}{<x-val>}{<length>}
3033 % syntax: full
3034 \tznormalat[<opt>]{<path>}{<x-val>}(<epsilon1>,<epsilon2>){<length>}[<rotate>]
3035 {<text>}[<node opt>]<code.append>
3036 % defaults
3037 []{<m>}{<m>}(.01,.01){<m>}[90]{}[]<>
3038 \end{tzdef}
3039
3040 \begin{tzcode}{.3}
3041 % \tznormalat
3042 \begin{tikzpicture}
3043 \tzhelplines*(5,4)
3044 \tzcoors*(0,0)(A)(2,2)(B){B}[b](3.5,1)(C)(5,3)(D);
3045 \tztos[thick]"AA"(A)[out=0,in=180]
3046 (B)[out=0,in=180]
3047 (C)[out=0,in=255]
3048 (D);
3049 \tzslopeat[red,thick]{AA}{1}{3cm}
3050 \tzslopeat[blue]{AA}{2}{2cm}
3051 \tzslopeat{AA}{4}{2cm}{$f'(4)$}[r]
3052 \tznormalat[->,red,thick]{AA}{1}{3cm}
3053 \tznormalat[->,blue]{AA}{2}{2cm}
3054 \tznormalat[->]{AA}{4}{2cm}{normal}[r]
3055 \end{tikzpicture}
3056 \end{tzcode}
3057
3058 You can change its direction with the option |[<rotate>]| after the argument |{<length>}|.
3059
3060 \begin{tzcode}{.3}
3061 % \tznormalat: rotated
3062 \begin{tikzpicture}
3063 \tzhelplines*(5,4)
3064 \tzcoors*(0,0)(A)(2,2)(B){B}[b](3.5,1)(C)(5,3)(D);
3065 \tztos[thick]"AA"(A)[out=0,in=180]
3066 (B)[out=0,in=180]
3067 (C)[out=0,in=255]
3068 (D);
3069 \tzslopeat[red]{AA}{2}{3cm}
3070 \tznormalat[->,blue]{AA}{2}{2cm}
3071 \tznormalat[->,blue]{AA}{2}{2cm}[45]{45\textdegree}[ar]
3072 \tznormalat[->,blue]{AA}{2}{2cm}[135]
3073 \end{tikzpicture}
3074 \end{tzcode}
3075
3076
3077 \subsection{\protect\cmd{\tznormalat'}}
3078 \label{ss:tznormalat'}
3079
3080 The \iisw{swap version} \icmd{\tznormalat'} draws a normal line with the opposite direction of |\tznormalat|.
3081
3082 \begin{tzdef}
3083 % syntax: minimum
3084 \tznormalat'{<path>}{<x-val>}{<length>}
3085 % syntax: full
3086 \tznormalat'[<opt>]{<path>}{<x-val>}(<epsilon1>,<epsilon2>){<length>}[<rotate>]
3087 {<text>}[<node opt>]<code.append>
3088 % defaults
3089 []{<m>}{<m>}(.01,.01){<m>}[-90]{}[]<>
3090 \end{tzdef}
3091
3092 \begin{tzcode}{.3}
3093 % \tznormalat' (swap version)
3094 \begin{tikzpicture}
3095 \tzhelplines*(5,4)
3096 \tzcoors*(0,0)(A)(2,2)(B){B}[b](3.5,1)(C)(5,3)(D);
3097 \tztos[thick]"AA"(A)[out=0,in=180]
3098 (B)[out=0,in=180]
3099 (C)[out=0,in=255]
3100 (D);
3101 \tzslopeat[red,thick]{AA}{1}{3cm}
3102 \tzslopeat[blue]{AA}{2}{2cm}
3103 \tzslopeat{AA}{4}{2cm}{$f'(4)$}[r]
3104 \tznormalat'[->,red,thick]{AA}{1}{3cm} %%
3105 \tznormalat[->,blue]{AA}{2}{2cm}
3106 \tznormalat'[->]{AA}{4}{2cm}{normal}[r] %%
3107 \end{tikzpicture}
3108 \end{tzcode}
3109
3110 \remark
3111 The swap version |\tznormalat'| has a fixed |[<rotate>]| value of |[-90]|.
3112 \begin{itemize}
3113 \item |\tznormalat{AA}{1}{3cm}[-90]| is equivalent to |\tznormalat'{AA}{1}{3cm}|.
3114 \item |\tznomralat'| does not change its direction with the option |[<rotate>]|.
3115 \end{itemize}
3116
3117
3118 \subsection{\protect\cmd{\tznormalat*(')}}
3119 \label{ss:tznormalat*}
3120
3121 \begin{tzdef}
3122 % syntax: minimum
3123 \tznormalat*{<path>}{<x-val>}{<length>}
3124 % syntax: full
3125 \tznormalat*[<opt>]{<path>}{<x-val>}(<epsilon1>,<epsilon2>){<length>}[<rotate>]
3126 {<text>}[<node opt>]<code.append>
3127 % defaults
3128 * []{<m>}{<m>}(.01,.01){<m>}[90]{}[]<>
3129 *'[]{<m>}{<m>}(.01,.01){<m>}[-90]{}[]<>
3130 \end{tzdef}
3131
3132 The starred version \icmd{\tznormalat*} works like |\tzslopeat|, but rotated |[90]|.
3133 And the swap version \icmd{\tznormalat*'} works like |\tzslopeat|, but rotated |[-90]|.
3134
3135 \remark
3136 The swap version |\tznormalat*'| has a fixed |[<rotate>]| value of |[-90]|.
3137 \begin{itemize}
3138 \item |\tznormalat*{AA}{1}{3cm}[-90]| is equivalent to |\tznormalat*'{AA}{1}{3cm}|.
3139 \item |\tznomralat*'| does not change its direction with the option |[<rotate>]|.
3140 \end{itemize}
3141
3142 \begin{tzcode}{.3}
3143 % \tznormalat*(')
3144 \begin{tikzpicture}
3145 \tzhelplines*(5,4)
3146 \tzcoors*(0,0)(A)(2,2)(B){B}[b](3.5,1)(C)(5,3)(D);
3147 \tztos[thick]"AA"(A)[out=0,in=180]
3148 (B)[out=0,in=180]
3149 (C)[out=0,in=255]
3150 (D);
3151 \tzslopeat[red,thick]{AA}{1}{3cm}
3152 \tzslopeat[blue]{AA}{2}{2cm}
3153 \tzslopeat{AA}{4}{2cm}{$f'(4)$}[r]
3154 \tznormalat*[->,red,thick]{AA}{1}{3cm}
3155 \tznormalat*[->,blue]{AA}{2}{2cm}
3156 \tznormalat*'[->]{AA}{4}{2cm}{normal}[r]
3157 \end{tikzpicture}
3158 \end{tzcode}
3159
3160
3161 \subsection{\protect\cmd{\tznormal}}
3162 \label{ss:tznormal}
3163
3164 \icmd{\tznormal} is the same as |\tznormalat|, except for one thing.
3165 |\tznormal| uses a coordinate instead of a value of $x$ to draw normal lines.
3166 So the mandatory arguments of |\tznormal| is |{<path>}|, |(<coor>)|, and |{<length>}|. The $y$ value of |(<x,y>)| is ignored.
3167
3168 \begin{tzdef}
3169 % syntax: minimum
3170 \tznormal{<path>}(<x,y>){<length>}
3171 % syntax: full
3172 \tznormal[<opt>]{<path>}(<x,y>)(<epsilon1>,<epsilon2>){<length>}[<angle>]
3173 {<text>}[<pos,opt>]<code.append>
3174 % defaults
3175 []{<m>}(<m>)(.01,.01){<m>}[90]{}[]<>
3176 \end{tzdef}
3177
3178
3179
3180 \begin{tzcode}{.3}
3181 % \tznormal
3182 \begin{tikzpicture}
3183 \tzhelplines*(5,4)
3184 \tzcoors*(0,0)(A)(2,2)(B){B}[b](3.5,1)(C)(5,3)(D);
3185 \tztos[thick]"AA"(A)[out=0,in=180]
3186 (B)[out=0,in=180]
3187 (C)[out=0,in=255]
3188 (D);
3189 \tzslope[red]{AA}(1,0){3cm}
3190 \tzgetxyval(B){\Bx}{\By}
3191 \tzslopeat[blue]{AA}{\Bx}{2cm}
3192 \tzslope{AA}(4,0){2cm}{$f'(4)$}[r]
3193 \tznormal[->,blue]{AA}(1,0){2cm}
3194 \tznormal[->,red]{AA}(B){2cm}
3195 \tznormal[->,red]{AA}(4,0){2cm}{normal}[a]
3196 \end{tikzpicture}
3197 \end{tzcode}
3198
3199 You can change its direction with the option |[<rotate>]| after the argument |{<length>}|.
3200
3201 \begin{tzcode}{.3}
3202 % \tznormal: rotated
3203 \begin{tikzpicture}
3204 \tzhelplines*(5,4)
3205 \tzcoors*(0,0)(A)(2,2)(B){B}[b](3.5,1)(C)(5,3)(D);
3206 \tztos[thick]"AA"(A)[out=0,in=180]
3207 (B)[out=0,in=180]
3208 (C)[out=0,in=255]
3209 (D);
3210 \tzslope[red]{AA}(B){3cm}
3211 \tznormal[->,blue]{AA}(B){2cm}
3212 \tznormal[->,blue]{AA}(B){2cm}[45]{45\textdegree}[ar]
3213 \tznormal[->,blue]{AA}(B){2cm}[135]
3214 \end{tikzpicture}
3215 \end{tzcode}
3216
3217
3218 \subsection{\protect\cmd{\tznormal'}}
3219 \label{ss:tznormal'}
3220
3221 The \iisw{swap version} \icmd{\tznormal'} draws a normal line with the opposite direction of |\tznormal|.
3222
3223 \begin{tzdef}
3224 % syntax: minimim
3225 \tznormal'{<path>}(<x,y>){<length>}
3226 % syntax: full
3227 \tznormal'[<opt>]{<path>}(<x,y>)(<epsilon1>,<epsilon2>){<length>}[<angle>]
3228 {<text>}[<pos,opt>]<code.append>
3229 % defaults
3230 []{<m>}(<m>)(.01,.01){<m>}[-90]{}[]<>
3231 \end{tzdef}
3232
3233 \remark
3234 The swap version |\tznormal'| has a fixed |[<rotate>]| value of |[-90]|.
3235 \begin{itemize}
3236 \item |\tznormal{AA}{1}{3cm}[-90]| is equivalent to |\tznormal'{AA}{1}{3cm}|.
3237 \item |\tznomral'| does not change its direction with the option |[<rotate>]|.
3238 \end{itemize}
3239
3240 \begin{tzcode}{.3}
3241 % \tznormal' (swap version)
3242 \begin{tikzpicture}
3243 \tzhelplines*(5,4)
3244 \tzcoors*(0,0)(A)(2,2)(B){B}[b](3.5,1)(C)(5,3)(D);
3245 \tztos[thick]"AA"(A)[out=0,in=180]
3246 (B)[out=0,in=180]
3247 (C)[out=0,in=255]
3248 (D);
3249 \tzslope[red]{AA}(1,0){3cm}
3250 \tzgetxyval(B){\Bx}{\By}
3251 \tzslopeat[blue]{AA}{\Bx}{2cm}
3252 \tzslope{AA}(4,0){2cm}{$f'(4)$}[r]
3253 \tznormal'[->,blue]{AA}(1,0){2cm} %%
3254 \tznormal[->,red]{AA}(B){2cm}
3255 \tznormal'[->,red]{AA}(4,0){2cm}{normal}[b] %%
3256 \end{tikzpicture}
3257 \end{tzcode}
3258
3259
3260 \subsection{\protect\cmd{\tznormal*(')}}
3261 \label{ss:tznormal*}
3262
3263 The starred version \icmd{\tznormal*} works like |\tzslope|, but rotated |[90]|.
3264 And its swap version \icmd{\tznormal*'} works like |\tzslope|, but rotated |[-90]|.
3265
3266 \begin{tzdef}
3267 % syntax
3268 \tznormal*[<opt>]{<path>}(<x,y>)(<epsilon1>,<epsilon2>){<length>}[<angle>]
3269 {<text>}[<pos,opt>]<code.append>
3270 % defaults
3271 * []{<m>}(<m>)(.01,.01){<m>}[90]{}[]<>
3272 *'[]{<m>}(<m>)(.01,.01){<m>}[-90]{}[]<>
3273 \end{tzdef}
3274
3275
3276 \remark
3277 The swap version |\tznormal*'| has a fixed |[<rotate>]| value of |[-90]|.
3278 \begin{itemize}
3279 \item |\tznormal*{AA}{1}{3cm}[-90]| is equivalent to |\tznormal*'{AA}{1}{3cm}|.
3280 \item |\tznomral*'| does not change its direction with the option |[<rotate>]|.
3281 \end{itemize}
3282
3283
3284 \begin{tzcode}{.3}
3285 % \tznormal*(')
3286 \begin{tikzpicture}
3287 \tzhelplines*(5,4)
3288 \tzcoors*(0,0)(A)(2,2)(B){B}[b](3.5,1)(C)(5,3)(D);
3289 \tztos[thick]"AA"(A)[out=0,in=180]
3290 (B)[out=0,in=180]
3291 (C)[out=0,in=255]
3292 (D);
3293 \tzslopeat[red,thick]{AA}{1}{3cm}
3294 \tzslopeat[blue]{AA}{2}{2cm}
3295 \tzslopeat{AA}{4}{2cm}{$f'(4)$}[r]
3296 \tznormal*[->,red,thick]{AA}(1,0){3cm}
3297 \tznormal*[->,blue]{AA}(B){2cm}
3298 \tznormal*'[->]{AA}(4,0){2cm}{normal}[r]
3299 \end{tikzpicture}
3300 \end{tzcode}
3301