diff options
Diffstat (limited to 'Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-coordinates.tex')
-rw-r--r-- | Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-coordinates.tex | 533 |
1 files changed, 349 insertions, 184 deletions
diff --git a/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-coordinates.tex b/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-coordinates.tex index 448bd24a029..1847b27bc92 100644 --- a/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-coordinates.tex +++ b/Master/texmf-dist/doc/generic/pgf/text-en/pgfmanual-en-tikz-coordinates.tex @@ -15,8 +15,8 @@ A \emph{coordinate} is a position on the canvas on which your picture is drawn. \tikzname\ uses a special syntax for specifying coordinates. Coordinates are always put in round brackets. The general -syntax is -\declare{|(|\opt{|[|\meta{options}|]|}\meta{coordinate specification}|)|}. +syntax is +\declare{|(|\opt{|[|\meta{options}|]|}\meta{coordinate specification}|)|}. The \meta{coordinate specification} specified coordinates using one of many different possible \emph{coordinate systems}. Examples are the @@ -109,7 +109,7 @@ Let us start with the basic coordinate systems. To specify a coordinate in the coordinate system implicitly, you use two dimensions that are separated by a comma as in |(0cm,3pt)| or - |(2cm,\textheight)|. + |(2cm,\textheight)|. \begin{codeexample}[] \begin{tikzpicture} \draw[help lines] (0,0) grid (3,2); @@ -127,11 +127,10 @@ Let us start with the basic coordinate systems. $z$-vectors. By default, the $x$-vector points 1cm to the right, the $y$-vector points 1cm upwards, but this can be changed arbitrarily as explained in Section~\ref{section-xyz}. The default - $z$-vector points to $\bigl(-\frac{1}{\sqrt2} - \textrm{cm},-\frac{1}{\sqrt2}\textrm{cm}\bigr)$. + $z$-vector points to $\bigl(-3.85\textrm{mm},-3.85\textrm{mm}\bigr)$. To specify the factors by which the vectors should be multiplied - before being added, you use the following three options: + before being added, you use the following three options: \begin{key}{/tikz/cs/x=\meta{factor} (initially 0)} Factor by which the $x$-vector is multiplied. \end{key} @@ -152,7 +151,7 @@ Let us start with the basic coordinate systems. This coordinate system can also be selected implicitly. To do so, you just provide two or three comma-separated factors (not - dimensions). + dimensions). \begin{codeexample}[] \begin{tikzpicture}[->] \draw (0,0) -- (1,0); @@ -179,7 +178,7 @@ of two coordinate |(|\meta{x}|,0)| and |(0pt,|\meta{y}|)| is used. \meta{y} internally uses a mixture of dimensions and dimensionless values, then all dimensionless values are ``upgraded'' to dimensions by interpreting them as |pt|. So, |2+3cm| is the same dimension as -|2pt+3cm|. +|2pt+3cm|. \begin{coordinatesystem}{canvas polar} The |canvas polar| coordinate system allows you to specify @@ -210,9 +209,9 @@ by interpreting them as |pt|. So, |2+3cm| is the same dimension as \tikz \draw (0,0) -- (canvas polar cs:angle=30,radius=1cm); \end{codeexample} - The implicit form for canvas polar coordinates is the following: + The implicit form for canvas polar coordinates is the following: you specify the angle and the distance, separated by a colon as in - |(30:1cm)|. + |(30:1cm)|. \begin{codeexample}[] \tikz \draw (0cm,0cm) -- (30:1cm) -- (60:1cm) -- (90:1cm) @@ -284,7 +283,7 @@ by interpreting them as |pt|. So, |2+3cm| is the same dimension as \begin{coordinatesystem}{xy polar} This is just an alias for |xyz polar|, which some people might prefer as there is no z-coordinate involved in the |xyz polar| - coordinates. + coordinates. \end{coordinatesystem} @@ -308,7 +307,7 @@ The |barycentric cs| allows you to specify such coordinates easily. should be a comma-separated list of expressions of the form \meta{node name}|=|\meta{number}. Note that (currently) the list should not contain any spaces before or after the \meta{node name} - (unlike normal key-value pairs). + (unlike normal key-value pairs). The specified coordinate is now computed as follows: Each pair provides one vector and a number. The vector is the |center| anchor @@ -323,7 +322,7 @@ The |barycentric cs| allows you to specify such coordinates easily. \coordinate (content) at (90:3cm); \coordinate (structure) at (210:3cm); \coordinate (form) at (-30:3cm); - + \node [above] at (content) {content oriented}; \node [below left] at (structure) {structure oriented}; \node [below right] at (form) {form oriented}; @@ -361,12 +360,12 @@ you use the following coordinate system: You can use three options to specify which coordinate you mean: \begin{key}{/tikz/cs/name=\meta{node name}} Specifies the node in which you which to specify a coordinate. The - \meta{node name} is + \meta{node name} is the name that was previously used to name the node using the |name=|\meta{node name} option or the special node name syntax. \end{key} \begin{key}{/tikz/anchor=\meta{anchor}} - Specifies an anchor of the node. Here is an example: + Specifies an anchor of the node. Here is an example: \begin{codeexample}[] \begin{tikzpicture} \node (shape) at (0,2) [draw] {|class Shape|}; @@ -398,7 +397,7 @@ you use the following coordinate system: It is possible to provide \emph{neither} the |anchor=| option nor the |angle=| option. In this case, \tikzname\ will calculate an - appropriate border position for you. Here is an example: + appropriate border position for you. Here is an example: \begin{codeexample}[] \begin{tikzpicture} @@ -418,12 +417,12 @@ you use the following coordinate system: with the curve-to operation |..|. For other path commands, such as |parabola| or |plot|, the center will be used. If this is not desired, you should give a named anchor or an angle anchor. - + Note that if you use an automatic coordinate for both the start and the end of a line-to, as in |--(node cs:name=b)--|, then \emph{two} border coordinates are computed with a move-to between them. This is usually exactly what you want. - + If you use relative coordinates together with automatic anchor coordinates, the relative coordinates are computed relative to the node's center, not relative to the border point. Here is an @@ -458,159 +457,117 @@ Similarly, in the following examples both control points are $(1,1)$: (2,2) node(c) [rectangle,rotate=20,draw,fill] {A rectangle} (5,2) node(d) [rectangle,rotate=-30,draw,fill] {Another rectangle}; \draw[thick] (a.south) -- (b) -- (c) -- (d); - \draw[thick,red,->] (a) |- +(1,3) -| (c) |- (b); - \draw[thick,blue,<->] (b) .. controls +(right:2cm) and +(down:1cm) .. (d); + \draw[thick,red,->] (a) |- +(1,3) -| (c) |- (b); + \draw[thick,blue,<->] (b) .. controls +(right:2cm) and +(down:1cm) .. (d); \end{tikzpicture} \end{codeexample} \end{coordinatesystem} - -\subsubsection{Intersection Coordinate Systems} - -Often you wish to specify a point that is on the -intersection of two lines or shapes. For this, the following -coordinate system is useful: - -\begin{coordinatesystem}{intersection} - First, you must specify two objects that should be - intersected. These ``objects'' can either be lines or the shapes of - nodes. There are two option to specify the first object: - \begin{key}{/tikz/cs/first line={\ttfamily\char`\{}|(|\meta{first - coordinate}|)--(|\meta{second coordinate}|)|{\ttfamily\char`\}}} - Specifies that the first object is a line that goes from - \meta{first coordinate} to meta{second coordinate}. - \end{key} - Note that you have to write |--| between the coordinate, but this - does not mean that anything is added to the path. This is simply a - special syntax. - \begin{key}{/tikz/cs/first node=\meta{node}} - Specifies that the first object is a previously defined node named - \meta{node}. - \end{key} - - To specify the second object, you use one of the following keys: - \begin{key}{/tikz/cs/second line={\ttfamily\char`\{}|(|\meta{first - coordinate}|)--(|\meta{second coordinate}|)|{\ttfamily\char`\}}} - As above. - \end{key} - \begin{key}{/tikz/cs/second node=\meta{node}} - Specifies that the second object is a previously defined node - named \meta{node}. - \end{key} - - Since it is possible that two objects have multiple intersections, - you may need to specify which solution you want: - \begin{key}{/tikz/cs/solution=\meta{number} (initially 1)} - Specifies which solution should be used. Numbering starts with 1. - \end{key} - The coordinate specified in this way is the \meta{number}th - intersection of the two objects. If the objects do not intersect, - an error may occur. +% Deprecated: + +% \subsubsection{Intersection Coordinate Systems} + +% Often you wish to specify a point that is on the +% intersection of two lines or shapes. For this, the following +% coordinate system is useful: + +% \begin{coordinatesystem}{intersection} +% First, you must specify two objects that should be +% intersected. These ``objects'' can either be lines or the shapes of +% nodes. There are two option to specify the first object: +% \begin{key}{/tikz/cs/first line={\ttfamily\char`\{}|(|\meta{first +% coordinate}|)--(|\meta{second coordinate}|)|{\ttfamily\char`\}}} +% Specifies that the first object is a line that goes from +% \meta{first coordinate} to meta{second coordinate}. +% \end{key} +% Note that you have to write |--| between the coordinate, but this +% does not mean that anything is added to the path. This is simply a +% special syntax. +% \begin{key}{/tikz/cs/first node=\meta{node}} +% Specifies that the first object is a previously defined node named +% \meta{node}. +% \end{key} + +% To specify the second object, you use one of the following keys: +% \begin{key}{/tikz/cs/second line={\ttfamily\char`\{}|(|\meta{first +% coordinate}|)--(|\meta{second coordinate}|)|{\ttfamily\char`\}}} +% As above. +% \end{key} +% \begin{key}{/tikz/cs/second node=\meta{node}} +% Specifies that the second object is a previously defined node +% named \meta{node}. +% \end{key} + +% Since it is possible that two objects have multiple intersections, +% you may need to specify which solution you want: +% \begin{key}{/tikz/cs/solution=\meta{number} (initially 1)} +% Specifies which solution should be used. Numbering starts with 1. +% \end{key} +% The coordinate specified in this way is the \meta{number}th +% intersection of the two objects. If the objects do not intersect, +% an error may occur. + +% \begin{codeexample}[] +% \begin{tikzpicture} +% \draw[help lines] (0,0) grid (3,2); +% \draw (0,0) coordinate (A) -- (3,2) coordinate (B) +% (1,2) -- (3,0); + +% \fill[red] (intersection cs: +% first line={(A)--(B)}, +% second line={(1,2)--(3,0)}) circle (2pt); +% \end{tikzpicture} +% \end{codeexample} + +% The implicit way of specifying this coordinate system is to write +% \declare{|(intersection |\opt{\meta{number}}| of |\meta{first +% object}% +% | and |\meta{second object}|)|}. Here, \meta{first object} either +% has the form \meta{$p_1$}|--|\meta{$p_2$} or it is just a node +% name. Likewise for \meta{second object}. Note that there are \emph{no} +% parentheses around the $p_i$. Thus, you would write +% |(intersection of A--B and 1,2--3,0)| for the intersection of the +% line through the coordinates |A| and |B| and the line through the +% points $(1,2)$ and $(3,0)$. You would write +% |(intersection 2 of c_1 and c_2)| for the second +% intersection of the node named |c_1| and the node named +% |c_2|. + +% \tikzname\ needs an explicit algorithm for computing the +% intersection of two shapes and such an algorithm is available only +% for few shapes. Currently, the following intersection will be +% computed correctly: +% \begin{itemize} +% \item a line and a line +% \item a |circle| node and a line (in any order) +% \item a |circle| and a |circle| +% \end{itemize} +% \begin{codeexample}[] +% \begin{tikzpicture}[scale=.25] +% \coordinate [label=-135:$a$] (a) at ($ (0,0) + (rand,rand) $); +% \coordinate [label=45:$b$] (b) at ($ (3,2) + (rand,rand) $); + +% \coordinate [label=-135:$u$] (u) at (-1,1); +% \coordinate [label=45:$v$] (v) at (6,0); + +% \draw (a) -- (b) +% (u) -- (v); + +% \node (c1) at (a) [draw,circle through=(b)] {}; +% \node (c2) at (b) [draw,circle through=(a)] {}; + +% \coordinate [label=135:$c$] (c) at (intersection 2 of c1 and c2); +% \coordinate [label=-45:$d$] (d) at (intersection of u--v and c2); +% \coordinate [label=135:$e$] (e) at (intersection of u--v and a--b); + +% \foreach \p in {a,b,c,d,e,u,v} +% \fill [opacity=.5] (\p) circle (8pt); +% \end{tikzpicture} +% \end{codeexample} +% \end{coordinatesystem} -\begin{codeexample}[] -\begin{tikzpicture} - \draw[help lines] (0,0) grid (3,2); - \draw (0,0) coordinate (A) -- (3,2) coordinate (B) - (1,2) -- (3,0); - - \fill[red] (intersection cs: - first line={(A)--(B)}, - second line={(1,2)--(3,0)}) circle (2pt); -\end{tikzpicture} -\end{codeexample} - - The implicit way of specifying this coordinate system is to write - \declare{|(intersection |\opt{\meta{number}}| of |\meta{first - object}% - | and |\meta{second object}|)|}. Here, \meta{first obejct} either - has the form \meta{$p_1$}|--|\meta{$p_2$} or it is just a node - name. Likewise for \meta{second object}. Note that there are \emph{no} - parentheses around the $p_i$. Thus, you would write - |(intersection of A--B and 1,2--3,0)| for the intersection of the - line through the coordinates |A| and |B| and the line through the - points $(1,2)$ and $(3,0)$. You would write - |(intersection 2 of c_1 and c_2)| for the second - intersection of the node named |c_1| and the node named - |c_2|. - - \tikzname\ needs an explicit algorithm for computing the - intersection of two shapes and such an algorithm is available only - for few shapes. Currently, the following intersection will be - computed correctly: - \begin{itemize} - \item a line and a line - \item a |circle| node and a line (in any order) - \item a |circle| and a |circle| - \end{itemize} -\begin{codeexample}[] -\begin{tikzpicture}[scale=.25] - \coordinate [label=-135:$a$] (a) at ($ (0,0) + (rand,rand) $); - \coordinate [label=45:$b$] (b) at ($ (3,2) + (rand,rand) $); - \coordinate [label=-135:$u$] (u) at (-1,1); - \coordinate [label=45:$v$] (v) at (6,0); - - \draw (a) -- (b) - (u) -- (v); - - \node (c1) at (a) [draw,circle through=(b)] {}; - \node (c2) at (b) [draw,circle through=(a)] {}; - - \coordinate [label=135:$c$] (c) at (intersection 2 of c1 and c2); - \coordinate [label=-45:$d$] (d) at (intersection of u--v and c2); - \coordinate [label=135:$e$] (e) at (intersection of u--v and a--b); - - \foreach \p in {a,b,c,d,e,u,v} - \fill [opacity=.5] (\p) circle (8pt); -\end{tikzpicture} -\end{codeexample} -\end{coordinatesystem} - -A frequent special case of intersections is the intersection of a -vertical line going through a point $p$ and a horizontal line going -through some other point $q$. For this situation there is another -coordinate system. - -\begin{coordinatesystem}{perpendicular} - This coordinate system works the same way as |intersection|, only - the lines are specified differently: - - \begin{key}{/tikz/cs/horizontal line through={\ttfamily\char`\{}|(|\meta{coordinate}|)|{\ttfamily\char`\}}} - Specifies that one line is a horizontal line that goes through the - given coordinate. - \end{key} - \begin{key}{/tikz/cs/vertical line through={\ttfamily\char`\{}|(|\meta{coordinate}|)|{\ttfamily\char`\}}} - Specifies that the other line is vertical and goes through the - given coordinate. - \end{key} - - The implicit syntax is to write \declare{|(|\meta{p}\verb! |- !\meta{q}|)|} or - \declare{|(|\meta{q}\verb! -| !\meta{p}|)|}. - - For example, \verb!(2,1 |- 3,4)! and \verb!(3,4 -| 2,1)! both yield - the same as \verb!(2,4)! (provided the $xy$-coordinate system has not - been modified). - - The most useful application of the syntax is to draw a line up to some - point on a vertical or horizontal line. Here is an example: - -\begin{codeexample}[] -\begin{tikzpicture} - \path (30:1cm) node(p1) {$p_1$} (75:1cm) node(p2) {$p_2$}; - - \draw (-0.2,0) -- (1.2,0) node(xline)[right] {$q_1$}; - \draw (2,-0.2) -- (2,1.2) node(yline)[above] {$q_2$}; - - \draw[->] (p1) -- (p1 |- xline); - \draw[->] (p2) -- (p2 |- xline); - \draw[->] (p1) -- (p1 -| yline); - \draw[->] (p2) -- (p2 -| yline); -\end{tikzpicture} -\end{codeexample} -\end{coordinatesystem} - - \subsubsection{Tangent Coordinate Systems} \begin{coordinatesystem}{tangent} @@ -626,19 +583,18 @@ coordinate system. The following options may be given: \begin{key}{/tikz/cs/node=\meta{node}} This key specifies the node on whose border the tangent should - lie. + lie. \end{key} \begin{key}{/tikz/cs/point=\meta{point}} - This key speicifes the point through which the tangent should go. + This key specifies the point through which the tangent should go. \end{key} \begin{key}{/tikz/cs/solution=\meta{number}} Specifies which solution should be used if there are more than one. \end{key} - As for intersection coordinate system, a special algorithm is needed - in order to compute the tangent for a given shape. Currently, - tangents can be computed for nodes whose shape is one of the - following: + A special algorithm is needed in order to compute the tangent for a + given shape. Currently, tangents can be computed for nodes whose + shape is one of the following: \begin{itemize} \item |coordinate| \item |circle| @@ -651,7 +607,7 @@ coordinate system. \coordinate (a) at (3,2); \node [circle,draw] (c) at (1,1) [minimum size=40pt] {$c$}; - + \draw[red] (a) -- (tangent cs:node=c,point={(a)},solution=1) -- (c.center) -- (tangent cs:node=c,point={(a)},solution=2) -- cycle; \end{tikzpicture} @@ -660,6 +616,8 @@ coordinate system. There is no implicit syntax for this coordinate system. \end{coordinatesystem} + + \subsubsection{Defining New Coordinate Systems} While the set of coordinate systems that \tikzname\ can parse via @@ -687,8 +645,8 @@ commands are used: defined. \begin{codeexample}[] \makeatletter -\define@key{cylindricalkeys}{angle}{\def\myangle{#1}} -\define@key{cylindricalkeys}{radius}{\def\myradius{#1}} +\define@key{cylindricalkeys}{angle}{\def\myangle{#1}} +\define@key{cylindricalkeys}{radius}{\def\myradius{#1}} \define@key{cylindricalkeys}{z}{\def\myz{#1}} \tikzdeclarecoordinatesystem{cylindrical}% {% @@ -704,11 +662,217 @@ commands are used: \end{command} \begin{command}{\tikzaliascoordinatesystem\marg{new name}\marg{old name}} - Creates an alias of \meta{old name}. + Creates an alias of \meta{old name}. \end{command} +\subsection{Coordinates at Intersections} +\label{section-intersection-coordinates} + +You will wish to compute the intersection of two paths. For the +special and frequent case of two perpendicular lines, a special +coordinate system called |perpendicular| is available. For more +general cases, the |intersection| library can be used. + + +\subsubsection{Intersections of Perpendicular Lines} + +A frequent special case of path intersections is the intersection of a +vertical line going through a point $p$ and a horizontal line going +through some other point $q$. For this situation there is a useful +coordinate system. + +\begin{coordinatesystem}{perpendicular} + You can specify the two lines using the following keys: + + \begin{key}{/tikz/cs/horizontal line through={\ttfamily\char`\{}|(|\meta{coordinate}|)|{\ttfamily\char`\}}} + Specifies that one line is a horizontal line that goes through the + given coordinate. + \end{key} + \begin{key}{/tikz/cs/vertical line through={\ttfamily\char`\{}|(|\meta{coordinate}|)|{\ttfamily\char`\}}} + Specifies that the other line is vertical and goes through the + given coordinate. + \end{key} + + However, in almost all cases you should, instead, use the implicit + syntax. Here, you write \declare{|(|\meta{p}\verb! |- !\meta{q}|)|} or + \declare{|(|\meta{q}\verb! -| !\meta{p}|)|}. + + For example, \verb!(2,1 |- 3,4)! and \verb!(3,4 -| 2,1)! both yield + the same as \verb!(2,4)! (provided the $xy$-coordinate system has not + been modified). + + The most useful application of the syntax is to draw a line up to some + point on a vertical or horizontal line. Here is an example: + +\begin{codeexample}[] +\begin{tikzpicture} + \path (30:1cm) node(p1) {$p_1$} (75:1cm) node(p2) {$p_2$}; + + \draw (-0.2,0) -- (1.2,0) node(xline)[right] {$q_1$}; + \draw (2,-0.2) -- (2,1.2) node(yline)[above] {$q_2$}; + + \draw[->] (p1) -- (p1 |- xline); + \draw[->] (p2) -- (p2 |- xline); + \draw[->] (p1) -- (p1 -| yline); + \draw[->] (p2) -- (p2 -| yline); +\end{tikzpicture} +\end{codeexample} +\end{coordinatesystem} + + +\subsubsection{Intersections of Arbitrary Paths} + +\begin{tikzlibrary}{intersections} + This library enables the calculation of intersections of + two arbitrary paths. However, due to the low accuracy of + \TeX, the paths should not be ``too complicated''. + In particular, you should not try to intersect paths consisting + lots of very small segments such as plots or decorated paths. +\end{tikzlibrary} + +To find the intersections of two paths in \tikzname, they must be +``named''. A ``named path'' is, quite simply, a path that has been +named using the following key: + +\begin{keylist}{% + /tikz/name path=\meta{name}, + /tikz/name path global=\meta{name}} + The effect of this key is that, after the path has been constructed, + just before it is used, it is associated with \meta{name}. For |name path|, + this association survives beyond the final semi-colon of the path + but not the end of the surrounding scope. For |name path global|, the association + will survive beyond any scope as well. Handle with care. + + Any paths created by nodes on the (main) path are ignored, unless + this key is explicitly used. If the same \meta{name} is used for the + main path and the node path(s), then the paths will be added + together and then associated with \meta{name}. +\end{keylist} + +To find the intersection of named paths, the following key is used: + +\begin{key}{/tikz/name intersections=\marg{options}} + This key changes the key path to |/tikz/intersection| and processes + \meta{options}. These options determine, among other things, + which paths to use for the intersection. Having processed the + options, any intersections are then found. A coordinate is created + at each intersection, which by default, will be named + |intersection-1|, |intersection-2|, and so on. + Optionally, the prefix |intersection| can be changed, and the + total number of intersections stored in a \TeX-macro. + +\begin{codeexample}[] +\begin{tikzpicture}[every node/.style={opacity=1, black, above left}] + \draw [help lines] grid (3,2); + \draw [name path=ellipse] (2,0.5) ellipse (0.75cm and 1cm); + \draw [name path=rectangle, rotate=10] (0.5,0.5) rectangle +(2,1); + \fill [red, opacity=0.5, name intersections={of=ellipse and rectangle}] + (intersection-1) circle (2pt) node {1} + (intersection-2) circle (2pt) node {2}; +\end{tikzpicture} +\end{codeexample} + +The following keys can be used in \meta{options}: + +\begin{key}{/tikz/intersection/of=\meta{name path 1}| and |\meta{name path 2}} + This key is used to specify the names of the paths to use for + the intersection. +\end{key} + +\begin{key}{/tikz/intersection/name=\meta{prefix} (initially intersection)} + This key specifies the prefix name for the coordinate nodes placed + at each intersection. +\end{key} + +\begin{key}{/tikz/intersection/total=\meta{macro}} + This key will mean than the total number of intersections found + will be stored in \meta{macro}. +\end{key} + +\begin{codeexample}[] +\begin{tikzpicture} + \clip (-2,-2) rectangle (2,2); + \draw [name path=curve 1] (-2,-1) .. controls (8,-1) and (-8,1) .. (2,1); + \draw [name path=curve 2] (-1,-2) .. controls (-1,8) and (1,-8) .. (1,2); + + \fill [name intersections={of=curve 1 and curve 2, name=i, total=\t}] + [red, opacity=0.5, every node/.style={above left, black, opacity=1}] + \foreach \s in {1,...,\t}{(i-\s) circle (2pt) node {\footnotesize\s}}; +\end{tikzpicture} +\end{codeexample} + + + \begin{key}{/tikz/intersection/by=\meta{comma-separated list}} + This key allows you to specify a list of names for the intersection + coordinates. The intersection coordinates will still be named + \meta{prefix}|-|\meta{number}, but additionally the first + coordinate will also be named by the first element of the + \meta{comma-separated list}. What happens is that the + \meta{comma-separated list} is passed to the |\foreach| statement + and for \meta{list member} a coordinate is created at the + already-named intersection. +\begin{codeexample}[] +\begin{tikzpicture} + \clip (-2,-2) rectangle (2,2); + \draw [name path=curve 1] (-2,-1) .. controls (8,-1) and (-8,1) .. (2,1); + \draw [name path=curve 2] (-1,-2) .. controls (-1,8) and (1,-8) .. (1,2); + + \fill [name intersections={of=curve 1 and curve 2, by={a,b}}] + (a) circle (2pt) + (b) circle (2pt); +\end{tikzpicture} +\end{codeexample} + + You can also use the |...| notation of the |\foreach| statement + inside the \meta{comma-separated list}. + + In case an element of the \meta{comma-separated list} starts with + options in square brackets, these options are used when the + coordinate is created. A coordinate name can still, but need not, + follow the options. This + makes it easy to add labels to intersections: +\begin{codeexample}[] +\begin{tikzpicture} + \clip (-2,-2) rectangle (2,2); + \draw [name path=curve 1] (-2,-1) .. controls (8,-1) and (-8,1) .. (2,1); + \draw [name path=curve 2] (-1,-2) .. controls (-1,8) and (1,-8) .. (1,2); + + \fill [name intersections={ + of=curve 1 and curve 2, + by={[label=center:a],[label=center:...],[label=center:i]}}]; +\end{tikzpicture} +\end{codeexample} + \end{key} + + \begin{key}{/tikz/intersection/sort by=\meta{path name}} +By default, the intersections are simply returned in the order that +the intersection algorithm finds them. Unfortunately, this is not +necessarily a ``helpful'' ordering. This key can be used to sort +the intersections along the path specified by \meta{path name}, +which should be one of the paths mentioned in the +|/tikz/intersection/of| key. + +\begin{codeexample}[] +\begin{tikzpicture} +\clip (-0.5,-0.75) rectangle (3.25,2.25); +\foreach \pathname/\shift in {line/0cm, curve/2cm}{ + \tikzset{xshift=\shift} + \draw [->, name path=curve] (1,1.5) .. controls (-1,1) and (2,0.5) .. (0,0); + \draw [->, name path=line] (0,-.5) -- (1,2) ; + \fill [name intersections={of=line and curve,sort by=\pathname, name=i}] + [red, opacity=0.5, every node/.style={left=.25cm, black, opacity=1}] + \foreach \s in {1,2,3}{(i-\s) circle (2pt) node {\footnotesize\s}}; +} +\end{tikzpicture} +\end{codeexample} + + \end{key} +\end{key} + + + \subsection{Relative and Incremental Coordinates} @@ -753,7 +917,7 @@ relative to the start of the curve. This special behavior makes it easy to specify that a curve should ``leave or arrives from a certain direction'' at the start or end. In the following example, the curve ``leaves'' at $30^\circ$ and -``arrives'' at $60^\circ$: +``arrives'' at $60^\circ$: \begin{codeexample}[] \begin{tikzpicture} @@ -802,13 +966,14 @@ decide which you need. \draw[red] (2,0) -- ++(1,0) { [current point is local] -- ++(0,1) } -- ++(-1,0); \end{tikzpicture} -\end{codeexample} +\end{codeexample} In the above example, we could also have given the option outside the scope, for instance as a parameter to the whole scope. \end{key} \subsection{Coordinate Calculations} +\label{tikz-lib-calc} \begin{tikzlibrary}{calc} You need to load this library in order to use the coordinate @@ -837,7 +1002,7 @@ of the point |a|: The general syntax is the following: \begin{quote} - \declare{|(|\opt{|[|\meta{options}|]|}|$|\meta{coordinate computation}|$)|}. + \declare{|(|\opt{|[|\meta{options}|]|}|$|\meta{coordinate computation}|$)|}. \end{quote} As you can see, the syntax uses the \TeX\ math symbol |$| to %$ @@ -849,12 +1014,12 @@ The \meta{coordinate computation} has the following structure: \item It starts with \begin{quote} - \opt{\meta{factor}|*|}\meta{coordinate}\opt{\meta{modifiers}} + \opt{\meta{factor}|*|}\meta{coordinate}\opt{\meta{modifiers}} \end{quote} \item This is optionally followed by |+| or |-| and then another \begin{quote} - \opt{\meta{factor}|*|}\meta{coordinate}\opt{\meta{modifiers}} + \opt{\meta{factor}|*|}\meta{coordinate}\opt{\meta{modifiers}} \end{quote} \item This is once more followed by |+| or |-| and another of the above @@ -886,7 +1051,7 @@ everything up to the next occurrence of |*(|. Note that there is no space between the asterisk and the parenthesis. It is permissible to put the \meta{factor} is curly braces. This can -be used whenever it is unclear where the \meta{factor} would end. +be used whenever it is unclear where the \meta{factor} would end. Here are some examples of coordinate specifications that consist of exactly one \meta{factor} and one \meta{coordinate}: @@ -927,14 +1092,14 @@ factor between $0$ and $1$, not a percentage, and, second, as the the first. It is permissible to use \meta{numbers} that are smaller than $0$ or larger than $1$. The \meta{number} is evaluated using the |\pgfmathparse| command and, thus, it can involve complicated -computations. +computations. \begin{codeexample}[] \begin{tikzpicture} \draw [help lines] (0,0) grid (3,2); \draw (1,0) -- (3,2); - + \foreach \i in {0,0.2,0.5,0.9,1} \node at ($(1,0)!\i!(3,2)$) {\i}; \end{tikzpicture} @@ -1009,7 +1174,7 @@ following: Use the point that is distanced \meta{dimension} from \draw [help lines] (0,0) grid (3,2); \draw (1,0) -- (3,2); - + \foreach \i in {0cm,1cm,15mm} \node at ($(1,0)!\i!(3,2)$) {\i}; \end{tikzpicture} @@ -1060,7 +1225,7 @@ Here is an example: The effect is the following: We project the \meta{projection coordinate} orthogonally onto to the line from \meta{coordinate} to \meta{second coordinate}. This makes it easy to compute projected -points: +points: \begin{codeexample}[] \begin{tikzpicture} \draw [help lines] (0,0) grid (3,2); |