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}
10
  • 1
    You probably want the standalone document class instead of minimal. See tex.stackexchange.com/questions/42114/… Nov 13 '14 at 13:19
  • 1
    So basically you want to create the path before drawing it, then draw it in pieces? 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. 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. Nov 13 '14 at 22:01
3

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

1

I realise this is a very late answer, but this looks like a nice question to showcase the latest (as of Feb 2021) update of the spath3 package which introduces a number of routines for splitting paths and working with components of it.

\documentclass{article}
%\url{https://tex.stackexchange.com/q/211995/86}
\usepackage{tikz}
\usetikzlibrary{spath3, intersections}

\begin{document}

\begin{tikzpicture}
\begin{scope}[scale=2]
% Save the upper part of the arc
\path[spath/save=t] (1,0) to[out=90,in=180] (2,1) to[out=0,in=90] (3,0);
% These two are used to find the splitting points
\path [spath/save=ml] (2,0) -- (1,1);
\path [spath/save=l] (2,0) -- (3,1);

% Split the arc at the points where it intersects the
% other two paths, and then separate it into components
\tikzset{
  spath/split at intersections with={t}{ml},
  spath/split at intersections with={t}{l},
  spath/get components of={t}\cpts
}

% Draw the Y-shaed central bit, using a coordinate system
% defined from the components to get their endpoints
\draw[thick,draw=blue] (spath cs:\getComponentOf\cpts{1} 1) -- (2,0) -- (spath cs:\getComponentOf\cpts{3} 0) (2,0) -- (2,-1);

% Draw the left-hand part (in red), reversing the initial
% arc so that the join is correct
\draw[thick,red, spath/restore reverse=\getComponentOf\cpts{1}] -- (0,0);
% Label it half way along
\node[above left,spath/transform to={\getComponentOf\cpts{1}}{.5}] {\(a\)};

% Draw the middle part
\draw[thick,green, spath/restore=\getComponentOf\cpts{2}];
% And label it
\node[above,spath/transform to={\getComponentOf\cpts{2}}{.5}] {\(b\)};

% Draw the right-hand part
\draw[thick,orange, spath/restore=\getComponentOf\cpts{3}] -- (4,0);
% And label it
\node[above right,spath/transform to={\getComponentOf\cpts{3}}{.5}] {\(c\)};


\draw[thick,draw=blue] (1,0) to[out=-90,in=180] (2,-1) to[out=0,in=-90] (3,0);

\end{scope}
\end{tikzpicture}
\end{document}

Rendering split paths

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.