\defPStricks / pst-solides3d / 中的函数

\defPStricks / pst-solides3d / 中的函数

我正在阅读 pst-solides3d 文档,并尝试理解生成所附图像的以下代码。很难理解 \defFunction 的工作原理,以及 {t cos 3 mul} 或 {F} CourbeR2+ 等语法的含义。我在哪里可以找到这些?PStricks 文档?

我标记了下面回答了所有这些问题的答案。下面的一个回复提到渐近线对于 3D 矢量图形来说可能是更好的选择!

 \psset{unit=0.5}
 \psset{lightsrc=viewpoint,viewpoint=50 60 25 rtp2xyz,Decran=50}
 \begin{pspicture}(-9,-4)(4,8)
 \defFunction{F}(t){t cos 3 mul}{t sin 3 mul}{}
 \defFunction{G}(t){t cos}{t sin}{}
 \psSolid[object=grille,base=-6 6 -4 4,action=draw]%
 \psSolid[object=prisme,
 h=8,fillcolor=yellow,
 RotX=90,ngrid=8 18,
 base=0 180 {F} CourbeR2+
 180 0 {G} CourbeR2+](0,4,0)
\axesIIID(3,4,3)(8,6,7)
 \end{pspicture}

上述代码的结果

答案1

怎么\defFunction運作?

在你使用它的形式中,它需要 5 个强制参数来指定三维函数的参数化版本。更具体地说,

\defFunction{<name>}(<var>){<x>}{<y>}{<z>}

定义一个函数<name>,它在 X 方向上根据 而变化<x>,在 Y 方向上根据 而变化<y>,在 Z 方向上根据 而变化<z>。所有三个函数都可以根据<var>iable 来定义。因此,

\defFunction{F}(t){t cos 3 mul}{t sin 3 mul}{}

定义 F(x(t), y(t)),其中 x(t) = 3 cos(t) 和 y(t) = 3 sin(t)(未指定 z(t))。


{t cos 3 mul}或等语法的含义是什么{F} CourbeR2+

该语法称为逆波兰表示法(RPN)本质上,运算符跟在操作数后面。因此,3 + 4 的代数用法在 RPN 中重写为 3 4 +,其中运算符 (+) 跟在操作数(3 和 4)后面。进一步解释通过例子。以下是XKCD 解释

在此处输入图片描述

“在 20 世纪 70 年代和 80 年代,惠普公司在其所有台式和手持计算器中都使用了 RPN。在计算机科学中,逆波兰表示法用于面向堆栈的编程语言,例如 Forth 和 PostScript。”pstricks通常使用 PostScript\special命令,甚至可以插入任意的 PostScript 代码(\psverb例如,参见),因此它使用 RPN 是自然而然的。

通过可选方法可以实现更直观的表示[algebraic]


选项

base = 0 180 {F} CourbeR2+
       180 0 {G} CourbeR2+

\psSolid函数的 t 范围指定F0(t-min) 至180(t-max)(度),并将 的范围指定G180(t-min) 至0(t-max),之后CourbeR2+在两个实例中调用该函数。事实上,CourbeR2+需要 3 个参数,在 RPN 中有以下语法

tmin tmax {X} CourbeR2+

答案2

与代数符号相同,可以与一起使用\defFunction[algebraic]

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

\psset{unit=0.5,lightsrc=viewpoint,viewpoint=50 60 25 rtp2xyz,Decran=50}
\begin{pspicture}(-9,-4)(4,8)
\psSolid[object=grille,base=-6 6 -4 4,action=draw]%
\defFunction[algebraic]{F}(t){3*cos(t)}{3*sin(t)}{}
\defFunction[algebraic]{G}(t){cos(t)}{sin(t)}{}
\psSolid[object=prisme,h=8,fillcolor=yellow,RotX=90,ngrid=8 18,
      base=0 Pi {F} CourbeR2+ Pi 0 {G} CourbeR2+](0,4,0)
\axesIIID(3,4,3)(8,6,7)
\end{pspicture} 

\end{document}

\defFunction有一个可选参数和 5 个必选参数:名称、变量和 x、y、z 的三个定义。CourbeR2+是一个内部 PostScript 函数,它运行给定函数:0 Pi {F} CourbeR2+在二维系统中运行 F(t),其中 tmin=0 和 tmax=Pi。

在此处输入图片描述

答案3

这里有一种用更普通的符号来输入的方法。这\typeout只是为了确认原始函数被重现。“RPN”是否真的代表“逆波兰符号”,我不知道,我总是想法这是一个糟糕的笑话,但我不确定(似乎不要开玩笑)。

