![PSTriks 3D 球体随机分布在圆环内](https://linux22.com/image/457558/PSTriks%203D%20%E7%90%83%E4%BD%93%E9%9A%8F%E6%9C%BA%E5%88%86%E5%B8%83%E5%9C%A8%E5%9C%86%E7%8E%AF%E5%86%85.png)
我想在圆环内随机分布“n”个球体(或球体)。我用来生成圆环的代码如下:
\documentclass[12pt]{standalone}
\usepackage{pstricks}
\usepackage{pst-3dplot}
\pagestyle{empty}
\def\drawCircles{%
\parametricplotThreeD[xPlotpoints=100](0,360)(0,360){%
/k 2 def /k2 4 def
t cos k mul 4 u sin k mul add mul
t sin k mul 4 u sin k mul add mul
u cos k2 mul
}
\parametricplotThreeD[yPlotpoints=100](0,360)(0,360){%
/k 2 def /k2 4 def
u cos k mul 4 t sin k mul add mul
u sin k mul 4 t sin k mul add mul
t cos k2 mul
}
}
\begin{document}
\psset{unit=0.75}
\begin{pspicture}(-28,-8)(28,8)
\psset{Beta=10,Alpha=0,linewidth=0.1pt,linecolor=blue}
\drawCircles
\end{pspicture}
\end{document}
我该如何使用 PSTricks 来实现?谢谢!
答案1
这是一个平行视图中的 3d 对象,没有隐藏线,因此很难看到前后。使用包更有意义pst-solides3d
。它可以处理带有隐藏线的透视图。
\documentclass[12pt,pstricks]{standalone}
\usepackage{pstricks}
\usepackage{pst-3dplot}
\pagestyle{empty}
\def\drawCircles{%
\parametricplotThreeD[xPlotpoints=100](0,360)(0,360){%
/k 2 def /k2 4 def
t cos k mul 4 u sin k mul add mul
t sin k mul 4 u sin k mul add mul
u cos k2 mul
}
\parametricplotThreeD[yPlotpoints=100](0,360)(0,360){%
/k 2 def /k2 4 def
u cos k mul 4 t sin k mul add mul
u sin k mul 4 t sin k mul add mul
t cos k2 mul
}
}
\begin{document}
\psset{unit=0.75}
\begin{pspicture}(-15,-10)(15,10)
\psset{Beta=30,Alpha=0,linewidth=0.1pt,linecolor=blue}
\pstThreeDCoor[xMax=6,yMax=6,zMax=6]
\drawCircles
\pstThreeDSphere(0,8,0){4}
\pstThreeDSphere(8,0,0){4}
\pstThreeDSphere(0,-8,0){4}
\pstThreeDSphere(-8,0,0){4}
\end{pspicture}
\begin{pspicture}(-15,-10)(15,10)
\psset{Beta=30,Alpha=0,linewidth=0.1pt,linecolor=blue}
\pstThreeDCoor[xMax=6,yMax=6,zMax=6]
\pstThreeDSphere(0,8,0){4}
\pstThreeDSphere(8,0,0){4}
\pstThreeDSphere(0,-8,0){4}
\pstThreeDSphere(-8,0,0){4}
\drawCircles
\end{pspicture}
\end{document}
对于随机值(这里只针对 +/- x:
\pstThreeDSphere( rrand rand 17 mod 8 sub, dup \pst@number\psunit\space div dup mul 64 exch sub sqrt,0){4}
\pstThreeDSphere( rand 17 mod 8 sub, dup \pst@number\psunit\space div dup mul 64 exch sub sqrt,0){4}
\pstThreeDSphere( rand 17 mod 8 sub, dup \pst@number\psunit\space div dup mul 64 exch sub sqrt,0){4}
\pstThreeDSphere( rand 17 mod 8 sub, dup \pst@number\psunit\space div dup mul 64 exch sub sqrt,0){4}