# How to raster area bounded by two functions?

This code works normally:

\documentclass[pstricks]{standalone}
\usepackage{pst-plot}
%\usepackage{auto-pst-pdf}% only for pdflatex
\begin{pspicture}[algebraic,linestyle=curve](-2,-6)(6,6)
\psaxes{->}(0,0)(-2,-4)(5.5,4)[$x$,0][$y$,90]
\psclip{%
\psplot[linestyle=none]{0}{6.5}{x*(3-x)/2}}
\psplot[linecolor=blue,fillstyle=vlines]{.5}{5}{x*(x-6)+6}
\endpsclip
\psplot{0}{4.5}{x*(3-x)/2}}
\psplot[linecolor=blue]{.5}{5}{x*(x-6)+6}
\rput[bl](1.8,1.2){$y=\dfrac{-x^2+3x}{2}$}
\rput[t](2,-3.1){$y=x^2-6x+6$}
\end{pspicture}
\end{document} but the following code is not working:

\documentclass[pstricks]{standalone}
\usepackage{pst-plot}
%\usepackage{auto-pst-pdf}% only for pdflatex
\begin{pspicture}[algebraic,linestyle=curve](-2,-6)(6,6)
\psaxes{->}(0,0)(-2,-4)(5.5,4)[$x$,0][$y$,90]
\psclip{%
\psplot[linecolor=blue,]{-1}{5}{-1*x+2}}
\psplot[fillstyle=hlines]{.5}{5}{x*(x-6)+6}
\endpsclip
\psplot[linewidth=1.5pt]{.5}{5}{x*(x-6)+6}
\rput[bl](1.5,1){$y=-x+2$}
\rput[t](2,-3.1){$y=x^2-6x+6$}
\end{pspicture}
\end{document} • Welcome to TeX.SX! Can you please expand the code snippet that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a \documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. At the moment we have to guess what packages etc you are using before we can compile your code. – Andrew Nov 20 '18 at 8:30
• You should remove everything from the example code which is not important for the problem, e.g. the margin setting, amsmath, a lot of the PSTricks packages, graphicx – user2478 Nov 20 '18 at 9:22
• @Herbert: I do so since I hope while compiling not having error. – Trong Vuong Nov 20 '18 at 9:30
• linestyle=curve should be plotstyle=curve – user2478 Nov 20 '18 at 10:57

## 2 Answers

You have to define an area which will then be clipped. The area is build with connecting the first point with the last one. For a line you simply get an area of zero, and from this area nothing can be clipped!

With \psline(0,2)(5,-3)(0,-3) I define a triangle. It is automatically a closed area becasue it draws a line from (0,-3) to (0,2). And from that area the curve with {x*(x-6)+6} is clipping a part which will be filled.

\documentclass[pstricks]{standalone}
\usepackage{pst-plot}
\begin{document}

\begin{pspicture}[algebraic,plotstyle=curve](-2,-6)(6,6)
\psaxes{->}(0,0)(-2,-4)(5.5,4)[$x$,0][$y$,90]
\psclip{\psline[linestyle=none](0,2)(5,-3)(0,-3)}
\psplot[fillstyle=vlines]{.5}{5}{x*(x-6)+6}
\endpsclip
\psplot[linewidth=1.5pt,linecolor=blue]{.5}{5}{x*(x-6)+6}
\psline[linewidth=1.5pt](0,2)(5,-3)
\rput[bl](1.5,1){$y=-x+2$}
\rput[t](2,-3.1){$y=x^2-6x+6$}
\end{pspicture}

\end{document} As an alternative you can calculate the intersectionpoints (needs package pst-intersect) and using \pscustom

%%\usepackage{pst-intersect} in the preamble
\begin{pspicture}[algebraic](-2,-6)(6,6)
\pssavepath[linewidth=1.5pt]{Curve}{\psplot{.5}{5}{x*(x-6)+6}}
\pssavepath[linewidth=1.5pt]{Line}{\psplot{0}{5}{-x+2}}
\psintersect[name=C]{Curve}{Line}
\psaxes{->}(0,0)(-2,-4)(5.5,4)[$x$,0][$y$,90]
\pscustom[fillcolor=red,fillstyle=solid,opacity=0.4]{%
\psplot{\psGetNodeCenter{C1}C1.x}{\psGetNodeCenter{C2}C2.x}{x*(x-6)+6}%
}
\end{pspicture} However, that one with pst-intersect works not with xelatex

# Generic Template

Proposed features:

• functions are defined globally so you can change easily.
• intersection points are calculated at "runtime" as opposed to statically hard coded.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-eucl,pst-plot}

\def\f(#1){((#1)^2-6*(#1)+6)}
\def\g(#1){(2-(#1))}

\begin{document}
\begin{pspicture}[algebraic,saveNodeCoors,PointSymbol=none,PointName=none](-1,-3.5)(6,4)
\psaxes{->}(0,0)(-.5,-3.5)(5.5,3.5)[$x$,0][$y$,90]
\pstInterFF{\f(x)}{\g(x)}{0}{A}
\pstInterFF{\f(x)}{\g(x)}{5}{B}
\pscustom*[linecolor=yellow!50]{%
\psplot{N-A.x}{N-B.x}{\f(x)}
\psplot{N-B.x}{N-A.x}{\g(x)}
\closepath
}
\psset{linewidth=2pt,linecolor=cyan}
\psplot{.5}{5}{\f(x)}
\psplot{-.5}{5}{\g(x)}
\uput[-90](*5 {\g(x)}){$y=-x+2$}
\uput(*.7 {\f(x)}){$y=x^2-6x+6$}
\end{pspicture}
\end{document} # Statically hard-coded Version

Cons: you have to calculate the intersection points in advance by hands.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}

\def\f{x^2-6*x+6}
\def\g{2-x}

\begin{document}
\begin{pspicture}[algebraic](-1,-3.5)(6,4)
\psaxes{->}(0,0)(-.5,-3.5)(5.5,3.5)[$x$,0][$y$,90]
\pscustom[fillstyle=vlines,hatchcolor=red,hatchsep=0.8pt]{\psplot{1}{4}{\f}\psplot{4}{1}{\g}}
\psset{linewidth=2pt,linecolor=blue}
\psplot{.5}{5}{\f}
\psplot{-.5}{5}{\g}
\uput[-90](*5 {\g}){$y=-x+2$}
\uput(*.7 {\f}){$y=x^2-6x+6$}
\end{pspicture}
\end{document} • So happy, now I understand your code perfectly. :-) ; :-) ; :-).... – Trong Vuong Feb 7 at 9:58