\documentclass{standalone}
\usepackage{pst-solides3d,infix-RPN}
\begin{document}
 \psset{unit=0.5}
 \psset{lightsrc=viewpoint,viewpoint=50 60 25 rtp2xyz,Decran=50}
 \begin{pspicture}(-9,-4)(9,8)
 \infixtoRPN{cos(t)*3}%
 \edef\RPNone{\RPN}
 \infixtoRPN{sin(t)*3}%
 \edef\RPNtwo{\RPN}
 \typeout{\RPNone,\RPNtwo}
 \defFunction{F}(t){\RPNone}{\RPNtwo}{}
 \defFunction{G}(t){t cos}{t sin}{}
 \psSolid[object=grille,base=-6 6 -4 4,action=draw]%
 \psSolid[object=prisme,
 h=8,fillcolor=yellow,
 RotX=90,ngrid=8 18,
 base=0 180 {F} CourbeR2+
 180 0 {G} CourbeR2+](0,4,0)
\axesIIID(3,4,3)(8,6,7)
 \end{pspicture}
\end{document}

当然,输出和你的例子一样。

至于你在评论中提出的问题:你可以学习法语,也可以在手册中查找这些内容。我很遗憾地告诉你,尽管我使用 pstricks 近 20 年,并且真的很喜欢它,但我几乎完全忘记了所有这些东西,因为我换成了 tikz。这并不是试图改变你,但我想问你以下代码:

\documentclass[tikz,3.14mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{calc,shadings}
\begin{document}
\tdplotsetmaincoords{60}{150}
\begin{tikzpicture}[tdplot_main_coords]
\draw[thick,fill=yellow,fill opacity=0.6] (3,-3,0) 
 -- (1,-3,0)  plot[variable=\x,domain=0:180] ({1*cos(\x)},-3,{1*sin(\x)})
 -- (-3,-3,0) plot[variable=\x,domain=180:0] ({3*cos(\x)},-3,{3*sin(\x)})
;
\draw[very thick,-latex] (0,0,0) -- (9,0,0) node[pos=1.1] {$x$};
\draw[very thick,-latex] (0,0,0) -- (0,6,0) node[pos=1.1] {$y$};
\draw[very thick,-latex] (0,0,0) -- (0,0,6) node[pos=1.1] {$z$};
\foreach \X in {-6,...,5}
{\foreach \Y in {-3,...,2}
{\draw[thick] (\X,\Y) -- (\X+1,\Y) -- (\X+1,\Y+1) -- (\X,\Y+1) -- cycle;}
}
\draw[thick,fill=yellow,fill opacity=0.6] (3,3,0) 
 -- (1,3,0)  plot[variable=\x,domain=0:180] ({1*cos(\x)},3,{1*sin(\x)})
 -- (-3,3,0) plot[variable=\x,domain=180:0] ({3*cos(\x)},3,{3*sin(\x)})
;
\pgfmathsetmacro{\xmax}{180}
\draw[thick] (3,3,0) --
(3,-3,0) -- plot[variable=\x,domain=0:\xmax,smooth] ({3*cos(\x)},-3,{3*sin(\x)}) -- 
({3*cos(\xmax)},3,{3*sin(\xmax)}) -- 
plot[variable=\x,domain=\xmax:0,smooth] ({3*cos(\x)},3,{3*sin(\x)});
\pgfmathsetmacro{\xmax}{135}
\shade let \p1=($(3,3,0)-(3,-3,0)$),\n1={atan2(\y1,\x1)} in 
[right color=yellow,left color=yellow!30!black,opacity=0.8,shading angle=\n1]
(3,3,0) --
(3,-3,0) -- plot[variable=\x,domain=0:\xmax,smooth] ({3*cos(\x)},-3,{3*sin(\x)}) -- 
({3*cos(\xmax)},3,{3*sin(\xmax)}) -- 
plot[variable=\x,domain=\xmax:0,smooth] ({3*cos(\x)},3,{3*sin(\x)}) --cycle;
\draw[very thick,-latex] (0,0,3) -- (0,0,6);
\end{tikzpicture}
\end{document}

在此处输入图片描述

我敢打赌你的反应会是:天哪,这看起来太复杂了。从表面上看,是的,但原因是我根本没有使用任何预定义的宏,我要么需要学习一门新语言,要么翻阅手册,你只需要一些基本的东西,然后开始绘画。(我还应该补充一点,这个例子并不好,因为 pstricks 的 3d 引擎比 Ti 更好Z,它没有,但是如果你想要真正的 3d 而不是假的 3d,你可以使用渐近线。)所以再次抱歉不能更好地解释这些事情,我忘记了很多事情,并且在使用 pstricks 时也不知道很多事情。

答案4

在计算时,Postscript 使用逆波兰表示法 ( RPN),又称postfix符号,它不需要括号。

t cos意思是 cos(t)t cos 3 mul前面的结果乘以 3,即3cos(t)

注意pt-solides3d 理解algebraic的选项pst-plot

相关内容