# Fill from path to axis with tikz intersections

I am trying to represent parts of a plot that extend from a simple curve to the boundaries, but I can't find a simple way of creating the closed path from the intersection of two paths. I have seen much more complicated examples, so I'm sure there is an easy way using intersections but I can't find a description in the manual for something that seems simple. The MWE is below, but what I need is the fill to join up with the curve. Ultimately I need 2 such fills going to the x-axis, but happy to start with 1! Any suggestions welcome.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}
\begin{tikzpicture}
\draw [help lines] (0,0) grid (8,6);
\draw [name path=curve, very thick ] (0,4.5) to [out=-90,in=90]  (8,0);
\draw [name path=top, very thick]  (0,4.5) to (8,4.5)  to (8,3) to (0,3);
\path [name intersections = {of=curve and top}];
\coordinate (A) at (intersection-1);
\coordinate (B) at (intersection-2);
\fill [green] (A)--(8,4.5)--(8,3) --(B) --(A);
\end{tikzpicture}

\end{document}


• Great addition. – Jesse Mar 21 '14 at 23:45

Is this what you are looking for? Here I use only 'clip technique to achieve the objective. I marked out some of your code. First form a clip rectangle

\clip (0,3) rectangle (8,4.5);


then followed by the curve area

\draw [fill=green,very thick ] (0,4.5) to [out=-90,in=90]  (8,0) -- (8,4.5);


Intersection of these two areas becomes the green shape. All these command must be restricted in the scope environment.

Code

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}
\begin{tikzpicture}
\draw [help lines] (0,0) grid (8,6);
%\draw [name path=curve, blue,very thick ] (0,4.5) to [out=-90,in=90]  (8,0);
%\draw [name path=top, red, very thick]  (0,4.5) to (8,4.5)  to (8,3) to (0,3);
%\path [name intersections = {of=curve and top}];
%\coordinate (A) at (intersection-1);
%\coordinate (B) at (intersection-2);
\begin{scope}
\clip (0,3) rectangle (8,4.5);
\draw [fill=green,very thick ] (0,4.5) to [out=-90,in=90]  (8,0) -- (8,4.5);
\end{scope}
\draw [very thick ] (0,4.5) to [out=-90,in=90]  (8,0);
\draw [very thick]  (0,4.5) to (8,4.5)  to (8,3) to (0,3);
\end{tikzpicture}

\end{document}


Yes - that works very - thank you. This is what I was after, so I have just added another 2 scopes. like:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}

\begin{tikzpicture}
\draw [help lines] (0,0) grid (8,6);
%\draw [name path=curve, blue,very thick ] (0,4.5) to [out=-90,in=90]  (8,0);
%\draw [name path=top, red, very thick]  (0,4.5) to (8,4.5)  to (8,3) to (0,3);
%\path [name intersections = {of=curve and top}];
%\coordinate (A) at (intersection-1);
%\coordinate (B) at (intersection-2);
\begin{scope}
\clip (0,3) rectangle (8,4.5);
\draw [fill=green,very thick ] (0,4.5) to [out=-90,in=90]  (8,0) -- (8,4.5);
\end{scope}
\begin{scope}
\clip (0,2) rectangle (8,3);
\draw [fill=blue,very thick ] (0,4.5) to [out=-90,in=90]  (8,0) -- (8,4.5);
\end{scope}
\begin{scope}
\clip (0,0) rectangle (8,2);
\draw [fill=red,very thick ] (0,4.5) to [out=-90,in=90]  (8,0) -- (8,4.5);
\end{scope}
\draw [very thick ] (0,4.5) to [out=-90,in=90]  (8,0);
%\draw [very thick]  (0,4.5) to (8,4.5)  to (8,3) to (0,3);
\end{tikzpicture}

\end{document}
`

to get this: