# Objective

I want to draw a region in Cartesian coordinate system that satisfies a set of inequalities. How to do this in the simplest way?

# Minimal Code

\documentclass{minimal}

\begin{document}
\pspicture*[showgrid=false](-1,-4)(3,1)
\pspolygon[fillstyle=solid,fillcolor=red,opacity=0.25,linestyle=none]%
(0,0)(0,-3)(2,0)
\psset{linewidth=0.4pt}
\psaxes[arrows=<->](0,0)(-0.5,-3.5)(2.5,0.5)[$x$,0][$y$,90]
\psplot[algebraic]{-0.25}{2.25}{1.5*x-3}
\psset{linecolor=red,linewidth=1.5pt}
\psline[linestyle=dashed](0,-3)
\psline[linestyle=dashed](2,0)
\psline(2,0)(0,-3)
\rput[tl](1,-1.5){$y=\frac{3}{2}x-3$}
\endpspicture

\end{document}


# Edit 1

Actually I can do this by finding the "critical" points MANUALLY and use them as the parameters for \psline. Put the lines into \pscustom and set the fill color. Done.

But if there is a more efficient approach, please let me know.

I see, you want to clip the area. This is easy:

\documentclass{minimal}
\usepackage{pst-plot}

\begin{document}

\psset{unit=2}
\begin{pspicture}(-1,-4)(3,1)
\psclip{%
\pscustom[linestyle=none]{%
\psline(0,-4)
\psplot[algebraic]{-1}{2.25}{1.5*x-3}
\psline(3,0)(0,0)
}
}
\psframe[fillstyle=vlines,linestyle=none](0,-4)(3,0)
\endpsclip
\psaxes[arrows=<->](0,0)(-0.5,-3.5)(2.5,0.5)[$x$,0][$y$,90]
\psplot[algebraic]{-1}{2.25}{1.5*x-3}
\end{pspicture}

\end{document}


Clipping does the calculation of the intermediate points by default.

• There is no IfTE in pst-plot. – xport Jan 14 '11 at 8:00
• @xport: hm maybe pstricks-add. Cannot really remember – user2478 Jan 14 '11 at 9:19
• @xport: see edited answer – user2478 Jan 14 '11 at 12:33

For a more complicated case, we have to find the intersection points first as follows.

\documentclass[border=12pt,pstricks]{standalone}

\def\g#1{#1 neg 3 div 2 add}

\def\getX#1{\psGetNodeCenter{#1} #1.x}

\begin{document}
\begin{pspicture*}[showgrid](-1,-2)(4,3)
\psset{PointName=none,PointSymbol=none}
\pstInterFF{\f{x}}{\g{x}}{0}{A}%
\pstInterFF{\g{x}}{\h{x}}{0}{B}%
\begin{psclip}{
\pscustom[linestyle=none]{
\psline(!0 \f{0})
\psplot{0}{\getX{A}}{\f{x}}
\psplot{\getX{A}}{\getX{B}}{\g{x}}
\psplot{\getX{B}}{2.5}{\h{x}}
\psline(2.5,0)
\closepath}}
\rput(1.5,0.5){\includegraphics[width=3cm]{example-grid-100x100pt}}
\end{psclip}
\psplot{-1}{4}{\f{x}}
\psplot{-1}{4}{\g{x}}
\psplot{-1}{4}{\h{x}}
\psline(2.5,-2)(2.5,3)
\psaxes[labelFontSize=\scriptscriptstyle]{->}(0,0)(-0.75,-1.75)(3.5,2.5)[$x$,0][$y$,90]
\end{pspicture*}

\end{document}


## Latest update

Using infix notation for the sake of your convenience.

\documentclass[border=12pt,pstricks]{standalone}

\def\f{(x+1)}
\def\g{(-x/3+2)}
\def\h{(-x+3)}
\def\x#1{N-#1.x}

\pstVerb{/I2P {AlgParser cvx exec} def}

\begin{document}
\begin{pspicture*}[algebraic,saveNodeCoors,PointName=none,PointSymbol=none](-1,-2)(4,3)
\pstInterFF{\f I2P}{\g I2P}{0}{A}
\pstInterFF{\g I2P}{\h I2P}{0}{B}
\begin{psclip}{%
\pscustom[linestyle=none]
{
\psline(*0 {\f})
\psplot{0}{\x{A}}{\f}
\psplot{\x{A}}{\x{B}}{\g}
\psplot{\x{B}}{2.5}{\h}
\psline(2.5,0)
\closepath
}}
\rput(1.5,0.5){\includegraphics[width=3cm]{example-grid-100x100pt}}
\end{psclip}
\psplot{-1}{4}{\f}
\psplot{-1}{4}{\g}
\psplot{-1}{4}{\h}
\psline(2.5,-2)(2.5,3)
\psaxes[labelFontSize=\scriptscriptstyle]{->}(0,0)(-0.75,-1.75)(3.5,2.5)[$x$,0][$y$,90]
\end{pspicture*}

\end{document}