我想使用
\psset{linecolor = blue!\mapDFVtoColor}
而\mapDFVtoColor
定义为
\def\mapDFVtoColor{20 40 add 3.5 div}
下面是一个较长但精简的示例
\documentclass[dvips]{standalone}
\usepackage{pstricks, pstricks-add}
\begin{document}
\begin{pspicture}[showgrid = true](-4.5, -4.5)(4.5, 5)
\def\radius{4\space}
\def\Adeg{68\space}
\def\Bdeg{30\space}
\def\xp{2\space}
\def\yp{1\space}
\def\zp{1\space}
\def\DistanceFromViewer{%
\radius \Bdeg cos \Adeg sin mul mul \xp mul %
\radius \Adeg cos \Bdeg cos mul mul \yp mul add %
\radius \Bdeg sin mul \zp mul add %
\radius dup mul sub abs %
\radius div\space}
\def\MinDist{0\space}
\def\MaxDist{\radius 2 mul\space}
\def\MinColor{40\space}
\def\MaxColor{100\space}
\def\mapDFVtoColor{%
\DistanceFromViewer \MinDist sub %
\MaxColor \MinColor sub mul %
\MaxDist \MinDist sub div %
\MinColor add}
\rput(1, 1){Distance: \psPrintValue{\DistanceFromViewer}}
\rput(1, 0){Map: \psPrintValue{\mapDFVtoColor}}
\psset{linecolor = blue!\mapDFVtoColor}
\end{pspicture}
\end{document}
我的想法是,我想根据与观察者的距离缩放 3D 中某个点的颜色。感谢您的评论。
答案1
以下是我对 egreg 评论的回答:
\documentclass[dvips]{standalone}
\usepackage{pstricks, pstricks-add}
\usepackage{fp}
\begin{document}
\begin{pspicture}[showgrid = true](-4.5, -4.5)(4.5, 5)
\def\radius{4\space}
\def\Adeg{68\space}
\def\Bdeg{30\space}
\def\xp{2\space}
\def\yp{1\space}
\def\zp{1\space}
\def\DistanceFromViewer{%
\radius \Bdeg cos \Adeg sin mul mul \xp mul %
\radius \Adeg cos \Bdeg cos mul mul \yp mul add %
\radius \Bdeg sin mul \zp mul add %
\radius dup mul sub abs %
\radius div\space}
\FPeval{\resultDistanceFromViewer}{%
abs(\radius * cos(\FPpi * \Bdeg / 180) * sin(\FPpi * \Adeg / 180) * \xp + %
\radius * cos(\FPpi * \Adeg / 180) * cos(\FPpi * \Bdeg / 180) * \yp + %
\radius * sin(\FPpi * \Bdeg / 180) * \zp - %
\radius * \radius) / (\radius)}
\def\MinDist{0\space}
\def\MaxDist{\radius 2 mul\space}
\def\MinColor{40\space}
\def\MaxColor{100\space}
\def\mapDFVtoColor{%
\DistanceFromViewer \MinDist sub %
\MaxColor \MinColor sub mul %
\MaxDist \MinDist sub div %
\MinColor add}
\FPeval{\resulmapDFVtoColor}{%
(\resultDistanceFromViewer - \MinDist) * %
(\MaxColor - \MinColor) / (\MaxDist - \MinDist) + \MinColor}
\rput(1, 1){Distance: \psPrintValue{\DistanceFromViewer}}
\rput(1, 0){Map: \psPrintValue{\mapDFVtoColor}}
\rput(1, -1){Distance: \resultDistanceFromViewer}
\rput(1, -2){Map: \resulmapDFVtoColor}
\end{pspicture}
\end{document}
它还显示了您从 postscript 代码和数字运算中获得的结果之间的比较fp
。调用\psset{linecolor = blue!\resulmapDFVtoColor}
也适用于此。