| 1 |
% !TeX root = tikz-ext-manual.tex |
| 2 |
% !TeX spellcheck = en_US |
| 3 |
% Copyright 2022 by Qrrbrbirlbel |
| 4 |
% |
| 5 |
% This file may be distributed and/or modified |
| 6 |
% |
| 7 |
% 1. under the LaTeX Project Public License and/or |
| 8 |
% 2. under the GNU Free Documentation License. |
| 9 |
% |
| 10 |
|
| 11 |
\section{Extending the Path Timers} |
| 12 |
\label{library:timer} |
| 13 |
|
| 14 |
\begin{tikzlibrary}{ext.paths.timer} |
| 15 |
This library adds timers to the path specifications |rectangle|, |parabola|, |sin| and |cos|. |
| 16 |
|
| 17 |
\inspiration{TimerRect-Q,TimerPara-Q}{TimerRect-A,TimerPara-A} |
| 18 |
\end{tikzlibrary} |
| 19 |
|
| 20 |
In \tikzname, the path specification |rectangle|, |parabola|, |sin| and |cos| do not provide |
| 21 |
their own timer, i.\,e. a node placing algorithm that is dependent on the actual path. |
| 22 |
For |rectangle| the timer of the straight line between the rectangle's corners is used, for |
| 23 |
the other paths, nodes, coordinates, pics, etc. are placed on the last coordinate. |
| 24 |
|
| 25 |
This library allows this. |
| 26 |
|
| 27 |
\subsection{Rectangle} |
| 28 |
\indexPathOperationO{rectangle} |
| 29 |
|
| 30 |
For the |rectangle| path operator, the timer starts with |pos = 0| (= |at start|) from\indexKeyO{pos} |
| 31 |
the starting coordinate in a counter-clockwise direction along the rectangle. |
| 32 |
The corners will be at positions 0.0, 0.25, 0.5, 0.75 and 1.0. |
| 33 |
|
| 34 |
\begin{key}{/\tikzext/rectangle timer=|line| or |rectangle|} |
| 35 |
\keycompat{tikz} |
| 36 |
By default, the library activates the new (correct) timer for |rectangle|. |
| 37 |
With |rectangle timer = line| the original line timer can be reinstated. |
| 38 |
\end{key} |
| 39 |
\begin{codeexample}[width=10cm,preamble=\usetikzlibrary{ext.paths.timer}] |
| 40 |
\begin{tikzpicture}[scale=2, every pin edge/.style={latex-, gray}] |
| 41 |
\coordinate [label=above right:Target] (A) at (0,0); |
| 42 |
\coordinate [label=below left:Start] (B) at (1,2); |
| 43 |
\draw[->, help lines] ([shift=(50:.3 and .75)] .5,1) |
| 44 |
arc[start angle=50, delta angle=340, x radius=.3, y radius=.75]; |
| 45 |
\draw (B) rectangle (A) |
| 46 |
foreach \pos/\ang in {at start/60, very near start/90, near start/180, pos=.375/180, |
| 47 |
midway/180, pos=.625/270, near end/0, very near end/0, at end/0}{ |
| 48 |
node[pin=\ang:\pos, style/.expanded=\pos]{}}; |
| 49 |
\end{tikzpicture} |
| 50 |
\end{codeexample} |
| 51 |
|
| 52 |
\subsection{Parabola} |
| 53 |
\indexPathOperationO{parabola}% |
| 54 |
|
| 55 |
For the |parabola| path operator the timer is similar to the |.. controls ..| operator. |
| 56 |
|
| 57 |
The position 0.5 will lie at the |bend|. |
| 58 |
\begin{codeexample}[width=.3\linewidth,preamble=\usetikzlibrary{ext.paths.timer}] |
| 59 |
\begin{tikzpicture} |
| 60 |
\draw[help lines] (-2.25, -1.25) grid (2.25, 3.25); |
| 61 |
\draw ( 2,-1) parabola bend (0,0) (-1,3); |
| 62 |
\draw[ultra thick] (-2,-1) parabola bend (0,0) ( 1,3) |
| 63 |
foreach \pos in {1,...,4,6,7,...,9}{ |
| 64 |
node[ |
| 65 |
pos=.\pos, sloped, fill=white, font=\small, inner sep=+0pt |
| 66 |
] {\pos} |
| 67 |
}; |
| 68 |
\end{tikzpicture} |
| 69 |
\end{codeexample} |
| 70 |
|
| 71 |
If no |bend| is specified half the positions will collapse into one end of the curve. |
| 72 |
|
| 73 |
\begin{codeexample}[width=.3\linewidth,preamble=\usetikzlibrary{ext.paths.timer}] |
| 74 |
\begin{tikzpicture}[every pin edge/.style={latex-, shorten <=1pt, gray}] |
| 75 |
\draw (-2,-2) parabola (1,0) |
| 76 |
foreach \pos in {0, 1, ..., 10} { |
| 77 |
node [pos=\pos/10, pin={[anchor=-18*\pos+90]-18*\pos+270:\pos}]{} |
| 78 |
}; |
| 79 |
\end{tikzpicture} |
| 80 |
\end{codeexample} |
| 81 |
|
| 82 |
\subsection{Sine/Cosine} |
| 83 |
\indexPathOperationO{sin}\indexPathOperationO{cos}% |
| 84 |
|
| 85 |
The |sin| and |cos| path operators also allow placing of nodes along their paths. |
| 86 |
|
| 87 |
\begin{codeexample}[width=.3\linewidth,preamble=\usetikzlibrary{ext.paths.timer}] |
| 88 |
\begin{tikzpicture}[mark nodes on line/.style={insert path={ |
| 89 |
foreach \pos in {1, ..., 9} {node[ |
| 90 |
sloped, fill=white, font=\small, inner sep=+0pt, pos=\pos/10] {\pos}}}}] |
| 91 |
\draw[help lines] (-2.1,-2.1) grid (2.1,0.1); |
| 92 |
\draw (-2,-2) sin (1,0) [mark nodes on line]; |
| 93 |
\draw[shift=(0:1)](-2,-2) cos (1,0) [mark nodes on line]; |
| 94 |
\end{tikzpicture} |
| 95 |
\end{codeexample} |
| 96 |
\endinput |