| 1 |
%!TEX root = tzplot-doc.tex |
| 2 |
%\begin{document} |
| 3 |
|
| 4 |
%%%%%=====CNONTINUED============ |
| 5 |
%%%%%%========================== |
| 6 |
%%%\part{Points, Lines, and Curves} |
| 7 |
%%%%%%========================== |
| 8 |
%%%\label{p:linesandcurves} |
| 9 |
|
| 10 |
|
| 11 |
%%================================== |
| 12 |
\chapter{Connecting Points} |
| 13 |
\label{c:tzto} |
| 14 |
|
| 15 |
%%%------------------------------------------------------------ |
| 16 |
\section{\protect\cmd{\tzto}: Two points} |
| 17 |
\label{s:tzto} |
| 18 |
|
| 19 |
\icmd{\tzto} connects two points with a straight or curved line, using \Tikz's |to| operation. |
| 20 |
So |\tzto| is more general than |\tzline|, which only connects points only with a straight line. |
| 21 |
|
| 22 |
\begin{tzdef} |
| 23 |
% syntax: minimum |
| 24 |
\tzto(<coor>)(<coor>) |
| 25 |
% syntax: medium |
| 26 |
\tzto[<opt>](<coor>){<text>}[<node opt>](<coor>){<text>}[<node opt>] |
| 27 |
% syntax: full |
| 28 |
\tzto[<opt>]<shift coor>"<path name>" |
| 29 |
(<coor>){<text>}[<node opt>] |
| 30 |
(<coor>){<text>}[<node opt>]<code.append> |
| 31 |
% defaults |
| 32 |
[]<>""(<m>){}[above](<m>){}[]<> |
| 33 |
\end{tzdef} |
| 34 |
|
| 35 |
|
| 36 |
\begin{tztikz} |
| 37 |
\tzto[dashed](1,1)(3,2) % works like: |
| 38 |
\draw [dashed] (1,1) to (3,2); |
| 39 |
\end{tztikz} |
| 40 |
|
| 41 |
|
| 42 |
\paragraph{Line styles} |
| 43 |
You can control line styles with the first optional argument |[<opt>]|. |
| 44 |
|
| 45 |
\begin{tzcode}{.3} |
| 46 |
% \tzto |
| 47 |
\begin{tikzpicture} |
| 48 |
\tzhelplines(4,3) |
| 49 |
\tzto[blue,thick](0,1)(3,3) |
| 50 |
\tzto[out=0](0,0)(4,2) |
| 51 |
\tzto[bend right,dashed](2,0)(4,1) |
| 52 |
\settzmidarrow{o}[very thick,red] |
| 53 |
\tzarc(2,2)(180:45:1cm) |
| 54 |
\end{tikzpicture} |
| 55 |
\end{tzcode} |
| 56 |
|
| 57 |
\paragraph{Adding text} |
| 58 |
|
| 59 |
You can add text \xem{next to the line} (|[midway,above]|, by default) by specifying the options |{<text>}| and |[<node opt>]| \xem{in-between} the two coordinates. |
| 60 |
|
| 61 |
\begin{tztikz} |
| 62 |
\tzto[->,bend right](1,1){A}[near start](3,2) % works like: |
| 63 |
\draw [->,bend right] (1,1) to node [near start] {A} (3,2); |
| 64 |
|
| 65 |
\tzto[->,bend right](1,1){A}[near start](3,2){B}[right] % works like: |
| 66 |
\draw [->,bend right] (1,1) to node [near start] {A} |
| 67 |
(3,2) node [right] {B}; |
| 68 |
\end{tztikz} |
| 69 |
|
| 70 |
|
| 71 |
You can also add text \xem{at or around} the last coordinate by the options |{<text>}| and |[<node opt>]| \xem{immediately after} the last coordinate. |
| 72 |
|
| 73 |
\begin{tzcode}{.3} |
| 74 |
% \tzto: adding text |
| 75 |
\begin{tikzpicture} |
| 76 |
\tzhelplines(4,3) |
| 77 |
\tzto[blue,thick,->](0,1){line}[sloped](3,3) |
| 78 |
\tzto[out=0](0,0){curve}[pos=.8](4,2){line B}[r] |
| 79 |
\tzto[bend right,dashed](2,0)(4,1){line C}[red,r] |
| 80 |
\end{tikzpicture} |
| 81 |
\end{tzcode} |
| 82 |
|
| 83 |
\paragraph{Shift} |
| 84 |
You can move the line by specifying the option |<shift coor>| before the first coordinate or immediately before the option |"<path name>"| if it exists. |
| 85 |
(The \xem{empty} shift option |<>| is \xem{not allowed}.) |
| 86 |
|
| 87 |
\begin{tzcode}{.3} |
| 88 |
% \tzto: shift |
| 89 |
\begin{tikzpicture} |
| 90 |
\tzhelplines(4,3) |
| 91 |
\tzto[blue,thick,->]<0,1>(0,1){line}[sloped](3,3) |
| 92 |
\tzto[out=0]<1,1>(0,0){curve}[pos=.8](4,2){line B}[r] |
| 93 |
\tzto[bend right,dashed]<-1,0>(2,0)(4,1){line C}[red,r] |
| 94 |
\end{tikzpicture} |
| 95 |
\end{tzcode} |
| 96 |
|
| 97 |
\paragraph{Naming paths: Intersections} |
| 98 |
You can name the path of |\tzto| by specifying the option |"<path name>"| immediately before the first coordinate. |
| 99 |
|
| 100 |
\begin{tzcode}{.3} |
| 101 |
% \tzto: name path |
| 102 |
\begin{tikzpicture} |
| 103 |
\tzhelplines(4,3) |
| 104 |
\tzto[bend right=45,blue,thick,->]"curveA"(1,3)(4,0) |
| 105 |
\tzto[out=0]"curveB"(0,0)(4,2){line B}[r] |
| 106 |
% intersection point |
| 107 |
\tzXpoint*{curveA}{curveB} |
| 108 |
\end{tikzpicture} |
| 109 |
\end{tzcode} |
| 110 |
|
| 111 |
\paragraph{Extending the path} |
| 112 |
You can extend the path of |\tzto| by writing \Tikz\ code in the last optional argument |<code.append>|. |
| 113 |
|
| 114 |
\begin{tzcode}{.3} |
| 115 |
% \tzto: extending path |
| 116 |
\begin{tikzpicture} |
| 117 |
\tzhelplines(4,3) |
| 118 |
\tzto[bend right=45,blue,thick,->](1,3)(4,0) |
| 119 |
<--([turn]0:1cm) node [b] {extended}> |
| 120 |
\tzto[out=0](0,0)(4,2) |
| 121 |
<--([turn]0:1cm) node [r] {extended}> |
| 122 |
\end{tikzpicture} |
| 123 |
\end{tzcode} |
| 124 |
|
| 125 |
You can also use \icmd{\tztoAtBegin} and \icmd{\tztoAtEnd} to extend a path of |\tzto| at the beginning and at the end, respectively. |
| 126 |
Specifying |<code.append>| extends the path after |\tztoAtEnd|. |
| 127 |
|
| 128 |
\begin{tzcode}{.3} |
| 129 |
% \tzto: extending path |
| 130 |
\begin{tikzpicture} |
| 131 |
\tzhelplines(4,3) |
| 132 |
\tztoAtBegin{(0,2) to [bend left]} |
| 133 |
\tztoAtEnd{--([turn]0:1cm) node [b] {extended}} |
| 134 |
\tzto[bend right=45,blue,thick,->](1,3)(4,0) |
| 135 |
\tztoAtEnd{--([turn]0:1cm) node [r] {extended}} |
| 136 |
\tzto[out=0](0,0)(4,2) |
| 137 |
\end{tikzpicture} |
| 138 |
\end{tzcode} |
| 139 |
|
| 140 |
|
| 141 |
%%------------------------------------------------------------ |
| 142 |
\section{\protect\cmd{\tzto+}: Relative coordinates} |
| 143 |
\label{s:tzto+} |
| 144 |
|
| 145 |
The \iisw{plus version} \icmd{\tzto+} uses the second coordinate relative to the first coordinate. |
| 146 |
|
| 147 |
\xem{Everything else is the same as in} |\tzto|. |
| 148 |
|
| 149 |
\begin{tztikz} |
| 150 |
\tzto+(1,1)(3,2) % works like: |
| 151 |
\draw (1,1) to ++(3,2); |
| 152 |
\end{tztikz} |
| 153 |
|
| 154 |
\begin{tzcode}{.3} |
| 155 |
% \tzto+ |
| 156 |
\begin{tikzpicture} |
| 157 |
\tzhelplines(4,3) |
| 158 |
\tzto+[blue,thick,->](0,1){line}[sloped](3,2) |
| 159 |
\tzto+[out=0](0,0){curve}[pos=.8](4,2){line B}[r] |
| 160 |
\tzto+[bend right,dashed](2,0)(2,1){line C}[red,r] |
| 161 |
\end{tikzpicture} |
| 162 |
\end{tzcode} |
| 163 |
|
| 164 |
\begin{tzcode}{.3} |
| 165 |
% \tzto+ |
| 166 |
\begin{tikzpicture} |
| 167 |
\tzhelplines(4,3) |
| 168 |
\tzto+[bend right=45,blue,thick,->](1,3)(3,-3) |
| 169 |
<--([turn]0:1cm) node [b] {extended}> |
| 170 |
\tzto+[out=0](0,0)(4,2) |
| 171 |
<--([turn]0:1cm) node [r] {extended}> |
| 172 |
\end{tikzpicture} |
| 173 |
\end{tzcode} |
| 174 |
|
| 175 |
|
| 176 |
\begin{tzcode}{.3} |
| 177 |
% \tzto: extending path |
| 178 |
\begin{tikzpicture} |
| 179 |
\tzhelplines(4,3) |
| 180 |
\tztoAtBegin{(0,2) to [bend left]} |
| 181 |
\tztoAtEnd{--([turn]0:1cm) node [b] {extended}} |
| 182 |
\tzto+[bend right=45,blue,thick,->](1,3)(3,-3) |
| 183 |
\tztoAtEnd{--([turn]0:1cm) node [r] {extended}} |
| 184 |
\tzto+[out=0](0,0)(4,2) |
| 185 |
\end{tikzpicture} |
| 186 |
\end{tzcode} |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
%%------------------------------------------------------------ |
| 192 |
\section{\protect\cmd{\tztos}: Multiple points: Semicolon version} |
| 193 |
\label{s:tztos} |
| 194 |
|
| 195 |
\icmd{\tztos} takes an arbitrary number of coordinates as arguments to connect them by the \Tikz's |to| operation. |\tztos| is much more flexible than |\tzlines|. Since this is a \xem{semicolon version}, you need to enter a \xem{semicolon} to indicate when the coordinate iteration ends. |
| 196 |
|
| 197 |
\begin{tzdef} |
| 198 |
% syntax |
| 199 |
\tztos[<opt>]<shift coor>"<path name>" |
| 200 |
(<coor1>)[<to opt>]{<text>}[<node opt>]..repeated..()[]{}[] ; <code.append> |
| 201 |
% defaults |
| 202 |
[]<>""(<m>)[]{}[]..repeated..()[]{}[];<> |
| 203 |
\end{tzdef} |
| 204 |
|
| 205 |
The quadruple |(<coor>)[<to opt>]{<text>}[<node opt>]| is |
| 206 |
the whole repeating pattern. |
| 207 |
Here, |[<to opt>]| is for the options of \Tikz's |to| operation such as |[bend right]|, |[bend left]|, |[bend left=<angle>]|, |[out=<angle>,in=<angle>]| and so on. |
| 208 |
|
| 209 |
\begin{tztikz} |
| 210 |
\tztos(0,0)(1,2)(3,1); % works like: |
| 211 |
\draw (0,0) to (1,2) to (3,1); |
| 212 |
\end{tztikz} |
| 213 |
|
| 214 |
\begin{tztikz} |
| 215 |
\tztos[blue] (0,0) [bend right] (1,2) [out=-60,in=45] (3,1); % works like: |
| 216 |
\draw[blue] (0,0) to [bend right] (1,2) to [out=-60,in=45] (3,1); |
| 217 |
\end{tztikz} |
| 218 |
|
| 219 |
\paragraph{How to connect coordinates} |
| 220 |
You can use the options of \Tikz's |to| operation to connect the coordinates with different types of curves. |
| 221 |
|
| 222 |
\begin{tzcode}{.3} |
| 223 |
% \tztos |
| 224 |
\begin{tikzpicture} |
| 225 |
\tzhelplines(4,3) |
| 226 |
\tztos[blue,<->](0,1)(1,2)(3,1)(4,3); |
| 227 |
\tztos[red,thick] |
| 228 |
(0,0)[bend right] |
| 229 |
(1,1) |
| 230 |
(2,1)[out=-135,in=45] |
| 231 |
(3,0); |
| 232 |
\end{tikzpicture} |
| 233 |
\end{tzcode} |
| 234 |
|
| 235 |
\begin{tzcode}{.3} |
| 236 |
% \tztos |
| 237 |
\begin{tikzpicture} |
| 238 |
\tzhelplines(4,3) |
| 239 |
\tzcoors*(0,0)(A)(1,2)(B){B}[b](3,3)(C)(4,2)(D); |
| 240 |
\tztos(A)[out=80,in=180] |
| 241 |
(B)[out=0,in=180] |
| 242 |
(C)[out=0,in=180] |
| 243 |
(D){End!}[r]; |
| 244 |
\end{tikzpicture} |
| 245 |
\end{tzcode} |
| 246 |
|
| 247 |
\paragraph{Adding text} |
| 248 |
You can add text next to lines or curves by specifying the options |{<text>}| and |[<node opt>]| \xem{in-between} coordinates or \xem{after} the option |[<to opt>]|, if it exists. |
| 249 |
You can also add text at or around the last coordinate by the last options |{<text>}| and |[<node opt>]|. |
| 250 |
|
| 251 |
\begin{tzcode}{.3} |
| 252 |
% \tztos: adding text |
| 253 |
\begin{tikzpicture} |
| 254 |
\tzhelplines(4,3) |
| 255 |
\tztos(0,1)[bend right]{A} |
| 256 |
(1,2) {Ben}[red,sloped,a] |
| 257 |
(3,1)[bend right]{Cate}[sloped,near end] |
| 258 |
(4,3) {Name}[draw,blue,a] ; |
| 259 |
\end{tikzpicture} |
| 260 |
\end{tzcode} |
| 261 |
|
| 262 |
\paragraph{Shift} |
| 263 |
You can move the line or curve of |\tztos| |
| 264 |
using the option |<shift coor>| before the first coordinate or immediately before the option |"<path name">|, if any. |
| 265 |
(The empty shift option |<>| is not allowed.) |
| 266 |
|
| 267 |
\begin{tzcode}{.3} |
| 268 |
% \tztos: shift |
| 269 |
\begin{tikzpicture} |
| 270 |
\tzhelplines(4,3) |
| 271 |
\tzdot(0,0) |
| 272 |
\tztos[blue,<->](0,1)(1,2)(3,1)(4,3); |
| 273 |
\tztos[red,thick] |
| 274 |
<1,1>(0,0)[bend right] |
| 275 |
(1,1) |
| 276 |
(2,1)[out=-135,in=45] |
| 277 |
(3,0); |
| 278 |
\end{tikzpicture} |
| 279 |
\end{tzcode} |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
\paragraph{Naming paths: intersections} |
| 284 |
You can name the path of |\tztos| by specifying |"<path name>"| immediately before the first mandatory coordinate. |
| 285 |
|
| 286 |
\begin{tzcode}{.3} |
| 287 |
% \tztos: name path, intersection points |
| 288 |
\begin{tikzpicture} |
| 289 |
\tzhelplines(4,3) |
| 290 |
\tzdot(0,0) |
| 291 |
\tztos[blue,<->]"AA"(0,1)(1,2)(3,1)(4,3); |
| 292 |
\tztos[red,thick] |
| 293 |
<1,1>"BB"(0,0)[bend right] |
| 294 |
(1,1) |
| 295 |
(2,1)[out=-135,in=45] |
| 296 |
(3,0); |
| 297 |
% intersection points |
| 298 |
\tzXpoint*{AA}{BB}(X) |
| 299 |
\tzdot(X-2)(4pt) |
| 300 |
\end{tikzpicture} |
| 301 |
\end{tzcode} |
| 302 |
|
| 303 |
|
| 304 |
\paragraph{Extending paths} |
| 305 |
You can extend the path of |\tztos| from the last coordinate, |
| 306 |
by writing \Tikz\ code in the last (after the semicolon) optional argument |<code.append>|. |
| 307 |
|
| 308 |
\begin{tzcode}{.3} |
| 309 |
% \tztos |
| 310 |
\begin{tikzpicture} |
| 311 |
\tzhelplines(4,3) |
| 312 |
\tztos[blue](0,1)(1,2)(3,1)(4,3);<--cycle> |
| 313 |
\tztos[red,thick] |
| 314 |
(0,0)[bend right] |
| 315 |
(1,1) |
| 316 |
(2,1)[out=-135,in=45] |
| 317 |
(3,0); < to ([turn]0:1.5cm) > |
| 318 |
\end{tikzpicture} |
| 319 |
\end{tzcode} |
| 320 |
|
| 321 |
You can also use \icmd{\tztosAtBegin} and \icmd{\tztosAtEnd} to extend a path of |\tztos| at the beginning and at the end, respectively. |
| 322 |
Specifying the option |<code.append>| extends the path after |\tztosAtEnd|. |
| 323 |
|
| 324 |
\begin{tzcode}{.3} |
| 325 |
% \tztos |
| 326 |
\begin{tikzpicture} |
| 327 |
\tzhelplines(4,3) |
| 328 |
\tztos[blue](0,1)(1,2)(3,1)(4,3);<--cycle> |
| 329 |
\tztosAtBegin{ (1,3) -| } |
| 330 |
\tztosAtEnd{ to ([turn]0:1.5cm) } |
| 331 |
\tztos[red,thick] |
| 332 |
(0,0)[bend right] |
| 333 |
(1,1) |
| 334 |
(2,1)[out=-135,in=45] |
| 335 |
(3,0); |
| 336 |
\end{tikzpicture} |
| 337 |
\end{tzcode} |
| 338 |
|
| 339 |
%%------------------------------------------------------------ |
| 340 |
\section{\protect\cmd{\tztos+}: Relative coordinates: Semicolon version} |
| 341 |
\label{s:tztos+} |
| 342 |
|
| 343 |
The \iisw{plus version} \icmd{\tztos+} takes each coordinate (except the first coordinate) relative (with |++|) to the previous coordinate. |
| 344 |
|
| 345 |
\xem{Everything else is the same as in} |\tztos|. |
| 346 |
|
| 347 |
\begin{tzcode}{.3} |
| 348 |
% \tztos+ |
| 349 |
\begin{tikzpicture} |
| 350 |
\tzhelplines(4,3) |
| 351 |
\tztos+[blue](0,1)(1,1)(2,-1)(1,2);<--cycle> |
| 352 |
\tztos+[red,thick] |
| 353 |
(0,0)[bend right] |
| 354 |
(1,1) |
| 355 |
(1,0)[out=-135,in=45] |
| 356 |
(1,-1); < to ([turn]0:1.5cm) > |
| 357 |
\end{tikzpicture} |
| 358 |
\end{tzcode} |
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
\section{\protect\cmd{\tzlink}: Two points} |
| 363 |
\label{s:tzlink} |
| 364 |
|
| 365 |
\icmd{\tzlink} is a \xem{generalized version} of |\tzline|. |
| 366 |
You can decide the style that links two coordinates. |
| 367 |
|
| 368 |
The default link style is |to|, which can be changed with the \xem{second} optional argument |[<code1>]| \xem{between two coordinates} like, for example, \verb+(<coor1>)[-|](<coor2>)+. |
| 369 |
Another way is to use the \xem{first} curly brace option |{<link style>}|. |
| 370 |
You can also change it by \icmd{\settzlinkstyle} like, for example, \verb+\settzlinkstyle{-|}+, which is effective until the end of the |tikzpicture| environment. |
| 371 |
|
| 372 |
\begin{tzdef} |
| 373 |
% syntax: minimum |
| 374 |
\tzlink(<coor1>)(<coor2>) % default: to |
| 375 |
% syntax: medium |
| 376 |
\tzlink[<opt>](<coor1>)[<code1>](coor2>) % change link style by [<code1>] |
| 377 |
% syntax: full |
| 378 |
\tzlink{<link style>}[<opt>]<shift coor>"<path name>" |
| 379 |
(<coor1>)[<code1>]{<text1>}[<node opt1>]<code2> |
| 380 |
(<coor2>){<text2>}[<node opt2>]<code.append> |
| 381 |
% remark: |
| 382 |
- {<link style>}: % default: to |
| 383 |
- [<code1>]: --, -|, to, edge, etc. (optionally more appropriate tikz code) |
| 384 |
- <code2>: + or ++ (possibly with other tikz code) |
| 385 |
- {<text1>}: node text next to line |
| 386 |
- {<text2>}: node text at the last coordinate |
| 387 |
% defaults |
| 388 |
{to}[]<>""(<m>)[]{}[above]<>(<m>){}[]<> |
| 389 |
\end{tzdef} |
| 390 |
|
| 391 |
\begin{tztikz} |
| 392 |
\tzlink(1,0)(3,1) % works like: |
| 393 |
\draw (1,0) to (3,1); |
| 394 |
\end{tztikz} |
| 395 |
|
| 396 |
\begin{tztikz} |
| 397 |
\tzlink(1,0)[-|]<++>(3,1) % works like: |
| 398 |
\draw (1,0) -| ++ (3,1); |
| 399 |
\end{tztikz} |
| 400 |
|
| 401 |
|
| 402 |
\paragraph{Link styles} You can change the link style (|to| by default) using the optional argument |[<code1>]| \xem{immediately after} the first coordinate. |
| 403 |
|
| 404 |
\begin{tzcode}{.3} |
| 405 |
% \tzlink: to (default link style) |
| 406 |
\begin{tikzpicture} |
| 407 |
\tzhelplines(4,3) |
| 408 |
\tzlink[->](0,0)(1,0) |
| 409 |
\tzlink[->,bend right](0,2)(3,0) |
| 410 |
\tzlink[->](1,2)[-|](4,1) |
| 411 |
\end{tikzpicture} |
| 412 |
\end{tzcode} |
| 413 |
|
| 414 |
You can also use \icmd{\settzlinkstyle} to change the link style. Its effect is valid until the end of the |tikzpicture| environment, unless changed again. |
| 415 |
|
| 416 |
\begin{tzcode}{.3} |
| 417 |
% \settzlinkstyle |
| 418 |
\begin{tikzpicture} |
| 419 |
\tzhelplines(4,3) |
| 420 |
\settzlinkstyle{to[bend left]} %% |
| 421 |
\tzlink[->](0,0)(1,0) |
| 422 |
\tzlink[->](0,2)[--](3,0) % local change |
| 423 |
\tzlink[->](1,2)(4,1) |
| 424 |
\end{tikzpicture} |
| 425 |
\end{tzcode} |
| 426 |
|
| 427 |
The \iisw{plus version} \icmd{\tzlink+} uses the second coordinate relative (with |++|, by default) to the first one. |
| 428 |
Everything else is the same as in |\tzlink|. |
| 429 |
|
| 430 |
|
| 431 |
\begin{tztikz} |
| 432 |
\tzlink (1,0)[to[bend right]]{A}[a]<++>(3,1) % or |
| 433 |
\tzlink+(1,0)[to[bend right]]{A}[a] (3,1) % works like: |
| 434 |
\draw (1,0) to[bend right] node [above] {A} ++ (3,1); |
| 435 |
\end{tztikz} |
| 436 |
|
| 437 |
|
| 438 |
\begin{tzcode}{.3} |
| 439 |
% \tzlink(+): various link styles |
| 440 |
\begin{tikzpicture} |
| 441 |
\tzhelplines(4,3) |
| 442 |
\tzlink[->,blue,out=90,in=180](0,2)(3,0) |
| 443 |
\tzlink+[->,dashed,blue](1,2)[to[bend left]](3,-1) |
| 444 |
\tzlink[->](0,0)[..controls (1,1) and (3,0)..](4,2) |
| 445 |
\tzlink+[red,thick](1,0)[edge[bend left]](2,3) |
| 446 |
\end{tikzpicture} |
| 447 |
\end{tzcode} |
| 448 |
|
| 449 |
\paragraph{Adding text} |
| 450 |
|
| 451 |
You can add text next to the line or curve of |\tzlink| by specifying the option |{<text1>}| followed by the optional argument |[<node opt1>]| \xem{between} two coordinates (or after the option |[<code1>]| if it exists). |
| 452 |
|
| 453 |
You can name the line or curve of |\tzlink| by specifying the optional arguments |{<text2>}| and |[<node opt2>]| \xem{after} the second coordinate. The option |[<node opt2>]| is often for the position of node text at or around the second coordinate. |
| 454 |
|
| 455 |
\begin{tzcode}{.3} |
| 456 |
% \tzlink |
| 457 |
\begin{tikzpicture} |
| 458 |
\tzhelplines(4,3) |
| 459 |
\tzlink[->](1,3){line A}(4,3) |
| 460 |
\tzlink[blue](0,3){line B}[sloped](3,0){E}[r] |
| 461 |
\tzlink[->,red](1,0){Start}[at start,l](4,2){Line C}[r] |
| 462 |
\end{tikzpicture} |
| 463 |
\end{tzcode} |
| 464 |
|
| 465 |
\begin{tzcode}{.3} |
| 466 |
% \tzlink(+) |
| 467 |
\begin{tikzpicture} |
| 468 |
\tzhelplines(4,3) |
| 469 |
\tzlink[->](0,0){A}(1,0) |
| 470 |
\tzlink+[bend right](0,2){curve}[sloped](3,-2){End}[r] |
| 471 |
\tzlink[->,auto](1,2)[-|]{B}(4,1){Goal!}[b,draw,blue] |
| 472 |
\end{tikzpicture} |
| 473 |
\end{tzcode} |
| 474 |
|
| 475 |
|
| 476 |
\paragraph{Shift} |
| 477 |
You can move the line or curve by specifying the option |<shift coor>| \xem{before} the first coordinate (or ever before the option |"<path name>"| if it exists). |
| 478 |
|
| 479 |
\begin{tzcode}{.3} |
| 480 |
% \tzlink(+): shift |
| 481 |
\begin{tikzpicture} |
| 482 |
\tzhelplines(4,3) |
| 483 |
\tzlink+[bend right](0,2)(3,-2){A}[r] |
| 484 |
\tzlink+[bend right]<.5,.5>(0,2)(3,-2){A-shifted}[r] |
| 485 |
\tzlink[->](1,2)[-|](4,1) |
| 486 |
\tzlink[->,dashed]<-.2,.3>(1,2)[-|](4,1) |
| 487 |
\end{tikzpicture} |
| 488 |
\end{tzcode} |
| 489 |
|
| 490 |
\paragraph{Naming paths: Intersections} |
| 491 |
You can name the path of |\tzlink| by specifying the quote option |"<path name>"| \xem{immediately before} the first coordinate. |
| 492 |
You can use the path names of two paths to find an intersection point. |
| 493 |
|
| 494 |
\begin{tzcode}{.3} |
| 495 |
% \tzlink(+): path name: intersection |
| 496 |
\begin{tikzpicture} |
| 497 |
\tzhelplines(4,3) |
| 498 |
\tzlink[blue]"BB"(0,3){line B}[sloped](3,0) |
| 499 |
\tzlink+[->,red,bend right]"CC"(1,0)(3,2){Line C}[r] |
| 500 |
\tzXpoint{BB}{CC}(E) % instersection |
| 501 |
\tzdot*(E){E}[a] |
| 502 |
\end{tikzpicture} |
| 503 |
\end{tzcode} |
| 504 |
|
| 505 |
|
| 506 |
\paragraph{Extending paths} |
| 507 |
You can extend the path of |\tzlink| by specifying \Tikz\ code in the last optional argument |<code.append>|. |
| 508 |
You can also use the macros \icmd{\tzlinkAtBegin} and \icmd{\tzlinkAtEnd} to extend the path at the beginning and at the end, respectively. |
| 509 |
Specifying the option |<code.append>| extends the path after |\tzlinkAtEnd|. |
| 510 |
|
| 511 |
\begin{tzcode}{.3} |
| 512 |
% \tzlink(+): path name: intersection |
| 513 |
\begin{tikzpicture} |
| 514 |
\tzhelplines(4,3) |
| 515 |
\tzlinkAtBegin{(1,1) to[bend left]} |
| 516 |
\tzlinkAtEnd{arc (180:90:1cm) node [r,draw] {BB}} |
| 517 |
\tzlink[blue]"BB"(0,3){line B}[sloped](3,0) |
| 518 |
\tzlink+[->,red,bend right]"CC"(1,0)(3,2){Line C}[r] |
| 519 |
< -| ++(-1,1) node [a] {End!} > |
| 520 |
\tzXpoint{BB}{CC}(E) |
| 521 |
\tzdot*(E){E}[a] |
| 522 |
\end{tikzpicture} |
| 523 |
\end{tzcode} |
| 524 |
|
| 525 |
|
| 526 |
%%------------------------------------------------------------ |
| 527 |
\section{\protect\cmd{\tzlinks}: All in one: Semicolon versions} |
| 528 |
\label{s:tzlinks} |
| 529 |
|
| 530 |
\subsection{\protect\cmd{\tzlinks}: Standard version} |
| 531 |
\label{ss:tzlinks} |
| 532 |
|
| 533 |
The macro \icmd{\tzlinks} is a \iisw{semicolon version} of |\tzlink|. |\tzlinks| accepts any number of coordinates to connect them with connected line segments or curves. |
| 534 |
You can change how two adjacent points are connected. |
| 535 |
|\tzlinks| is quite \xem{flexible} that you can think of it as a \xem{generalized version} of |\tzlines|. |
| 536 |
|
| 537 |
|
| 538 |
\begin{tzdef} |
| 539 |
% syntax: minimum |
| 540 |
\tzlinks (<coor>)(<coor>) ..repeated.. (<coor>) ; |
| 541 |
% syntax: full |
| 542 |
\tzlinks{<path style>}[<opt>]<shift coor>"<path name>" |
| 543 |
(<coor>)[<code1>]{<text>}[<node opt>]<code2> |
| 544 |
..repeated.. ()[]{}[]<> ; {<fill opacity>} <code.append> |
| 545 |
% remark: |
| 546 |
- <code1> must be link style, such as --, to, -|, etc. |
| 547 |
(possibly followed by other code) |
| 548 |
- <code2> is especially for + or ++ |
| 549 |
(possibly with other code) |
| 550 |
- repetition MUST be ended by ; (semicolon) |
| 551 |
- full repeating pattern is ()[]{}[]<>..repeated..()[]{}[]<> |
| 552 |
- {<fill opacity>} works only in \tzlinks* |
| 553 |
% defaults: \tzlinks, \tzlinks*, \tzlinks+, \tzlinks*+ |
| 554 |
{to}[]<>"" (<m>)[]{}[]<> ..repeated.. ()[]{}[]<> ; { }<> |
| 555 |
*{to}[fill=black!50,fill opacity=.3,text opacity=1] |
| 556 |
<>"" (<m>)[]{}[]<> ..repeated.. ()[]{}[]<> ; {.3}<> |
| 557 |
+{to}[]<>"" (<m>)[]{}[]<++> ..repeated.. ()[]{}[]<> ; { }<> |
| 558 |
\end{tzdef} |
| 559 |
|
| 560 |
\paragraph{How to change link styles} |
| 561 |
There are three ways of changing link styles: |
| 562 |
\begin{itemize}\firmlist |
| 563 |
\item The fist curly brace option |{<link style>}| controls the link style of connecting any two coordinates. |
| 564 |
\item The second bracket option |[<code1>]| (locally) changes the link style of two adjacent coordinates. |[<code1>]| (locally) overrides |{<link style>}|. |
| 565 |
\item The effect of the macro |\settzlinkstyle| remains until the end of |tikzpicture| environment, unless changed again. |
| 566 |
\end{itemize} |
| 567 |
|
| 568 |
\begin{tztikz} |
| 569 |
% standard version |
| 570 |
\tzlinks(1,1)(2,2)(3,1)(4,3); % works like: |
| 571 |
\draw (1,1) to (2,2) to (3,1) to (4,3); |
| 572 |
\end{tztikz} |
| 573 |
|
| 574 |
\begin{tzcode}{.3} |
| 575 |
% \tzlinks |
| 576 |
\begin{tikzpicture} |
| 577 |
\tzhelplines(4,3) |
| 578 |
\tzlinks(0,1)(1,2)(3,1)(4,3); |
| 579 |
\end{tikzpicture} |
| 580 |
\end{tzcode} |
| 581 |
|
| 582 |
The default path style is |to|, which can be by \icmd{\settzlinkstyle}. |
| 583 |
The effect remains valid until the end of |tikzpicture| environment unless changed again. |
| 584 |
|
| 585 |
\begin{tzcode}{.3} |
| 586 |
% \tzlinks: \settzlinkstyle |
| 587 |
\begin{tikzpicture} |
| 588 |
\tzhelplines(4,3) |
| 589 |
\settzlinkstyle{to[bend right]} %% |
| 590 |
\tzlinks[dashed](0,1)(1,2)[-|](3,1)(4,3); |
| 591 |
\tzlinks[blue] |
| 592 |
(0,0) |
| 593 |
(1,1) |
| 594 |
(2,1)[to[out=-135,in=45]] |
| 595 |
(3,0); |
| 596 |
\end{tikzpicture} |
| 597 |
\end{tzcode} |
| 598 |
|
| 599 |
|
| 600 |
\begin{tzcode}{.3} |
| 601 |
% \tzlinks: various link styles |
| 602 |
\begin{tikzpicture} |
| 603 |
\tzhelplines(4,3) |
| 604 |
\tzlinks[->](1,2)[-|] |
| 605 |
(0,0)[..controls (1,2) and (2,0)..] |
| 606 |
(3,1)[to[bend left]]<++> |
| 607 |
(1,2); |
| 608 |
\end{tikzpicture} |
| 609 |
\end{tzcode} |
| 610 |
|
| 611 |
|
| 612 |
\begin{tzcode}{.3} |
| 613 |
% \tzlinks: various link styles |
| 614 |
\begin{tikzpicture} |
| 615 |
\tzhelplines(4,3) |
| 616 |
\tzlinks[->](1,1)<++> |
| 617 |
(1,1)[[rounded corners=10pt]--] |
| 618 |
(0,3) |
| 619 |
(0,0)[[sharp corners]--] |
| 620 |
(4,0)<++> |
| 621 |
(-1,2); |
| 622 |
\end{tikzpicture} |
| 623 |
\end{tzcode} |
| 624 |
|
| 625 |
|
| 626 |
\begin{tzcode}{.3} |
| 627 |
% \tzlinks: edge |
| 628 |
\begin{tikzpicture} |
| 629 |
\tzhelplines(4,3) |
| 630 |
\tzlinks(0,1)(1,2)[edge[dashed]]<(3,1)>(3,1)(4,3); |
| 631 |
\end{tikzpicture} |
| 632 |
\end{tzcode} |
| 633 |
|
| 634 |
\remark |
| 635 |
In \Tikz, |edge| is not part of the main path. |
| 636 |
So you need to be careful when you move the path or find intersection points. |
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
\subsection{\protect\cmd{\tzlinks+}, \protect\cmd{\tzlinks*}, \protect\cmd{\tzlinks*+}: Variants} |
| 641 |
\label{ss:tzlinks-variants} |
| 642 |
|
| 643 |
The \iisw{plus version} \icmd{\tzlinks+} treats a coordinate as relative (with |++| by default) to the previous coordinate, except the first coordinate. |
| 644 |
|
| 645 |
\begin{tztikz} |
| 646 |
% plus (+) version |
| 647 |
\tzlinks+(1,1)(2,2){--}(3,1)(4,3); % works like: |
| 648 |
\draw (1,1) to ++(2,2) -- ++(3,1) to ++(4,3); |
| 649 |
\end{tztikz} |
| 650 |
|
| 651 |
\begin{tzcode}{.3} |
| 652 |
% \tzlinks+ |
| 653 |
\begin{tikzpicture} |
| 654 |
\tzhelplines(4,3) |
| 655 |
\tzlinks+(0,1)(1,1)[to[bend right]](2,-1)(1,2); |
| 656 |
\end{tikzpicture} |
| 657 |
\end{tzcode} |
| 658 |
|
| 659 |
The \xem{starred version} \icmd{\tzlinks*} is to fill the closed area formed by |\tzlinks| with color or pattern. The related default value is |[fill=black!50, fill opacity=.3, text opacity=1]|. |
| 660 |
In fact, |\tzlinks*[draw=none]| is (almost) the same as |\tzpath*| (See Section \ref{s:tzpath*} on page \pageref{s:tzpath*} for more details). |
| 661 |
|
| 662 |
\begin{tztikz} |
| 663 |
% starred (*) version |
| 664 |
\tzlinks*(1,1)(2,2)(3,1)(4,3); % works like: |
| 665 |
\draw [fill=black!50,fill opacity=.3,text opacity=1] |
| 666 |
(1,1) to (2,2) to (3,1) to (4,3); |
| 667 |
\end{tztikz} |
| 668 |
|
| 669 |
\icmd{\tzlinks*+} is the plus version of |\tzlinks*|. |
| 670 |
|
| 671 |
\begin{tzcode}{.3} |
| 672 |
% \tzlinks*+ |
| 673 |
\begin{tikzpicture} |
| 674 |
\tzhelplines(4,3) |
| 675 |
\tzlinks*+[thick](0,1)(1,1)[to[bend right]](2,-1)(1,2); |
| 676 |
\end{tikzpicture} |
| 677 |
\end{tzcode} |
| 678 |
|
| 679 |
\begin{tzcode}{.3} |
| 680 |
% \tzlinks: fill, fill opacity |
| 681 |
\begin{tikzpicture} |
| 682 |
\tzhelplines(4,3) |
| 683 |
\tzline[red,very thick](0,3)(4,0) |
| 684 |
\tzlinks[fill](0,0)(3,1)(2,3)(0,2); % default opacity=1 |
| 685 |
\tzlinks[fill=green,fill opacity=.5] |
| 686 |
<1,-1>(0,0)(3,1)(2,3)(0,2); |
| 687 |
\end{tikzpicture} |
| 688 |
\end{tzcode} |
| 689 |
|
| 690 |
You can also change the fill opacity by specifying the \xem{last} curly brace optional argument |{<fill opacity>}|, \xem{after the semicolon} (or before the option |<code.append>| it it exists). |
| 691 |
|
| 692 |
\begin{tzcode}{.3} |
| 693 |
% \tzlinks* |
| 694 |
\begin{tikzpicture} |
| 695 |
\tzhelplines(4,3) |
| 696 |
\settzfillcolor{green} |
| 697 |
\tzline[red,very thick](0,3)(4,0) |
| 698 |
\tzlinks*[blue](0,0)(3,1)(2,3)(0,2);{1} |
| 699 |
\tzlinks*%[green] |
| 700 |
<1,-1>(0,0)(3,1)(2,3)(0,2); {.5} %% |
| 701 |
\end{tikzpicture} |
| 702 |
\end{tzcode} |
| 703 |
|
| 704 |
You can also use the macros |\settzfillcolor| and |\settzfillopacity| to change the defaults. |
| 705 |
The effect remains valid until the end of the |tikzpicture| environment, unless changed again. |
| 706 |
|
| 707 |
%%------------------------------------------------------------ |
| 708 |
\subsection{Putting text, shift, intersections, and extending paths} |
| 709 |
\label{ss:tzlinks-add} |
| 710 |
|
| 711 |
|
| 712 |
\paragraph{Adding text} |
| 713 |
You can add text next to connected line segment or around the last coordinate by specifying options |{<text>}[<node option>]|. |
| 714 |
|
| 715 |
\begin{tztikz} |
| 716 |
\tzlinks+[dashed]"AA"(1,1){A}(2,2)[--]{B}[a]<+>(3,1){C}[b]; % works like |
| 717 |
\draw [dashed,name path=AA] |
| 718 |
(1,1) to node {A} |
| 719 |
++(2,2) -- node [above] {B} |
| 720 |
+(3,1) to node [below] {C} ; |
| 721 |
\end{tztikz} |
| 722 |
|
| 723 |
|
| 724 |
\begin{tzcode}{.3} |
| 725 |
% \tzlinks: adding text |
| 726 |
\begin{tikzpicture} |
| 727 |
\tzhelplines(4,3) |
| 728 |
\tzlinks[blue](0,0){Ace} |
| 729 |
(1,1){Beth}[sloped,a] |
| 730 |
(3,0){C} [near start] |
| 731 |
(4,2){End!}[draw,a=3pt]; |
| 732 |
\end{tikzpicture} |
| 733 |
\end{tzcode} |
| 734 |
|
| 735 |
\begin{tzcode}{.3} |
| 736 |
% \tzlinks: adding text |
| 737 |
\begin{tikzpicture} |
| 738 |
\tzhelplines(4,3) |
| 739 |
\tzlinks[->](1,1){start}[sloped,b]<++> |
| 740 |
(1,1)[[rounded corners=10pt]--]{K}[at end,a] |
| 741 |
(0,3){Rounded}[scale=0.7,font=\scshape,at end,ar] |
| 742 |
(0,0)[[sharp corners]--] |
| 743 |
(4,0)<++> |
| 744 |
(-1,2){End!}[draw,blue,a=3pt]; |
| 745 |
\end{tikzpicture} |
| 746 |
\end{tzcode} |
| 747 |
|
| 748 |
\begin{tzcode}{.3} |
| 749 |
% \tzlinks: edge |
| 750 |
\begin{tikzpicture} |
| 751 |
\tzhelplines(4,3) |
| 752 |
\tzlinks(0,1){start}[at start,b] |
| 753 |
(1,2)[edge[dashed,bend right]]{Go!}[sloped,b]<(3,1)> |
| 754 |
(3,1) |
| 755 |
(4,3){End\\here!}[align=center,r,draw,red] ; |
| 756 |
\end{tikzpicture} |
| 757 |
\end{tzcode} |
| 758 |
|
| 759 |
\remark Note that |edge| is not part of the main path. |
| 760 |
|
| 761 |
\paragraph{Shift} |
| 762 |
You can move the path of |\tzlinks| with the option |<shift coor>|. |
| 763 |
An \xem{empty} option |<>| is \xem{not allowed}. |
| 764 |
|
| 765 |
|
| 766 |
\begin{tzcode}{.3} |
| 767 |
% \tzlinks: |
| 768 |
\begin{tikzpicture} |
| 769 |
\tzhelplines(4,3) |
| 770 |
\tzlinks<.5,-1>(0,1){start}[at start,b] % shift |
| 771 |
(1,2)[to[dashed,bend right]]{Go!}[sloped,b] |
| 772 |
(3,1) |
| 773 |
(4,3){End\\here!}[align=center,r,draw,red] ; |
| 774 |
\end{tikzpicture} |
| 775 |
\end{tzcode} |
| 776 |
|
| 777 |
|
| 778 |
\paragraph{Naming paths: intersections} |
| 779 |
You can name the path of |\tzlinks| \xem{immediately befor} the first coordinate and use it to find intersection points. |
| 780 |
|
| 781 |
\begin{tzcode}{.3} |
| 782 |
% \tzlinks: edge |
| 783 |
\begin{tikzpicture} |
| 784 |
\tzhelplines(4,3) |
| 785 |
\tzlinks"AA"(0,1){start}[at start,b] |
| 786 |
(1,2)[edge[dashed,bend right]]{Go!}[sloped,b]<(3,1)> |
| 787 |
(3,1) |
| 788 |
(4,3){End\\here!}[align=center,r,draw,red] ; |
| 789 |
\tzhXpointat{AA}{1.5}(A) % horizontal intersections |
| 790 |
\tzdots*(A){\texttt{(A)}}(A-2){\texttt{(A-2)}}[0]; |
| 791 |
\end{tikzpicture} |
| 792 |
\end{tzcode} |
| 793 |
|
| 794 |
In the previous example, since |edge| is not part of the main path of |\tzlinks|, |
| 795 |
the second horizontal intersection point |(A-2)| is not on the |edge| curve. |
| 796 |
|
| 797 |
\paragraph{Extending paths} |
| 798 |
|
| 799 |
You can extend the path of |\tzlinks| by writing \Tikz\ code in the last (after the semicolon) optional argument |<code.append>|. |
| 800 |
So |<--cycle>| closes the path with a straight line. |
| 801 |
|
| 802 |
\begin{tzcode}{.3} |
| 803 |
% \tzlinks* <code.append> |
| 804 |
\begin{tikzpicture} |
| 805 |
\tzhelplines(4,3) |
| 806 |
\tzlinks*[blue](0,1)(1,2)[-|](3,1)(4,3); |
| 807 |
< to [bend right=60] (0,1) -- cycle > |
| 808 |
\tzlinks*[fill=red] |
| 809 |
(0,0)[to[bend right]] |
| 810 |
(1,1) |
| 811 |
(2,1)[to[out=-135,in=45]] |
| 812 |
(3,0); % not closed |
| 813 |
\end{tikzpicture} |
| 814 |
\end{tzcode} |
| 815 |
|
| 816 |
You can also use \icmd{\tzlinksAtBegin} and \icmd{\tzlinksAtEnd} to extend the path of |\tzlinks| at the beginning and at the end, respectively. |
| 817 |
Specifying the option |<code.append>| extends the path after |\tzlinksAtEnd|. |
| 818 |
|
| 819 |
\begin{tzcode}{.3} |
| 820 |
% \tzlinks*: extending paths |
| 821 |
\begin{tikzpicture} |
| 822 |
\tzhelplines(4,3) |
| 823 |
\tzlinksAtBegin{(0,2) to[bend left]} |
| 824 |
\tzlinksAtEnd{ to [out=210] (1,3) } |
| 825 |
\tzlinks*[blue](0,1)(1,2)[-|](3,1)(4,3); |
| 826 |
< -| (0,2) > |
| 827 |
\tzlinks*[fill=red] |
| 828 |
(0,0)[to[bend right]] |
| 829 |
(1,1) |
| 830 |
(2,1)[to[out=-135,in=45]] |
| 831 |
(3,0); <--cycle> |
| 832 |
\end{tikzpicture} |
| 833 |
\end{tzcode} |
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
%%================================== |
| 839 |
\chapter{Filling Area} |
| 840 |
\label{c:fillingarea} |
| 841 |
|
| 842 |
%%------------------------------------------------------------ |
| 843 |
\section{\protect\cmd{\tzpath}: Semicolon version} |
| 844 |
\label{s:tzpath} |
| 845 |
|
| 846 |
|
| 847 |
The macro \icmd{\tzpath} is the same as |\tzlinks[draw=none]|. In other words, |\tzpath| creates a path connecting an arbitrary number of coordinates, but it does not stroke the path. Since |\tzpath| is a \iisw{semicolon version} macro, you need to enter a \xem{semicolon} `|;|' to indicate where the coordinate iteration ends. |
| 848 |
|
| 849 |
You can visualize the path with |\tzpath[draw]|, which is the same as |\tzlinks|. |
| 850 |
|
| 851 |
|
| 852 |
\begin{tzdef} |
| 853 |
% syntax: minimal |
| 854 |
\tzpath (<coor>)(<coor>) ..repeated.. (<coor>) ; |
| 855 |
% syntax: full |
| 856 |
\tzpath {<path style>}[<opt>]<shift coor>"<path name>" |
| 857 |
(<coor>)[<code1>]{<text>}[<node opt>]<code2> |
| 858 |
..repeated.. ()[]{}[]<> ; <code.append> |
| 859 |
% remark: |
| 860 |
- <code1> must be link style, such as --, to, -|, etc. |
| 861 |
(possibly followed by other codes) |
| 862 |
- <code2> is especially for + and ++ |
| 863 |
(possibly with other codes) |
| 864 |
- repetition MUST be ended by ; (semicolon) |
| 865 |
% defaults: \tzpath |
| 866 |
{to}[]<>"" (<m>)[]{}[]<> ..repeated.. ()[]{}[]<> ; <> |
| 867 |
\end{tzdef} |
| 868 |
|
| 869 |
\remark |
| 870 |
\begin{itemize} |
| 871 |
\item The main purpose of |\tzpath| is to fill an enclosed area with colors or patterns. |
| 872 |
You can use |\tzpath[fill]| or |\tzpath[pattern=<...>]| to do it. |
| 873 |
\item Use \icmd{\settzpathlayer}, like |\settzpathlayre{behind}|, to change the layer of |\tzpath| (default: |main|). |
| 874 |
\end{itemize} |
| 875 |
|
| 876 |
\paragraph{Path construction operation} |
| 877 |
(If you are not an experienced user of \Tikz\, just skip this part.) |
| 878 |
|
| 879 |
%|\tzpath| is similar to |\tztos|, but it is more flexible in constructing paths. |
| 880 |
|\tzpath| allows you to choose how to construct a path using the |[<path style>]| option \xem{in-between} coordinates. \xem{Path extension operation} can be selected from `|--|', `|to|', `\verb+|-+', `\verb+-|+', etc. |
| 881 |
You can use \xem{the first brace option} |{<path style>}| to change all the |<path style>| in-between coordinates. |
| 882 |
|
| 883 |
|
| 884 |
\begin{tzcode}{.3} |
| 885 |
% \tzpath: path construction |
| 886 |
\begin{tikzpicture} |
| 887 |
\tzhelplines(4,3) |
| 888 |
\tzpath[draw](0,1)(1,2)[-|](3,1)(4,3); |
| 889 |
\tzpath[draw] |
| 890 |
(0,0)[to[bend right]] |
| 891 |
(1,1) |
| 892 |
(2,1)[to[out=-135,in=45]] |
| 893 |
(3,0); |
| 894 |
\end{tikzpicture} |
| 895 |
\end{tzcode} |
| 896 |
|
| 897 |
The default path style is `|to|' and can also be changed by \icmd{\settzpathstyle}, like, for example, |\settzpathstyle{--}|. |\settzpathstyle| is an alias of |\settzlinkstyle|. The effect remains valid until the end of |tikzpicture| environment unless changed again. |
| 898 |
|
| 899 |
\begin{tzcode}{.3} |
| 900 |
% \tzpath: \settzpathstyle |
| 901 |
\begin{tikzpicture} |
| 902 |
\tzhelplines(4,3) |
| 903 |
\settzpathstyle{to[bend right]} |
| 904 |
\tzpath[draw](0,1)(1,2)[-|](3,1)(4,3); |
| 905 |
\tzpath[draw] |
| 906 |
(0,0)[to[bend right]] |
| 907 |
(1,1) |
| 908 |
(2,1)[to[out=-135,in=45]] |
| 909 |
(3,0); |
| 910 |
\end{tikzpicture} |
| 911 |
\end{tzcode} |
| 912 |
|
| 913 |
\begin{tzcode}{.3} |
| 914 |
% \tzpath: \settzpathstyle |
| 915 |
\begin{tikzpicture} |
| 916 |
\tzhelplines(4,3) |
| 917 |
\settzpathstyle{to[bend right]} |
| 918 |
\tzlinks(0,1)(1,2)[-|](3,1)(4,3); |
| 919 |
\tzlinks |
| 920 |
(0,0)[to[bend right]] |
| 921 |
(1,1) |
| 922 |
(2,1)[to[out=-135,in=45]] |
| 923 |
(3,0); |
| 924 |
\end{tikzpicture} |
| 925 |
\end{tzcode} |
| 926 |
|
| 927 |
You can extend the path of |\tzpath| by writing \Tikz\ code in the last (after the semicolon) optional argument |<code.append>|. |
| 928 |
So |<--cycle>| closes the path with a straight line. |
| 929 |
|
| 930 |
\begin{tzcode}{.3} |
| 931 |
% \tzpath: <code.append> |
| 932 |
\begin{tikzpicture} |
| 933 |
\tzhelplines(4,3) |
| 934 |
\tzpath[draw](0,1)(1,2)[-|](3,1)(4,3); |
| 935 |
< to [bend right=60] (0,1) > |
| 936 |
\tzpath[fill] |
| 937 |
(0,0)[to[bend right]] |
| 938 |
(1,1) |
| 939 |
(2,1)[to[out=-135,in=45]] |
| 940 |
(3,0); <--cycle> |
| 941 |
\end{tikzpicture} |
| 942 |
\end{tzcode} |
| 943 |
|
| 944 |
\section{\protect\cmd{\tzpath*}: Semicolon version} |
| 945 |
\label{s:tzpath*} |
| 946 |
|
| 947 |
The starred version \icmd{\tzpath*} is the (almost) same as |\tzlinks*[draw=none]|. It fills the interior of |\tzpath| with |fill=black!50| with |fill opacity=.3| and |text opacity=1|, by default. |
| 948 |
The only difference between |\tzpath*| and |\tzlinks*[draw=none]| is that the layer of |\tzpath*| can be changed by |\settzpathlayer|, like |\settzpathlayer{behind}|. |
| 949 |
|
| 950 |
|\tzpath*| works like |\tzpath[fill=black!50,fill opacity=.3,text opacity=1]|. |
| 951 |
You can change the defaults by \icmd{\settzfillcolor} and \icmd{\settzfillopacity}. |
| 952 |
|
| 953 |
\begin{tzdef} |
| 954 |
% syntax: minimal |
| 955 |
\tzpath*(<coor>)(<coor>) ..repeated.. (<coor>) ; {<fill opacity>} |
| 956 |
% syntax: full |
| 957 |
\tzpath*{<path style>}[<opt>]<shift coor>"<path name>" |
| 958 |
(<coor>)[<code1>]{<text>}[<node opt>]<code2> |
| 959 |
..repeated.. ()[]{}[]<> ; {<fill opacity>} <code.append> |
| 960 |
% remark: |
| 961 |
- <code1> must be link style, such as --, to, -|, etc. |
| 962 |
(possibly followed by other codes) |
| 963 |
- <code2> is especially for + and ++ |
| 964 |
(possibly with other codes) |
| 965 |
- repetition MUST be ended by ; (semicolon) |
| 966 |
% defaults: \tzpath* |
| 967 |
*{to}[fill=black!50,fill opacity=.3,text opacity=1]<>"" |
| 968 |
(<m>)[]{}[]<> ..repeated.. ()[]{}[]<> ; {.3}<> |
| 969 |
\end{tzdef} |
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
\paragraph{Filling the interior} |
| 974 |
|
| 975 |
You can optionally change the opacity of fill color using the \Tikz\ option |fill opacity|. |
| 976 |
|
| 977 |
\begin{tzcode}{.3} |
| 978 |
% \tzpath: fill, fill opacity |
| 979 |
\begin{tikzpicture} |
| 980 |
\tzhelplines(4,3) |
| 981 |
\tzline[red,very thick](0,3)(4,0) |
| 982 |
\tzpath[fill](0,0)(3,1)(2,3)(0,2); % default opacity=1 |
| 983 |
\tzpath[fill,green,fill opacity=.5] |
| 984 |
<1,-1>(0,0)(3,1)(2,3)(0,2); |
| 985 |
\end{tikzpicture} |
| 986 |
\end{tzcode} |
| 987 |
|
| 988 |
You can also change the fill opacity by specifying the \xem{last} curly brace optional argument |{<fill opacity>}|, \xem{after the semicolon}. |
| 989 |
|
| 990 |
\begin{tzcode}{.3} |
| 991 |
% \tzpath* |
| 992 |
\begin{tikzpicture} |
| 993 |
\tzhelplines(4,3) |
| 994 |
\tzline[red,very thick](0,3)(4,0) |
| 995 |
\tzpath*(0,0)(3,1)(2,3)(0,2); |
| 996 |
\tzpath*[green] |
| 997 |
<1,-1>(0,0)(3,1)(2,3)(0,2); {.5} %% |
| 998 |
\end{tikzpicture} |
| 999 |
\end{tzcode} |
| 1000 |
|
| 1001 |
You can also use the macros |\settzfillcolor| and |\settzfillopacity| to change the defaults. |
| 1002 |
The effect remains valid until the end of the |tikzpicture| environment, unless changed again. |
| 1003 |
|
| 1004 |
\begin{tzcode}{.3} |
| 1005 |
% \tzpath*: \settzfillcolor |
| 1006 |
\begin{tikzpicture} |
| 1007 |
\tzhelplines(4,3) |
| 1008 |
\settzfillcolor{red} |
| 1009 |
\tzpath*[blue](0,1)(1,2)[-|](3,1)(4,3); |
| 1010 |
< to [bend right=60] (0,1) > |
| 1011 |
\tzpath* |
| 1012 |
(0,0)[to[bend right]] |
| 1013 |
(1,1) |
| 1014 |
(2,1)[to[out=-135,in=45]] |
| 1015 |
(3,0); <--cycle> |
| 1016 |
\end{tikzpicture} |
| 1017 |
\end{tzcode} |
| 1018 |
|
| 1019 |
|
| 1020 |
%%------------------------------------------------------------ |
| 1021 |
\section{\protect\cmd{\tzpath+} and \protect\cmd{\tzpath*+}: Relative coordinates: Semicolon versions} |
| 1022 |
\label{s:tzpath+} |
| 1023 |
|
| 1024 |
The \iisw{plus version} \icmd{\tzpath+} uses each coordinate (except for the first coordinate) relative (with |++|) to the previous coordinate. |
| 1025 |
|
| 1026 |
\xem{Everything else is the same as in} |\tzpath|. |
| 1027 |
|
| 1028 |
\icmd{\tzpath*+} is simply the plus version of |\tzpath*|. |
| 1029 |
|
| 1030 |
\begin{tzcode}{.3} |
| 1031 |
% \tzpath+ |
| 1032 |
\begin{tikzpicture} |
| 1033 |
\tzhelplines(4,3) |
| 1034 |
\tzline[red,very thick](0,3)(4,0) |
| 1035 |
\tzpath+[pattern=bricks,preaction={fill=brown}] |
| 1036 |
(0,0)(3,1)(-1,2)(-2,-1); |
| 1037 |
\tzpath+[pattern=north east lines,opacity=.5] |
| 1038 |
<1,-1>(0,0)(3,1)(-1,2)(-2,-1); |
| 1039 |
\end{tikzpicture} |
| 1040 |
\end{tzcode} |
| 1041 |
|
| 1042 |
You can change the layer (|main| by default) using |\settzpathlayer|. |
| 1043 |
|
| 1044 |
\begin{tzcode}{.3} |
| 1045 |
% \settzpathlayer |
| 1046 |
\begin{tikzpicture} |
| 1047 |
\tzhelplines(4,3) |
| 1048 |
\settzpathlayer{behind} %% layer |
| 1049 |
\tzline[red,very thick](0,3)(4,0) |
| 1050 |
\tzpath+[pattern=bricks,preaction={fill=brown}] |
| 1051 |
(0,0)(3,1)(-1,2)(-2,-1); |
| 1052 |
\tzpath+[pattern=north east lines,opacity=.5] |
| 1053 |
<1,-1>(0,0)(3,1)(-1,2)(-2,-1); |
| 1054 |
\end{tikzpicture} |
| 1055 |
\end{tzcode} |
| 1056 |
|
| 1057 |
\begin{tzcode}{.3} |
| 1058 |
% \tzpath*+ |
| 1059 |
\begin{tikzpicture} |
| 1060 |
\tzhelplines(4,3) |
| 1061 |
\tzline[red,very thick](0,3)(4,0) |
| 1062 |
\tzpath*+(0,0)(3,1)(-1,2)(-2,-1); |
| 1063 |
\tzpath*+[fill=green] |
| 1064 |
<1,-1>(0,0)(3,1)(-1,2)(-2,-1); {.5} %% |
| 1065 |
\end{tikzpicture} |
| 1066 |
\end{tzcode} |
| 1067 |
|
| 1068 |
|
| 1069 |
%%======================================= |
| 1070 |
%%================================== |
| 1071 |
\chapter{Curves} |
| 1072 |
\label{c:curves} |
| 1073 |
|
| 1074 |
There are many ways to draw curves. |
| 1075 |
|
| 1076 |
%%----------------------------------- |
| 1077 |
%%------------------------------------------------------------ |
| 1078 |
\section{B\'{e}zier curves} |
| 1079 |
\label{s:beziercurves} |
| 1080 |
|
| 1081 |
\subsection{\protect\cmd{\tzbezier}} |
| 1082 |
\label{ss:tzbezier} |
| 1083 |
|
| 1084 |
\icmd{\tzbezier} accepts \xem{three or four} coordinates to draw a B\'{e}zier curve from the first coordinate to the last coordinate, with \xem{one or two} control points. |
| 1085 |
|
| 1086 |
\begin{tzdef} |
| 1087 |
% syntax: minimal |
| 1088 |
\tzbezier(<start-coor>)(cntl-coor>)(<last-coor>) |
| 1089 |
\tzbezier(<start-coor>)(cntl-coor>)(<cntl-coor>)(<last-coor>) |
| 1090 |
% syntax: full |
| 1091 |
\tzbezier[<draw opt>]<shift coor>"<name path>" |
| 1092 |
(<start-coor>)(cntl-coor>)(<cntl-coor>)(<last-coor>) |
| 1093 |
{<text>}[<node opt>]<code.append> |
| 1094 |
% defaults |
| 1095 |
[]<>""(<m>)(<m>)()(<m>){}[]<> |
| 1096 |
\end{tzdef} |
| 1097 |
|
| 1098 |
\paragraph{Control points} |
| 1099 |
|
| 1100 |
You can specify one or two control points, |(<cntl-coor>)|. |
| 1101 |
|
| 1102 |
\begin{tztikz} |
| 1103 |
% three coordinates: one control point |
| 1104 |
\tzbezier(0,1)(1,0)(4,3) % works like: |
| 1105 |
\draw (0,0) ..controls (1,0).. (4,3); |
| 1106 |
\end{tztikz} |
| 1107 |
|
| 1108 |
\begin{tztikz} |
| 1109 |
% four coordinates: two control points |
| 1110 |
\tzbezier(0,1)(1,0)(2,4)(4,3) % works like: |
| 1111 |
\draw (0,0) ..controls (1,0) and (2,4).. (4,3); |
| 1112 |
\end{tztikz} |
| 1113 |
|
| 1114 |
\begin{tzcode}{.3} |
| 1115 |
% \tzbezier |
| 1116 |
\begin{tikzpicture} |
| 1117 |
\tzhelplines(4,4) |
| 1118 |
\tzbezier[red](0,3)(1,2)(2,4)(4,3) |
| 1119 |
\tzbezier[blue](0,2)(1,.5)(4,0) |
| 1120 |
\end{tikzpicture} |
| 1121 |
\end{tzcode} |
| 1122 |
|
| 1123 |
The style \ixxw{tzshowcontrols} displays the control points by drawing dotted lines, by default. |
| 1124 |
You can also change the dotted line style, like |tzshowcontrols={dashed,green}|. |
| 1125 |
|
| 1126 |
|
| 1127 |
\begin{tzcode}{.3} |
| 1128 |
% \tzbezier: tzshowcontrols |
| 1129 |
\begin{tikzpicture} |
| 1130 |
\tzhelplines(4,4) |
| 1131 |
\tzbezier[blue,tzshowcontrols](0,2)(1,.5)(4,0) |
| 1132 |
\tzdots*[blue](0,2)(1,.5)(4,0); |
| 1133 |
\tzbezier[red,tzshowcontrols={green,dashed}] |
| 1134 |
(0,3)(1,2)(2,4)(4,3) |
| 1135 |
\tzdots*[red](0,3)(1,2)(2,4)(4,3); |
| 1136 |
\end{tikzpicture} |
| 1137 |
\end{tzcode} |
| 1138 |
|
| 1139 |
\paragraph{Adding text} |
| 1140 |
You can add text next to the curve or at the last coordinate |
| 1141 |
by specifying the options |{<text>}| and |[<node opt>]| \xem{immediately after the last coordinate}. |
| 1142 |
|
| 1143 |
|
| 1144 |
\begin{tzcode}{.3} |
| 1145 |
% \tzbezier: adding text |
| 1146 |
\begin{tikzpicture} |
| 1147 |
\tzhelplines(4,4) |
| 1148 |
\tzbezier[blue](0,2)(1,.5)(4,0){curve}[draw,black,r] |
| 1149 |
\tzbezier[red](0,3)(1,2)(2,4)(4,3){bezier}[near end,a] |
| 1150 |
\end{tikzpicture} |
| 1151 |
\end{tzcode} |
| 1152 |
|
| 1153 |
\paragraph{Shift} |
| 1154 |
You can move the curve of |\tzbezier| by specifying the option |<shift coor>| before the first coordinate or immediately before the option |"<path name>"|, if it exists. |
| 1155 |
The \xem{empty} shift option |<>| is \xem{not allowed}. |
| 1156 |
|
| 1157 |
\begin{tzcode}{.3} |
| 1158 |
% \tzbezier: shift |
| 1159 |
\begin{tikzpicture} |
| 1160 |
\tzhelplines(4,4) |
| 1161 |
\tzbezier[blue] |
| 1162 |
(0,2)(1,.5)(4,0){curve}[draw,black,r] |
| 1163 |
\tzbezier[blue,dashed] |
| 1164 |
<1,1>(0,2)(1,.5)(4,0){curve}[r] |
| 1165 |
\tzbezier[red] |
| 1166 |
(0,3)(1,2)(2,4)(4,3){bezier}[near end,a] |
| 1167 |
\tzbezier[red,dashed] |
| 1168 |
<0,-1>(0,3)(1,2)(2,4)(4,3){bezier}[blue,near end,a] |
| 1169 |
\end{tikzpicture} |
| 1170 |
\end{tzcode} |
| 1171 |
|
| 1172 |
\paragraph{Naming paths: intersections} |
| 1173 |
You can name the path of |\tzbezier| by specifying the option |"<path name>"| \xem{immediately before} the first coordinate. |
| 1174 |
|
| 1175 |
\begin{tzcode}{.3} |
| 1176 |
% \tzbezier: name path, intersection |
| 1177 |
\begin{tikzpicture} |
| 1178 |
\tzhelplines(4,4) |
| 1179 |
\tzbezier[blue,dashed,thick]<1,1>"curve" |
| 1180 |
(0,2)(1,.5)(4,0){curve}[r] |
| 1181 |
\tzbezier[red,dashed,thick]<0,-1>"bezier" |
| 1182 |
(0,3)(1,2)(2,4)(4,3){bezier}[blue,near end,a] |
| 1183 |
% intersection point |
| 1184 |
\tzXpoint*{curve}{bezier}(X){X}[-90] |
| 1185 |
\end{tikzpicture} |
| 1186 |
\end{tzcode} |
| 1187 |
|
| 1188 |
\paragraph{Extending paths} |
| 1189 |
You can extend the path of |\tzbezier| from the last coordinate, by writing \Tikz\ code |
| 1190 |
in the last optional argument |<code.append>|. |
| 1191 |
|
| 1192 |
\begin{tzcode}{.3} |
| 1193 |
% \tzbezier: extending path |
| 1194 |
\begin{tikzpicture} |
| 1195 |
\tzhelplines(4,4) |
| 1196 |
\tzbezier[red](0,3)(1,2)(2,4)(4,3){bezier}[near end,a] |
| 1197 |
< to [bend right] ++(-1,-1) node [below] {A} > |
| 1198 |
\tzbezier[blue,->](0,2)(1,.5)(4,0) |
| 1199 |
< |- ++(-2,1) node [below] {B} > |
| 1200 |
\end{tikzpicture} |
| 1201 |
\end{tzcode} |
| 1202 |
|
| 1203 |
You can also use \icmd{\tzbezierAtBegin} and \icmd{\tzbezierAtEnd} to extend the path of |\tzbezier| at the beginning and at the end, respectively. |
| 1204 |
Specifying the option |<code.append>| extends the path after |\tzbezierAtEnd|. |
| 1205 |
|
| 1206 |
\begin{tzcode}{.3} |
| 1207 |
% \tzbezier: extending path |
| 1208 |
\begin{tikzpicture} |
| 1209 |
\tzhelplines(4,4) |
| 1210 |
\tzbezierAtEnd |
| 1211 |
{ to [bend right] ++(-1,-1) node [below] {A} } |
| 1212 |
\tzbezier[red](0,3)(1,2)(2,4)(4,3){bezier}[near end,a] |
| 1213 |
\tzbezierAtBegin{ (0,0) to [out=45,in=-30] } |
| 1214 |
\tzbezierAtEnd{ |- ++(-2,1) } |
| 1215 |
\tzbezier[blue,->](0,2)(1,.5)(4,0){B}[b] |
| 1216 |
< arc (0:90:1) node [a] {End!} > |
| 1217 |
\end{tikzpicture} |
| 1218 |
\end{tzcode} |
| 1219 |
|
| 1220 |
|
| 1221 |
\subsection{\protect\cmd{\tzbezier+}: Relative coordinates} |
| 1222 |
\label{ss:tzbezier+} |
| 1223 |
|
| 1224 |
For the \iisw{plus version} \icmd{\tzbezier+}, the last coordinate is \xem{relative} to the first coordinate. |
| 1225 |
And the first control point is \xem{relative} to the first coordinate. |
| 1226 |
|
| 1227 |
\begin{tztikz} |
| 1228 |
% three coordinates |
| 1229 |
\tzbezier+(0,1)(1,-1)(4,3) % works like: |
| 1230 |
\draw (0,1) ..controls +(1,-1).. ($(0,1)+(4,3)$); |
| 1231 |
\end{tztikz} |
| 1232 |
|
| 1233 |
In \Tikz, the second control point is \xem{relative} to the last coordinate. |
| 1234 |
|
| 1235 |
Therefore, for |\tzbezier+(A)(B)(C)(D)|, |(B)| and |(D)| are \xem{relative} to |(A)|, and the second control point |(C)| is \xem{relative} to the last coordinate |(D)|. |
| 1236 |
|
| 1237 |
\begin{tztikz} |
| 1238 |
% four coordinates |
| 1239 |
\tzbezier+(0,1)(1,-1)(-2,1)(4,3) % works like: |
| 1240 |
\draw (0,1) ..controls +(1,-1) and +(-2,1).. ($(0,1)+(4,3)$); |
| 1241 |
\end{tztikz} |
| 1242 |
|
| 1243 |
\begin{tzcode}{.3} |
| 1244 |
% \tzbezier+ |
| 1245 |
\begin{tikzpicture} |
| 1246 |
\tzhelplines(4,4) |
| 1247 |
\tzbezier+(0,3)(1,-1)(-2,1)(4,0){bezier}[near end,a] |
| 1248 |
< to [bend right] ++(-1,-1) node [below] {A} > |
| 1249 |
\tzbezier+[blue,->](0,2)(1,-1.5)(4,-2) |
| 1250 |
< |- ++(-2,1) node [above] {B} > |
| 1251 |
\end{tikzpicture} |
| 1252 |
\end{tzcode} |
| 1253 |
|
| 1254 |
|
| 1255 |
\begin{tzcode}{.3} |
| 1256 |
% \tzbezierAtBegin, \tzbezierAtEnd |
| 1257 |
\begin{tikzpicture} |
| 1258 |
\tzhelplines(4,4) |
| 1259 |
\tzbezierAtEnd |
| 1260 |
{ to [bend right] ++(-1,-1) node [below] {A} } |
| 1261 |
\tzbezier+(0,3)(1,-1)(-2,1)(4,0){bezier}[near end,a] |
| 1262 |
\tzbezierAtBegin{ (1,0) to [out=150,in=30] } |
| 1263 |
\tzbezierAtEnd{ |- ++(-2,1) node [a] {here!} } |
| 1264 |
\tzbezier+[blue,->](0,2)(1,-1.5)(4,-2){B}[b] |
| 1265 |
\end{tikzpicture} |
| 1266 |
\end{tzcode} |
| 1267 |
|
| 1268 |
|
| 1269 |
%%----------------------------------- |
| 1270 |
%%------------------------------------------------------------ |
| 1271 |
\section{Parabolas} |
| 1272 |
\label{s:parabolas} |
| 1273 |
|
| 1274 |
|
| 1275 |
\subsection{\protect\cmd{\tzparabola}} |
| 1276 |
\label{ss:tzparabola} |
| 1277 |
|
| 1278 |
\icmd{\tzparabola} accepts \xem{two or three} coordinates to draw a parabola from the first coordinate to the last coordinate. |
| 1279 |
In the case of three coordinates, the parabola bends at the second coordinate. |
| 1280 |
|
| 1281 |
\begin{tztikz} |
| 1282 |
% two coordinates |
| 1283 |
\tzparabola(0,0)(3,2) % works like: |
| 1284 |
\draw (0,0) parabola (3,2); |
| 1285 |
\end{tztikz} |
| 1286 |
|
| 1287 |
\begin{tztikz} |
| 1288 |
% three coordinates |
| 1289 |
\tzparabola(0,0)(1,1)(3,2) % works like: |
| 1290 |
\draw (0,0) parabola bend (1,1) (3,2); |
| 1291 |
\end{tztikz} |
| 1292 |
|
| 1293 |
|
| 1294 |
\begin{tzdef} |
| 1295 |
% syntax: minimal |
| 1296 |
\tzparabola(<coor>)(<coor>) |
| 1297 |
\tzparabola(<coor>)(<coor>)(<coor>) |
| 1298 |
% syntax: full |
| 1299 |
\tzparabola[<opt1>]<shift coor>"<path name>" |
| 1300 |
(<coor>)(<coor>)(<coor>){<text>}[<node opt>]<code.append> |
| 1301 |
% default |
| 1302 |
[]<>""(<m>)()(<m>){}[]<> |
| 1303 |
\end{tzdef} |
| 1304 |
|
| 1305 |
\paragraph{Parabolas} |
| 1306 |
|\tzplot| draws the graph of a quadratic function $f(x)=ax^2+bx+c$ for appropriate values of $a$, $b$, and $c$. |
| 1307 |
|
| 1308 |
\begin{tzcode}{.3} |
| 1309 |
% \tzparabola: two coordinates |
| 1310 |
\begin{tikzpicture} |
| 1311 |
\tzhelplines(4,3) |
| 1312 |
\tzparabola[thick](0,0)(2,2) |
| 1313 |
\tzparabola[bend at end,dashed](0,0)(2,2) |
| 1314 |
\tzparabola[red,thick,bend pos=.5](2,0)(4,3) |
| 1315 |
\tzparabola[blue,parabola height=-2cm](2,3)(4,2) |
| 1316 |
\end{tikzpicture} |
| 1317 |
\end{tzcode} |
| 1318 |
|
| 1319 |
\begin{tzcode}{.3} |
| 1320 |
% \tzparabola: three coordinates |
| 1321 |
\begin{tikzpicture} |
| 1322 |
\tzhelplines(4,3) |
| 1323 |
\tzparabola[thick](0,2)(1,0)(2,2) |
| 1324 |
\tzparabola[blue](0,3)(2,1)(4,2) |
| 1325 |
\tzparabola[red,thick](2,0)(3,2)(4,3) |
| 1326 |
\end{tikzpicture} |
| 1327 |
\end{tzcode} |
| 1328 |
|
| 1329 |
\paragraph{Adding text} |
| 1330 |
You can add text at or around the \xem{last coordinate} by specifying the options |{<text>}| and |[<node opt>]| \xem{immediately after the last coordinate}. |
| 1331 |
|
| 1332 |
\begin{tzcode}{.3} |
| 1333 |
% \tzparabola: adding text |
| 1334 |
\begin{tikzpicture} |
| 1335 |
\tzhelplines(4,3) |
| 1336 |
\tzparabola[thick](0,0)(2,2){parabola}[blue,draw,a] |
| 1337 |
\tzparabola[blue](0,3)(2,1)(4,2){AC}[r] |
| 1338 |
\tzparabola[red,thick,bend pos=.5](2,0)(4,3){C}[ar] |
| 1339 |
\end{tikzpicture} |
| 1340 |
\end{tzcode} |
| 1341 |
|
| 1342 |
\paragraph{Shift} |
| 1343 |
You can move the parabola by specifying the option |<shift coor>| before the first coordinate or immediately before the option |"<path name>"|, if it exist. |
| 1344 |
The \xem{empty} shift option |<>| is \xem{not allowed}. |
| 1345 |
|
| 1346 |
\begin{tzcode}{.3} |
| 1347 |
% \tzparabola: shift |
| 1348 |
\begin{tikzpicture} |
| 1349 |
\tzhelplines(4,3) |
| 1350 |
\tzparabola[blue] (0,3)(2,1)(4,2){AC}[r] |
| 1351 |
\tzparabola[dashed]<0,-.5>(0,3)(2,1)(4,2){AC}[r] |
| 1352 |
\tzparabola[dotted]<0,-1> (0,3)(2,1)(4,2){AC}[r] |
| 1353 |
\end{tikzpicture} |
| 1354 |
\end{tzcode} |
| 1355 |
|
| 1356 |
\paragraph{Naming paths: intersections} |
| 1357 |
You can name the path of |\tzparabola| by specifying the option |"<path name>"| \xem{immediately before} the first coordinate. |
| 1358 |
|
| 1359 |
\begin{tzcode}{.3} |
| 1360 |
% \tzparabola: name path, intersection |
| 1361 |
\begin{tikzpicture} |
| 1362 |
\tzhelplines(4,3) |
| 1363 |
\tzparabola[blue]"AC"(0,3)(2,1)(4,2){AC}[r] |
| 1364 |
\tzparabola"BB"(1,0)(2,2)(3,0) |
| 1365 |
% intersection points |
| 1366 |
\tzXpoint*{AC}{BB}(X) |
| 1367 |
\tzdot(X-2)(3pt) |
| 1368 |
\end{tikzpicture} |
| 1369 |
\end{tzcode} |
| 1370 |
|
| 1371 |
\paragraph{Extending paths} |
| 1372 |
You can extend the path of |\tzparabola| from the last coordinate by writing \Tikz\ code in the last optional argument |<code.append>|. |
| 1373 |
|
| 1374 |
\begin{tzcode}{.3} |
| 1375 |
% \tzparabola: extending path |
| 1376 |
\begin{tikzpicture} |
| 1377 |
\tzhelplines(4,3) |
| 1378 |
\tzparabola[blue,->]"AC"(0,3)(2,1)(4,2) |
| 1379 |
< -- ++ (-1,1) > |
| 1380 |
\tzparabola"BB"(1,0)(2,2)(3,0) |
| 1381 |
< -| ++ (1,1) node [right] {K!} > |
| 1382 |
\end{tikzpicture} |
| 1383 |
\end{tzcode} |
| 1384 |
|
| 1385 |
You can also use the macros \icmd{\tzparabolaAtBegin} and \icmd{\tzparabolaAtEnd} to extend the path of |\tzparabola| at the beginning and at the and, respectively. |
| 1386 |
Specifying the option |<code.append>| extends the path after |\tzparabolaAtEnd|. |
| 1387 |
|
| 1388 |
\begin{tzcode}{.3} |
| 1389 |
% \tzparabola: extending path |
| 1390 |
\begin{tikzpicture} |
| 1391 |
\tzhelplines(4,3) |
| 1392 |
\tzparabolaAtEnd{ -- ++ (-1,1) } |
| 1393 |
\tzparabola[blue,->]"AC"(0,3)(2,1)(4,2) |
| 1394 |
\tzparabolaAtBegin{ (0,1) to [bend right ] } |
| 1395 |
\tzparabolaAtEnd{ -| ++ (1,1) node [right] {End!} } |
| 1396 |
\tzparabola"BB"(1,0)(2,2)(3,0){K!}[bl] |
| 1397 |
< arc (-90:0:1) node [a] {here!} > |
| 1398 |
\end{tikzpicture} |
| 1399 |
\end{tzcode} |
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
\subsection{\protect\cmd{\tzparabola+}: Relative coordinates} |
| 1404 |
\label{ss:tzparabola+} |
| 1405 |
|
| 1406 |
The \iisw{plus version} \icmd{\tzparabola+} uses the second and the third coordinates \xem{relative} to the first coordinate. |
| 1407 |
|
| 1408 |
\xem{Everything else is the same as in} |\tzparabola|. |
| 1409 |
|
| 1410 |
\begin{tztikz} |
| 1411 |
% two coordinates |
| 1412 |
\tzparabola+(0,1)(1,2) % works like: |
| 1413 |
\draw (0,1) parabola ($(0,1)+(1,2)$); |
| 1414 |
\end{tztikz} |
| 1415 |
|
| 1416 |
|
| 1417 |
\begin{tztikz} |
| 1418 |
% three coordinates |
| 1419 |
\tzparabola+(0,1)(1,1)(3,-1) % works like: |
| 1420 |
\draw (0,1) parabola bend +(1,1) ($(0,1)+(3,-1)$); |
| 1421 |
\end{tztikz} |
| 1422 |
|
| 1423 |
\begin{tzcode}{.3} |
| 1424 |
% \tzparabola+ |
| 1425 |
\begin{tikzpicture} |
| 1426 |
\tzhelplines(4,3) |
| 1427 |
\tzparabola+[thick](0,0)(2,2){parabola}[blue,draw,a] |
| 1428 |
\tzparabola+[blue](0,3)(2,-2)(4,-1){AC}[r] |
| 1429 |
\tzparabola+[red,thick,bend pos=.5](2,0)(2,3){C}[ar] |
| 1430 |
\end{tikzpicture} |
| 1431 |
\end{tzcode} |
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
%%------------------------------------------------------------ |
| 1436 |
\section{Edges} |
| 1437 |
\label{s:edge} |
| 1438 |
|
| 1439 |
%%------------------------------------------------------------ |
| 1440 |
\subsection{\protect\cmd{\tzedge(+)}} |
| 1441 |
\label{ss:tzedge} |
| 1442 |
|
| 1443 |
The macro \icmd{\tzedge} connects two coordinates with a straight or curved line, using the \Tikz\ |edge| operation. |
| 1444 |
|
| 1445 |
|
| 1446 |
\begin{tzdef} |
| 1447 |
% syntax |
| 1448 |
\tzedge[<opt>]<shift coor> |
| 1449 |
(<coor>){<text>}[<opt>](<coor>){<text>}[<opt>]<code.append> |
| 1450 |
% defaults |
| 1451 |
[]<>(<m>){}[](<m>){}[]<> |
| 1452 |
\end{tzdef} |
| 1453 |
|
| 1454 |
\remark In \Tikz, the |edge| operation works like the |to| operation, but it is independently drawn after a main path is drawn and does not form a main path. So the option |"<path name>"| (for finding intersections) is not provided in |\tzedge|. |
| 1455 |
|
| 1456 |
|
| 1457 |
\begin{tztikz} |
| 1458 |
\tzedge(1,1)(3,2) % works like: |
| 1459 |
\draw (1,1) edge (3,2); |
| 1460 |
\end{tztikz} |
| 1461 |
|
| 1462 |
\begin{tztikz} |
| 1463 |
\tzedge[->,bend right](1,1){A}[near start](3,2) % works like: |
| 1464 |
\draw (1,1) edge [->,bend right] node [near start] {A} (3,2); |
| 1465 |
\end{tztikz} |
| 1466 |
|
| 1467 |
\begin{tzcode}{.3} |
| 1468 |
% \tzedge |
| 1469 |
\begin{tikzpicture} |
| 1470 |
\tzhelplines(4,3) |
| 1471 |
\tzedge[->](0,1)(2,3) |
| 1472 |
\tzedge[out=0,dashed] |
| 1473 |
(0,0){edge}[near start,sloped,a](4,2) |
| 1474 |
\tzedge[in=90,blue](2,0)(4,1){C}[r] |
| 1475 |
\end{tikzpicture} |
| 1476 |
\end{tzcode} |
| 1477 |
|
| 1478 |
The \xem{plus version} \icmd{\tzedge+} use the second coordinate \xem{relative} to the first coordinate. |
| 1479 |
|
| 1480 |
\begin{tztikz} |
| 1481 |
\tzedge+(1,1)(3,2) % works like: |
| 1482 |
\draw (1,1) edge ++(3,2); |
| 1483 |
\end{tztikz} |
| 1484 |
|
| 1485 |
\begin{tztikz} |
| 1486 |
\tzedge+[->,bend right](1,1){A}[near start](3,2){B}[right] % works like: |
| 1487 |
\draw (1,1) edge [->,bend right] node [near start] {A} ++(3,2) |
| 1488 |
++(3,2) node [right] {B}; |
| 1489 |
\end{tztikz} |
| 1490 |
|
| 1491 |
\begin{tzcode}{.3} |
| 1492 |
% \tzedge+: shift |
| 1493 |
\begin{tikzpicture} |
| 1494 |
\tzhelplines(4,3) |
| 1495 |
\tzedge+[->](0,1)(2,2) |
| 1496 |
\tzedge+[out=0,dashed] |
| 1497 |
(0,0){edge}[near start,sloped,a](4,2) |
| 1498 |
\tzedge+[in=90,blue]<-.5,.5>(2,0)(2,1){shifted}[b,draw] |
| 1499 |
\end{tikzpicture} |
| 1500 |
\end{tzcode} |
| 1501 |
|
| 1502 |
|
| 1503 |
\remark |edge| in the option |<code.append>| works with the second coordinate, but it works with the last node if the second option |{<text>}| is not empty. |
| 1504 |
(In \Tikz, if |edge| is preceded by |node|, the node is its start point.) |
| 1505 |
|
| 1506 |
\begin{tzcode}{.3} |
| 1507 |
% <code.append> |
| 1508 |
\begin{tikzpicture} |
| 1509 |
\tzhelplines(4,3) |
| 1510 |
\tzedge[->](0,1)(2,3)<edge[bend left,red] ++(1,-2)> |
| 1511 |
\tzedge[out=0,dashed] |
| 1512 |
(0,0){edge}[near start,sloped,a] |
| 1513 |
(4,2){A}[draw] |
| 1514 |
<edge[bend left,thick] ++ (-1,-2)> |
| 1515 |
\end{tikzpicture} |
| 1516 |
\end{tzcode} |
| 1517 |
|
| 1518 |
%%------------------------------------------------------------ |
| 1519 |
\subsection{\protect\cmd{\tzedges(+)}: Semicolon versions} |
| 1520 |
\label{ss:tzedges} |
| 1521 |
|
| 1522 |
The macro \icmd{\tzedges} accepts any number of coordinates to draw edges from the first coordinate to each of the next using the \Tikz\ |edge| operation. That is, the first coordinate is the unique start coordinate, and all others are target coordinates. |
| 1523 |
|\tzedges| is a semicolon version, so you need to type |;| to indicate when the coordinate iteration ends. |
| 1524 |
|
| 1525 |
|
| 1526 |
\begin{tzdef} |
| 1527 |
% syntax: minimum |
| 1528 |
\tzedges(<coor>)(<coor>)..repeated..(<coor>); |
| 1529 |
% syntax: full |
| 1530 |
\tzedges[<opt>]<shift coor> |
| 1531 |
(<coor>)[<edge opt>]{<text>}[<opt>]..repeated..()[]{}[] ; <code.append> |
| 1532 |
% defaults |
| 1533 |
[](<m>)[]{}[]..repeated..()[]{}[]; |
| 1534 |
\end{tzdef} |
| 1535 |
|
| 1536 |
\remark In \Tikz, the |edge| operation works like |to| operation, but it is added after main path is formed, like |node| does. |
| 1537 |
\begin{itemize}\firmlist |
| 1538 |
\item Each |edge| is drawn independently from a main path as well as any other |edge|'s. (See \Tikz\ manual for more details.) |
| 1539 |
\item The |edge| operation of \Tikz\ does not change change anything about a main path, so the current point is not changed by |\tzedges|. This means that the last node (with |{<text>}| and |[<node opt>]|) works with the first (namely, start) coordinate. |
| 1540 |
\end{itemize} |
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
\begin{tzcode}{.3} |
| 1547 |
% \tzedges |
| 1548 |
\begin{tikzpicture} |
| 1549 |
\tzhelplines(4,3) |
| 1550 |
\tzedges(0,1){A} (1,2) |
| 1551 |
[blue,thick]{edge}[b](3,1) |
| 1552 |
(4,3); |
| 1553 |
\end{tikzpicture} |
| 1554 |
\end{tzcode} |
| 1555 |
|
| 1556 |
\begin{tztikz} |
| 1557 |
\tzedges(0,1){A}(1,2)[blue,thick]{edge}[a](3,1)(4,3); % works like |
| 1558 |
\draw (0,1) edge node {A} (1,2) |
| 1559 |
edge [blue,thick] node [above] {edge} (3,1) |
| 1560 |
edge (4,3) ; |
| 1561 |
\end{tikzpicture} |
| 1562 |
\end{tztikz} |
| 1563 |
|
| 1564 |
\begin{tzcode}{.3} |
| 1565 |
% \tzedges: shift |
| 1566 |
\begin{tikzpicture} |
| 1567 |
\tzhelplines(4,3) |
| 1568 |
\tzedges[bend right]<1,-1> % shift |
| 1569 |
(0,1)[->,thick,blue]{A} |
| 1570 |
(1,2)[dotted]{Beta}[b] |
| 1571 |
(3,1)[dashed]{Cate}[near end,sloped,a] |
| 1572 |
(4,3); |
| 1573 |
\end{tikzpicture} |
| 1574 |
\end{tzcode} |
| 1575 |
|
| 1576 |
|
| 1577 |
The \xem{plus version} \icmd{\tzedges+} uses the second and next coordinates \xem{relative} to the first coordinate. |
| 1578 |
|
| 1579 |
\begin{tztikz} |
| 1580 |
\tzedges+(0,1)(2,1)(3,0)(4,2); % works like |
| 1581 |
\draw (0,1) edge ++ (2,1) |
| 1582 |
edge ++ (3,0) |
| 1583 |
edge ++ (4,2); |
| 1584 |
\end{tztikz} |
| 1585 |
|
| 1586 |
\begin{tzcode}{.3} |
| 1587 |
% \tzedges+ |
| 1588 |
\begin{tikzpicture} |
| 1589 |
\tzhelplines(4,3) |
| 1590 |
\tzedges+[bend right](0,1)[bend right=0]{A} |
| 1591 |
(1,1)[dotted]{Beta}[b] |
| 1592 |
(3,0)[dashed]{Cate}[near end,sloped,a] |
| 1593 |
(4,2); |
| 1594 |
\end{tikzpicture} |
| 1595 |
\end{tzcode} |
| 1596 |
|
| 1597 |
|
| 1598 |
\remark The option |<code.append>| works with the first coordinate because |edge| and |node| do not change the current point. |
| 1599 |
|
| 1600 |
|
| 1601 |
\begin{tzcode}{.3} |
| 1602 |
% <code.append> |
| 1603 |
\begin{tikzpicture} |
| 1604 |
\tzhelplines(4,3) |
| 1605 |
\tzedges+(0,1)[bend right=0,->]{A}[fill=white] |
| 1606 |
(1,1)[bend right,dotted]{Beta}[midway] |
| 1607 |
(3,0)[bend right,dashed]{Cate}[near end] |
| 1608 |
(4,2); |
| 1609 |
< edge [bend left,thick,blue] (1,3) > |
| 1610 |
\end{tikzpicture} |
| 1611 |
\end{tzcode} |
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
%%------------------------------------------------------------ |
| 1616 |
\section{More curves} |
| 1617 |
|
| 1618 |
\subsection{\protect\cmd{\tzplotcurve}, \protect\cmd{\tzplot}} |
| 1619 |
|
| 1620 |
You can draw curves with |\tzplotcurve| and |\tzplot|. |
| 1621 |
|
| 1622 |
\begin{tzcode}{.3} |
| 1623 |
% \tzplotcurve(*) |
| 1624 |
\begin{tikzpicture} |
| 1625 |
\tzhelplines(4,3) |
| 1626 |
\tzplotcurve*[red,text=blue] |
| 1627 |
(0,0)(1,2){B}(2,2)(3,3)(4,1){E}[0]; |
| 1628 |
\tzplotcurve(1,.5)(2,3)(3,2)(2,1)(3,1); |
| 1629 |
\end{tikzpicture} |
| 1630 |
\end{tzcode} |
| 1631 |
|
| 1632 |
|
| 1633 |
See Section \ref{s:tzplotcurve} on page \pageref{s:tzplotcurve}, for more details on |\tzplotcurve|. |
| 1634 |
|
| 1635 |
See Section \ref{s:tzplot} on page \pageref{s:tzplot}, for more details on |\tzplot|. |
| 1636 |
|
| 1637 |
|
| 1638 |
\subsection{\protect\cmd{\tzto}, \protect\cmd{\tztos}} |
| 1639 |
\label{ss:curves:tzto} |
| 1640 |
|
| 1641 |
You can draw curves with |\tzto| and |\tztos|. |
| 1642 |
|\tztos| are quite useful to draw various curves. |
| 1643 |
|
| 1644 |
\begin{tzcode}{.3} |
| 1645 |
% \tztos |
| 1646 |
\begin{tikzpicture} |
| 1647 |
\tzhelplines(4,3) |
| 1648 |
\tzcoors*(0,0)(A)(1,2)(B){B}[b](3,3)(C)(4,2)(D); |
| 1649 |
\tztos(A)[out=80,in=180] |
| 1650 |
(B)[out=0,in=180] |
| 1651 |
(C)[out=0,in=180] |
| 1652 |
(D){End!}[r]; |
| 1653 |
\end{tikzpicture} |
| 1654 |
\end{tzcode} |
| 1655 |
|
| 1656 |
See Section \ref{s:tzto} on page \pageref{s:tzto}, for more details on |\tzto|. |
| 1657 |
|
| 1658 |
See Section \ref{s:tztos} on page \pageref{s:tztos}, for more details on |\tztos|. |
| 1659 |
|
| 1660 |
\subsection{\protect\cmd{\tzlink}, \protect\cmd{\tzlinks}} |
| 1661 |
\label{ss:curves:tzlink} |
| 1662 |
|
| 1663 |
You can also draw curves with |\tzlink| and |\tzlinks|. |
| 1664 |
|
| 1665 |
\begin{tzcode}{.3} |
| 1666 |
% \tztos |
| 1667 |
\begin{tikzpicture} |
| 1668 |
\tzhelplines(4,3) |
| 1669 |
\tzcoors*(0,0)(A)(1,2)(B){B}[b](3,3)(C)(4,2)(D); |
| 1670 |
\tzlinks(A)[to[out=80,in=180]] |
| 1671 |
(B)[to[out=0,in=180]] |
| 1672 |
(C)[to[out=0,in=180]] |
| 1673 |
(D){End!}[r]; |
| 1674 |
\end{tikzpicture} |
| 1675 |
\end{tzcode} |
| 1676 |
|
| 1677 |
See Section \ref{s:tzlink} on page \pageref{s:tzlink}, for more details on |\tzlink|. |
| 1678 |
|
| 1679 |
See Section \ref{s:tzlink} on page \pageref{s:tzlinks}, for more details on |\tztos|. |
| 1680 |
|
| 1681 |
\subsection{\protect\cmd{\tzfn}} |
| 1682 |
\label{ss:curves:tzfn} |
| 1683 |
|
| 1684 |
With \icmd{\tzfn}, you can plot functions such as $f(x)=\frac13(x-1)^3+1$, $g(x)=\sin x$, $h(x)=\sqrt{x-1}$, and so on. |
| 1685 |
See Section \ref{s:tzfn} on page \pageref{s:tzfn}, for more details on |\tzfn|. |
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
|