5

I would like to fill the space between the central semi-circumference and the solid black lines above.

\documentclass[tikz,border=1.5cm]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc,intersections,spath3,pgfplots.fillbetween}

\begin{document}
\begin{tikzpicture}
\coordinate (orig1) at (0,0);
\path [spath/save=orig1--A, line width=0.5mm, red] (orig1) arc[start angle=0, end angle=180, radius=5cm] coordinate (A);
\coordinate (orig2) at ($(orig1)!0.5!(A)$);
\path [spath/save=orig2--B, line width=0.5mm, red] (orig2) arc[start angle=0, end angle=180, radius=5cm] coordinate (B);
\path [draw,name intersections={of=orig1--A and orig2--B,by=E}];
\tikzset
{% spath3 operatios:
   spath/split at intersections={orig1--A}{orig2--B},
   spath/get components of={orig1--A}\Acpts,
   spath/get components of={orig2--B}\Bcpts
}
\draw[line width=0.5mm,gray,dashed,
      spath/use=\getComponentOf\Acpts{1},
      spath/use={\getComponentOf\Bcpts{2},weld}];
\draw[name path=smerge, line width=0.5mm,
      spath/use=\getComponentOf\Acpts{2},spath/use=\getComponentOf\Bcpts{1}];
      
\draw[line width=0.25mm,dotted] ([shift=({-1,0})]B)--([shift=({1,0})]orig1);

\path [draw, name path=s3, line width=0.5mm, gray] (orig2) arc[start angle=0, end angle=180, radius=2.5cm];

\tikzfillbetween[of=smerge and s3]{blue, opacity=0.2};

\end{tikzpicture}
\end{document}

For this reason, I called smerge the path which includes both the two solid black lines and s3 the path of the semi-circumference. Then, I simply tried

\tikzfillbetween[of=smerge and s3]{blue, opacity=0.2};

But this is the result:

enter image description here

The desired area is filled, but also a sort of triangle is filled, starting from the extreme points of the semi-circumference. How can I avoid this and fill only the space between smerge and s3?

4 Answers 4

6

As you're currently using spath3 you can combine the 3 arcs 'welding' them to form a solid (so there is no need for fillbetween).

Something like this:

\documentclass[tikz,border=1.618mm]{standalone}
\usetikzlibrary{calc,intersections,spath3}

\begin{document}
\begin{tikzpicture}
\coordinate (orig1) at (0,0);
\path [spath/save=orig1--A] (orig1) arc[start angle=0, end angle=180, radius=5cm] coordinate (A);
\coordinate (orig2) at ($(orig1)!0.5!(A)$);
\path [spath/save=orig2--B] (orig2) arc[start angle=0, end angle=180, radius=5cm] coordinate (B);
\path [draw,name intersections={of=orig1--A and orig2--B,by=E}];
\node at (E)[circle,fill,red] {};
% creating the 'gray' arc and saving it (it will be gray)
\path [spath/save=s3] (orig2) arc[start angle=0, end angle=180, radius=2.5cm];
\tikzset
{% spath3 operatios:
   spath/split at intersections={orig1--A}{orig2--B},
   spath/get components of={orig1--A}\Acpts,
   spath/get components of={orig2--B}\Bcpts
}
\draw[line width=0.5mm,gray,dashed,
      spath/use=\getComponentOf\Acpts{1},
      spath/use={\getComponentOf\Bcpts{2},weld}];
\draw[name path=smerge, line width=0.5mm,
      spath/use=\getComponentOf\Acpts{2},spath/use=\getComponentOf\Bcpts{1}];
% drawing the saved gray path
\draw[spath/use=s3,line width=0.5mm, gray];
% combining various arcs in one solid
\fill[blue, opacity=0.2,
      spath/use={\getComponentOf\Acpts{2},reverse},
      spath/use={\getComponentOf\Bcpts{1},reverse,weld},
      spath/use={s3,weld}
     ];
\draw[line width=0.25mm,dotted] ([shift=({-1,0})]B)--([shift=({1,0})]orig1);
%\tikzfillbetween[of=smerge and s3]{blue, opacity=0.2};
\end{tikzpicture}
\end{document}

enter image description here

8

Just a simpler solution without the unneeded fancy packages.

