客观的
我想在笛卡尔坐标系中绘制一个满足一组不等式的区域。如何以最简单的方式做到这一点?
最少代码
\documentclass{minimal}
\usepackage{pstricks-add,amsmath}
\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}
编辑1
实际上我可以通过找到“关键”点来做到这一点手动并将它们用作 的参数\psline
。将线条放入\pscustom
并设置填充颜色。完成。
但如果有更有效的方法,请告诉我。
答案1
我知道了,你想剪切该区域。这很简单:
\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}
剪辑默认进行中间点的计算。
答案2
对于更复杂的情况,我们必须首先找到交点,如下所示。
\documentclass[border=12pt,pstricks]{standalone}
\usepackage{pstricks-add,pst-eucl,graphicx}
\def\f#1{#1 1 add}
\def\g#1{#1 neg 3 div 2 add}
\def\h#1{#1 neg 3 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}
最新更新
为了您的方便,使用中缀表示法。
\documentclass[border=12pt,pstricks]{standalone}
\usepackage{pstricks-add,pst-eucl,graphicx}
\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}