13

I have a path in my application that I want to split up in smaller paths. These, I would like to draw with a label attached to them. Take the following image as an example:

What I am trying to achieve

The upper arc is split up into three segments by the horizontal lines and by the two lines coming out of the center of the circle. I draw all three parts of the path and attach a label to them.

Now, the way I do this now is a bit tedious. For each segment I have to reconstruct the path by hand: I have to specify how the path is continued at each intersection. In this case the intersection is simple and the continuation is clear, but if the path is complicated this becomes more difficult.

What I would like to do is the following:

  1. Define a full path, in this case the upper arc from the the left all the way to the right. This path could be arbitrarily complicated.
  2. Find coordinates in the path by intersecting with other paths.
  3. Have a command to say: draw the path from the first intersection coordinate to the second and assign a label to this segment. Draw the path from the second intersection to the third, etc.

How can I achieve this?

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,shapes.multipart,fit,shapes,calc,backgrounds,decorations.pathreplacing,decorations.markings,intersections}

\begin{document}

\begin{tikzpicture}[scale=2]
\path[name path=t] (1,0) to[out=90,in=180] (2,1) to[out=0,in=90] (3,0); % top arc
\path [name path=ml] (2,0) -- (1,1);
\path [name intersections={of=ml and t}];
\coordinate (A) at (intersection-1);
\path [name path=l] (2,0) -- (3,1);
\path [name intersections={of=l and t}];
\coordinate (B) at (intersection-1);

\draw[thick,draw=blue,] (3,0) to[out=90,in=315] node[midway,above right] {$c$} (B) to[out=135,in=45] node[midway,above] {$b$} (A) to[out=225,in=90] node[midway,above left] {$a$} (1,0);
\draw[thick,draw=blue,] (1,0) -- (0,0) node[midway,above] {};

\draw[thick,draw=blue,] (1,0) to[out=-90,in=180] node[midway,below left] {} (2,-1);
\draw[thick,draw=blue,] (2,-1) to[out=0,in=-90] node[midway,below right] {} (3,0);
\draw[thick,draw=blue,] (4,0) -- (3,0) node[midway,above] {};

\draw[thick,draw=blue,] (2,0) -- node[midway,right] {} (2,-1);
\draw[thick,draw=blue,] (A) -- node[midway,below left] {} (2,0);
\draw[thick,draw=blue,] (2,0) -- node[midway,below right] {} (B);
\end{tikzpicture}
\end{document}
  • 1
    You probably want the standalone document class instead of minimal. See tex.stackexchange.com/questions/42114/… – Matthew Leingang Nov 13 '14 at 13:19
  • 1
    So basically you want to create the path before drawing it, then draw it in pieces? – Matthew Leingang Nov 13 '14 at 13:20
  • 1
    May be this helps: tex.stackexchange.com/q/74986/1952, I understand you want to draw the path in pieces to proper label it. This question asks how to convert some particular path point into a percentage to later use pos=... and the answer provides and iterative solution. – Ignasi Nov 13 '14 at 15:48
  • 1
    You could try cropping the path. – John Kormylo Nov 13 '14 at 15:57
  • 2
    If the only purpose of drawing the path in pieces is to add labels, an easier solution might be possible. If you actually want to \draw in pieces that would really depend on exactly how you want to specify the path -- for instance, you could code each portion of the path separately via control points. – Peter Grill Nov 13 '14 at 22:01
2

This is a very late answer and the tools used in it were, if I am not mistaken, not available at the time you asked the question. I found this question with this query, and the purpose of this answer is just to mention that now rather convenient means to do what you suggest. The new tool is the pgfplots library fillbetween that allows you to split paths in segments, which you can redraw, fill, or use in other ways.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{calc,shapes.multipart,fit,shapes,calc,backgrounds,decorations.pathreplacing,decorations.markings,intersections}
\usepgfplotslibrary{fillbetween}
\begin{document}

\begin{tikzpicture}[scale=2]
\path[name path=t] (1,0) to[out=90,in=180] (2,1) to[out=0,in=90] (3,0); % top arc
\path [name path=ml] (2,0) -- (1,1);
\path [name intersections={of=ml and t}];
\coordinate (A) at (intersection-1);
\path [name path=l] (2,0) -- (3,1);
\path [name intersections={of=l and t}];
\coordinate (B) at (intersection-1);


\draw[thick,draw=blue,] (3,0) to[out=90,in=315] node[midway,above right] {$c$} (B) to[out=135,in=45] node[midway,above] {$b$} (A) to[out=225,in=90] node[midway,above left] {$a$} (1,0);
\draw[thick,draw=blue,] (1,0) -- (0,0) node[midway,above] {};

\draw[thick,draw=blue,] (1,0) to[out=-90,in=180] node[midway,below left] {} (2,-1);
\draw[thick,draw=blue,] (2,-1) to[out=0,in=-90] node[midway,below right] {} (3,0);
\draw[thick,draw=blue,] (4,0) -- (3,0) node[midway,above] {};

\draw[thick,draw=blue,] (2,0) -- node[midway,right] {} (2,-1);
\draw[thick,draw=blue,] (A) -- node[midway,below left] {} (2,0);
\draw[thick,draw=blue,] (2,0) -- node[midway,below right] {} (B);

% draw the left segment
\draw[thick,red,
        intersection segments={of=t and ml,sequence={L1}}];
% construct an auxiliary path
\path[name path=aux,%draw=green,thick,
        intersection segments={of=t and ml,sequence={L0}}];
% draw the middle segment
\draw[thick,green!60!black,
        intersection segments={of=aux and l,sequence={L1}}];
% draw the right segment
\draw[thick,purple,
        intersection segments={of=aux and l,sequence={L0}}];
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.