我想在圆环内随机分布“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}