# [pstricks] Re: area under a curve

Denis Girou Denis.Girou at idris.fr
Fri Nov 23 18:24:51 CET 2001

The following message is a courtesy copy of an article
that has been posted to comp.text.tex as well.

>>>>> "Gregory.Gibby" == Gregory Gibby <berton at et.byu.edu> writes:

Gregory.Gibby> hello
Gregory.Gibby> I am using pstricks to write test questions for basic calc.
Gregory.Gibby> I am having trouble finding a command or technique that will
Gregory.Gibby> shade or crosshatch the area between a curve and the x-axis.

Gregory.Gibby> the type of curve is x^2 - 2*x (or x x mul x 2 mul sub for you
Gregory.Gibby> rpn addicts) from 0 to 4, so the shading has to up from the
Gregory.Gibby> parabola to the x-axis on one part and down from the parabola
Gregory.Gibby> to the axis on another part.

Gregory.Gibby> the documentation I have seen only lets you shade parabolas
Gregory.Gibby> symmetrically.  like you were filling them with water.

Gregory.Gibby> I'm sure that this is an easily solved problem, but I can't find a good
Gregory.Gibby> answer on google or in the graphics companion or the PST doc's.

See for instance paragraphs 19 and 20 (pages 35-37) of the User's guide,
paragraph 4.10 (pages 142-145) of the LaTeX Graphics Companion or the
http://tug.org/applications/PSTricks/Mathematics/
Web page for some more complex examples.

\documentclass{article}

\usepackage{pst-plot}

\pagestyle{empty}

\begin{document}

\begin{center}
\begin{displaymath}
f(x)=x^2 - 2x
\end{displaymath}

\begin{pspicture}(-0.5,-1.5)(4,8)
\psaxes(0,0)(0,-1)(4,8)
\pscustom[fillstyle=crosshatch]{%
\psplot{0}{4}{x x mul x 2 mul sub}
\psline(4,0)}
\end{pspicture}
\end{center}

\end{document}

Denis Girou
--
--------------------------------------------------------------------------
Institut du Développement et des Ressources en Informatique Scientifique |
Centre National de la Recherche Scientifique                             |
Bâtiment 506 - B.P. 167 - 91403 Orsay Cedex - France                     |
--------------------------------------------------------------------------