pst-solides3d:填充绘图下的区域

pst-solides3d:填充绘图下的区域

我该如何填补像下图这样位于 (x^2+y^2)/4 下方的区域?

填充 (x^2+y^2)/4 下的区域

\documentclass{article}

\usepackage{pstricks}
\usepackage{pst-solides3d}
\definecolor{darkred}{RGB}{139,000,000}
\pagestyle{empty}

\begin{document}
\psset{viewpoint=20 40 30 rtp2xyz,Decran=25}
\psset{lightsrc=viewpoint,lightintensity=4}
\psset{unit=0.3}

\centering
\begin{pspicture}(-4,-4)(4,4)
\psSurface[ngrid=.25 .25,
  fillcolor=darkred,incolor=blue!40!white,
  axesboxed,
  Zmin=0,Zmax=8,
  action=draw**,
  linewidth=0.2pt](-4,-4)(4,4){x dup mul y dup mul add 4 div }
\end{pspicture}
\end{document}

答案1

这其实并不容易。你必须定义新的对象,即曲线下的条纹(多边形)。四条边和面(平面):

\documentclass{article}
\usepackage{pst-solides3d}
\definecolor{darkred}{RGB}{180,000,000}

\begin{document}
\begin{center}
\psset{viewpoint=40 30 30 rtp2xyz,Decran=20,lightsrc=viewpoint}

\begin{pspicture}(-4,-3)(4,6)
  \psSurface[ngrid=16 16,hue=0 1,fillcolor=yellow!50,
     axesboxed,algebraic,Zmin=0,Zmax=8,
     action=draw**,linewidth=0.2pt](-4,-4)(4,4){ (x^2+y^2)/4 }
\pstVerb{
  /fct {dup mul 16 add 4 div} def
  /Sommets1 { %  y=4
    4 -0.5 -3.5 {/xi exch def
    xi 4 0 xi 0.5 sub 4 0 xi 0.5 sub dup 4 exch fct
    xi dup 4 exch fct } for } def
  /Faces1 {
    0 4 [Sommets2] length 3 idiv 4 sub { /iF exch def
    [ iF iF 1 add iF 2 add iF 3 add ] } for } def
  /Sommets2 { % x=4
    -4 0.5 3.5 {/yi exch def
       4 yi 0 4 yi 0.5 add 0 4 yi 0.5 add dup fct
       4 yi dup fct } for } def
  /Faces2 {
    0 4 [Sommets2] length 3 idiv 4 sub { /iF exch def
    [ iF iF 1 add iF 2 add iF 3 add ] } for } def
}%
\psSolid[object=new,sommets=Sommets1,faces={Faces1},
    fillcolor=darkred,linewidth=0.2pt]
\psSolid[object=new,sommets=Sommets2,faces={Faces2},
    fillcolor=darkred,linewidth=0.2pt]
\end{pspicture}
\end{center}
\end{document}

在此处输入图片描述

答案2

填充可见空间(即边界曲线下方的区域)就足够了。TeXwelt网站我最近展示了如何回答:我有多少本关于“空间中的情节”的书?

  • 通过固定 x 或 y 值获取边缘曲线
  • 绘制边缘曲线并命名路径
  • 在命名路径和底线之间填充
  • 可选阴影以改善 3D 印象
  • 如果绘图顺序有要求,则使用图层

在此处输入图片描述

使用 pfgplots 完成,以展示另一种方法:

\documentclass[border=15pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{colormaps,fillbetween}
\pgfplotsset{compat=1.10}
\begin{document}
\begin{tikzpicture}
  \pgfdeclarelayer{pre main}
  \pgfsetlayers{pre main,main}
  \begin{axis}[
      hide axis,
      domain = -4:4,
      zmax   = 12,
      colormap/bone
    ]
    \begin{pgfonlayer}{pre main}
      \addplot3 [surf] {(x^2+y^2)/4};
    \end{pgfonlayer}
    \addplot3 [name path = xline, draw = none] (x,-4,0);
    \addplot3 [name path = yline, draw = none] (4,y,0);
    \addplot3 [name path = xcurve, y domain = 0:0, draw = none]
      (x, -4, {(x^2+16)/4});
    \addplot3 [name path = ycurve, y domain = 0:0, draw = none]
      (4, x, {(16+x^2)/4});
    \addplot [left color = black, right color = black!50, draw = none]
      fill between[of = xcurve and xline];
    \addplot [left color = black!50, right color = black, draw = none]
      fill between[of = yline and ycurve, reverse = true];
  \end{axis}
\end{tikzpicture}
\end{document}

相关内容