[Tex/LaTex] How to plot a region under $y=\sin(x)$ in TikZ

tikz-pgf

I would like to plot the shaded region between $y=\sin(x)$ and $y=0$ over $x \in [0, \pi]$ using TikZ and/or possible other packages which I don't know yet. Can you give some examples?

Specifically:

how to do the computation of the special function $\sin$?

how to specify the region in TikZ?

how to shade the region?

Thanks and regards!

Best Answer

This is explained in the sections “15.4 Filling a Path” and “19 Plots of Functions” in the TikZ manual (numbers refer to the 2.10 version).

A simple example (note that \x r interprets \x as radians; the TikZ's sin function takes degrees as input):

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
    \fill[fill=red] (pi/4,0) -- plot [domain=pi/4:3*pi/4] (\x,{sin(\x r)}) -- (3*pi/4,0) -- cycle;
    \draw plot[domain=0:pi] (\x,{sin(\x r)});

    \draw[gray,->] (-0.3,0) -- (pi+0.3,0);
\end{tikzpicture}
\end{document}

example