The voodoo effect comes from the fact that when a coordinate is omitted origin is assumed and this happens to be the center of the circle. If you change the starting point the mystery goes away rather quickly.
I've placed more arrows to show the effect when the paths start from different coordinates.
\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\def\rad{2cm}
\begin{document}
\begin{tikzpicture}
[point/.style = {draw, circle, fill=black, inner sep=0.5pt}]
\draw[style=help lines] (0,-1) grid[step=1cm] (5,4);
\node (C) at (2,1) [point,label=0:C]{};
\draw (C) circle (\rad);
\path (2,1) node[point,label={180:P}] (P) at +(120:\rad){};
\foreach \x in {0,10,...,90}{
\draw[-latex,draw=blue,thick] (2,1) -- (P) -- ([turn]\x:2cm);
\draw[-latex,draw=red] (P) -- ([turn]\x:2cm);% You can add (0,0) -- as an initial point too
}
\end{tikzpicture}
\end{document}
As you can see, when initiated from a different point the red arrows loose the magic tangentiality but rather follow the incoming angle to that point (though blue arrows still preserve since the initial point is given). When the initial point is omitted it assumes that the path starts from (0,0) hence there is an inherent illusion of guessing the tangent.
A solution which allows to draw intersection segments
of any two intersections is available as tikz library fillbetween
.
This library works as general purpose tikz
library, but it is shipped with pgfplots
and you need to load pgfplots
in order to make it work:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\draw [name path=red,red] (120:1.06) circle (1.9);
%\draw [name path=yellow,yellow] (0:1.06) circle (2.12);
\draw [name path=green,green!50!black] (0:0.77) circle (2.41);
\draw [name path=blue,blue] (0:0) circle (1.06);
% substitute this temp path by `\path` to make it invisible:
\draw[name path=temp1, intersection segments={of=red and blue,sequence=L1}];
\draw[red,-stealth,ultra thick, intersection segments={of=temp1 and green,sequence=L3}];
\end{tikzpicture}
\end{document}
The key intersection segments
is described in all detail in the pgfplots
reference manual section "5.6.6 Intersection Segment Recombination"; the key idea in this case is to
create a temporary path temp1
which is the first intersection segment of red and blue
, more precisely, it is the first intersection segment in the L
eft argument in red and blue
: red
. This path is drawn as thin black path. Substitute its \draw
statement by \path
to make it invisible.
Compute the desired intersection segment
by intersecting temp1
and green
and use the correct intersection segment. By trial and error I figured that it is the third segment of path temp1
which is written as L3
(L
= left argument in temp1 and green
and 3
means third segment of that path).
The argument involves some trial and error because fillbetween
is unaware of the fact that end and startpoint are connected -- and we as end users do not see start and end point.
Note that you can connect these path segments with other paths. If such an intersection segment
should be the continuation of another path, use --
as before the first argument in sequence. This allows to fill paths segments:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\draw [name path=red,red] (120:1.06) circle (1.9);
%\draw [name path=yellow,yellow] (0:1.06) circle (2.12);
\draw [name path=green,green!50!black] (0:0.77) circle (2.41);
\draw [name path=blue,blue] (0:0) circle (1.06);
% substitute this temp path by `\path` to make it invisible:
\draw[name path=temp1, intersection segments={of=red and blue,sequence=L1}];
\draw[red,fill=blue,-stealth,ultra thick, intersection segments={of=temp1 and green,sequence=L3}]
[intersection segments={of=temp1 and green, sequence={--R2}}]
;
\end{tikzpicture}
\end{document}
Best Answer
You can do something simple such as
The code:
Or. you can go "really" 3D:
The result:
In the last code I used a variation of Tomas M. Trzeciak's example on
Stereographic and cylindrical map projections
Explanation on
turn
Regarding the question about the
turn
key, a little example can be illustrative:When you use
(<coord1>) -- (<coord2>) -- ([turn]<angle>:<distance>)
you are specifying a point that lies<distance>
away from(<coord2>)
in the direction of the last tangent entering the last point, but with a rotation of<angle>
(further details on page 141 of the manual for version 3.0 of PGF).Means join
(C)
to(P)
with a straight line; since the tangent at(P)
to this line is the line itself,([turn]-90:2cm)
performs a rotation of-90
degrees and locates the point2cm
away from(P)
in this direction. However, when you saythis is the same as
and things work (well, if you were ineterested just in the final red segment) just because
turn
takes the origin(0,0)
as the default first coordinate. Had you centered your circle around a different point, you would've got the wrong result as can be seen in the image in the middle in the figure below. To prevent this is better to sayif you want both segments drawn or
to draw just the last part. In any case, when using
turn
you previously have to specify two coordinates in the path so the proper angle is calculated.