\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\newcommand{\radius}{3cm}
\draw[gray, thick, dotted] (-2*\radius-1,0) -- (2*\radius+1,0);
\draw[gray, ultra thick, dotted] (0.5*\radius,0) arc[start angle=0, end angle=180, radius=\radius];
\draw[gray, ultra thick, dotted] (-0.5*\radius,0) arc[start angle=180, end angle=0, radius=\radius];
\draw[ultra thick, fill=blue!20] (0.5*\radius,0) arc[start angle=0, end angle=180, radius=0.5*\radius] arc[start angle=0, end angle=-60, radius=-\radius] arc[start angle=60, end angle=0, radius=\radius] -- cycle;
\end{tikzpicture}
\end{document}

Arcs with filled area

1
4

Adaptations

  • Just change the order of \Bcpts{1} and \Acpts{2}:
    \draw[name path=smerge, line width=0.5mm,
          spath/use=\getComponentOf\Bcpts{1},
          spath/use=\getComponentOf\Acpts{2}];
    
    This means: first draw the left part of right arc (B), then the right part of left arc (A). This kind of problem can mostly be changed by correcting the order.

Code

\documentclass[tikz,border=1.5cm]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc,intersections,spath3,pgfplots.fillbetween}

\begin{document}
\begin{tikzpicture}
\coordinate (orig1) at (0,0);
\path [spath/save=orig1--A, line width=0.5mm, red] (orig1) arc[start angle=0, end angle=180, radius=5cm] coordinate (A);
\coordinate (orig2) at ($(orig1)!0.5!(A)$);
\path [spath/save=orig2--B, line width=0.5mm, red] (orig2) arc[start angle=0, end angle=180, radius=5cm] coordinate (B);
\path [draw,name intersections={of=orig1--A and orig2--B,by=E}];
\tikzset
{% spath3 operatios:
   spath/split at intersections={orig1--A}{orig2--B},
   spath/get components of={orig1--A}\Acpts,
   spath/get components of={orig2--B}\Bcpts
}
\draw[line width=0.5mm,gray,dashed,
      spath/use=\getComponentOf\Acpts{1},
      spath/use={\getComponentOf\Bcpts{2},weld}];
\draw[name path=smerge, line width=0.5mm,
      spath/use=\getComponentOf\Bcpts{1},
      spath/use=\getComponentOf\Acpts{2}];
      
\draw[line width=0.25mm,dotted] ([shift=({-1,0})]B)--([shift=({1,0})]orig1);

\path [draw, name path=s3, line width=0.5mm, gray] (orig2) arc[start angle=0, end angle=180, radius=2.5cm];

\tikzfillbetween[of=smerge and s3]{blue, opacity=0.2};

\end{tikzpicture}
\end{document}

Result

enter image description here

2

While you are waiting for answers to your Tikz questions, here is a lualatex alternative using the built-in Metapost language.

enter image description here

You need to compile this with lualatex:

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
input colorbrewer-rgb
beginfig(1);
  numeric r, s; r = 144; s = 60;
  path a, b, c, base, shark;
  a = halfcircle scaled 2r shifted (s * right);
  b = halfcircle scaled 2r shifted (s * left);
  c = halfcircle scaled abs (point 0 of b - point 4 of a);
  base = point 4 of b shifted 20 left -- point 0 of a shifted 20 right;
  shark = buildcycle(b, a, reverse c);

  fill shark withcolor Blues 8 3;
  fill c -- cycle withcolor Oranges 8 2;
  draw a dashed evenly;
  draw b dashed evenly;
  draw shark;
  draw base dashed withdots scaled 1/2;

endfig;
\end{mplibcode}
\end{document}

Notes

  • The colorbrewer colour definitions for MP are part of a full texmf installation.

  • The built-in halfcircle path has five points numbered from 0 (at 3 o'clock) to 4 (at 9 o'clock).

  • The buildcycle macro takes a list of <path> variables, and attempts to combine them into a closed path. It works best if you list the paths in the right order, and have them all running in the same direction round the cycle. Hence buildcycle(a, b, reverse c).

  • You can only fill closed paths, hence you have to do fill c--cycle rather than just fill c.

  • Filling and drawing are separate operations in MP.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .