# Filling between a curve and a Line

How do I fill the space between a Cos curve and a horizontal Line Linking to points on the curve? Say, I would like fill the space between a Line[{{Pi/4, Cos[Pi/4]}, {-Pi/4, Cos[Pi/4]}}] the curve Cos[x], {x, -Pi/4, Pi/4}.

Your Line has a constant $$y$$ value... so I picked a bit more adventurous example:

With[{line =
Interpolation[
{{-Pi, Cos[-Pi]}, {Pi/4, Cos[Pi/4]}},
InterpolationOrder -> 1]},
Plot[{Cos[x], Quiet[line[x]]}, {x, -Pi, Pi/4}, Filling -> {1 -> {2}}]] Line coordinates are fed to first-order Interpolation which creates a function corresponding its $$y$$ value. This is used as the second equation on Plot. With Filling one can specify the interval to fill (and with FillingStyle one can modify the appearance).

(Quiet is used to silence possible warnings on extrapolation of the resulting InterpolationFunction.)

Try this:

Plot[{Cos[x], Cos[\[Pi]/4]}, {x, -\[Pi]/4, \[Pi]/4},
PlotRange -> {0, 1}, Filling -> {1 -> {2}}]


with the following effect: Have fun!