# tikz apply fill between two lines

Simple question:

Is it possible to fill the following shape:

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\begin{documet}
\begin{tikzpicture}
\draw [decorate,decoration = {snake,amplitude =.4mm, segment length = 5mm}] (0,0)--(10,0);
\draw (0,0)..controls(0,-1)and(10,-1)..(10,0);
\end{tikzpicture}
\end{document}


Apologies if this question is rather simplistic.

-

The typical approach to fill complex shapes is trying to envision our area as the intersection of two simpler closed paths, and then fill one of those paths areas while clipping to the another.

For example, your region can be seen as the intersection of the following two paths:

\draw  (0,0) .. controls +(0,-1) and +(0,-1)..(10,0) -- (10,1) -- (0,1) --cycle ;
\draw [decorate,decoration = {snake,amplitude =.4mm, segment length = 5mm}] (0,0)--(10,0) -- (10,-1) -- (0,-1) -- cycle;


So the idea is to fill the "wavy rectangle", and clipping the result to the "curved bottom rectangle". The part of the code which does this trick has to be enclosed in a scope to prevent the clipping to be applied to the whole figure (in case that it is part of something bigger).

The following code implements this idea:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip  (0,0) .. controls +(0,-1) and +(0,-1)..(10,0) -- (10,1) -- (0,1) --cycle ;
\draw  [fill=orange!50, decorate,decoration = {snake,amplitude =.4mm, segment length = 5mm}] (0,0)--(10,0) -- (10,-1) -- (0,-1) --cycle ;
\end{scope}
\draw (0,0) ..controls +(0,-1)and +(0,-1)..(10,0);
\end{tikzpicture}
\end{document}


-
I would enclose the \clip path in the pgfinterruptboundingbox environment. Otherwise you have nearly 1cm more height in the resulting box containing the TikZ picture. Of course, this doesn’t matter if you add more stuff above the wavy line. –  Qrrbrbirlbel Mar 6 '13 at 21:07

In this simple case, you can use just one path that gets filled.

A few notes:

• The decoration is activated with decorate {<part of path that shall be decorated>}, so we put (0,0) -- (10,0) in it.

• The control syntax understands relative coordinates which I introduced because I needed to switch the direction of the curve (it now goes from (10, 0) to (0, 0)).

• Instead of the .. controls (<c1>) and (<c2>) .. syntax you can also use curve to paths. In this case with the angles set to 270 and a distance of 1cm:

to[distance=1cm, out=270, in = 270] (water-start)

• The -- cycle makes a nice line at the start.

• I have also introduced two coordinates:

• water-start and
• water-end.

As water-start is used twice in the path, you now only need to change the \coordinate line, if you want to start elsewhere and not two values in a path.

## Code

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
\coordinate (water-start) at (0,0);
\coordinate (water-end) at (10,0);
\draw[
decoration={
snake,
amplitude =.4mm,
segment length = 5mm
},
fill=blue
] decorate {(water-start) -- (water-end)}
%   .. controls +(0,-1) and +(0,-1) .. (water-start) % this is the same
to[distance=1cm, out=270, in = 270] (water-start) % as this
-- cycle
;
\end{tikzpicture}
\end{document}


## Output

-

As stated in the TIKZ/PGF-3.0 manual in section 24.2 Decorating a Subpath Using the Decorate Path Command this can be achieved with the decorate path command.

\draw[fill=orange!50] (0,0) -- (0,1) -- (1,1) decorate[decoration=snake] {-- (1,0)} -- cycle;

-
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}
\begin{document}
\begin{pspicture}[dimen=monkey](-4,-2)(4,0)
\pscustom[fillstyle=solid,fillcolor=cyan]
{
\psplot[algebraic,plotpoints=150]{-4}{4}{.1*sin(2*Pi*x/(8/15))}
\psellipticarcn(4,2){0}{180}
\closepath
}
\end{pspicture}
\end{document}


-