PSTricks:使用 pst-3dplot 绘制马蹄形磁铁

PSTricks:使用 pst-3dplot 绘制马蹄形磁铁

我正在尝试使用 PSTricks 用马蹄形磁铁重现图像。我意识到有一个关于这个问题使用 TikZ,但我更喜欢 PSTricks。我想用 PSTricks (pst-3dplot) 绘制类似以下的内容: 屏幕前的小马蹄形磁铁 马蹄形磁铁中的电缆摆动


我查看了该pst-3dplot包以寻求指导。它们有一个\pstThreeDBox用于绘制简单矩形长方体(dt. Quader)的定义。受此启发,并省略了不同坐标视角的情况的许多巧妙定义(coorType=0现在就使用),我最终得到了以下代码:

% Supposed to draw a threeD Horseshoe
\def\pstThreeDHorseshoe{\pst@object{pstThreeDHorseshoe}}
\def\pstThreeDHorseshoe@i(#1,#2,#3){%
  \pst@killglue
  \begingroup
  \addbefore@par{alternative=false,linestyle=\psk@ThreeDplot@visibleLineStyle}%
  \use@keep@par
  \gdef\pst@tempX{#1 }%
  \gdef\pst@tempY{#2 }%
  \gdef\pst@tempZ{#3 }%
  \pstThreeDHorseshoe@ii
}% end pstThreeDHorseshoe@i.
\def\pstThreeDHorseshoe@ii(#1,#2,#3)(#4,#5,#6)(#7,#8,#9){%
  % Top square :
  \pstThreeDSquare(\pst@tempX #1 add,\pst@tempY #2 add,\pst@tempZ #3 add)(#4,#5,#6)(#7,#8,#9)%
  % First left square :
  \pstThreeDSquare(\pst@tempX #4 add,\pst@tempY #5 add,\pst@tempZ #6 add)(#1 .15 mul,#2 .15 mul,#3 .15 mul)(#7,#8,#9)
  % Second left square :
  \pstThreeDSquare(\pst@tempX #4 add #1 .85 mul add,\pst@tempY #5 add #2 .85 mul add,\pst@tempZ #6 add #3 .85 mul add)(#1 .15 mul,#2 .15 mul,#3 .15 mul)(#7,#8,#9)
  % first front bit :
  \pstThreeDSquare(\pst@tempX #7 add,\pst@tempY #8 add,\pst@tempZ #9 add)(#1 .15 mul,#2 .15 mul,#3 .15 mul)(#4,#5,#6)
  % second front bit :
  \pstThreeDSquare(\pst@tempX #7 add #1 .85 mul add,\pst@tempY #8 add #2 .85 mul add,\pst@tempZ #9 add #3 .85 mul add)(#1 .15 mul,#2 .15 mul,#3 .15 mul)(#4,#5,#6)%
  % Inside square one :
  \pstThreeDSquare(\pst@tempX #7 .2 mul add #1 .15 mul add,\pst@tempY #8 .2 mul add #2 .15 mul add,\pst@tempZ #9 .2 mul add #3 .15 mul add)(#4,#5,#6)(#7 .8 mul,#8 .8 mul, #9 .8 mul)%
  \pstThreeDSquare(\pst@tempX #7 .2 mul add #1 .85 mul add,\pst@tempY #8 .2 mul add #2 .85 mul add,\pst@tempZ #9 .2 mul add #3 .85 mul add)(#4,#5,#6)(#7 .8 mul,#8 .8 mul, #9 .8 mul)%
  % Inside square three :
  \pstThreeDSquare(\pst@tempX #7 .2 mul add #1 .15 mul add,\pst@tempY #8 .2 mul add #2 .15 mul add,\pst@tempZ #9 .2 mul add #3 .15 mul add)(#4,#5,#6)(#1 .7 mul,#2 .7 mul,#3 .7 mul)
  % Back square : 
  \pstThreeDSquare(\pst@tempX,\pst@tempY,\pst@tempZ)(#4,#5,#6)(#1,#2,#3)
\endgroup
\ignorespaces
}% end pstThreeDHorseshoe@ii.

并运行

\pstThreeDHorseshoe(0,0,0)(0,0,2)(1.5,0,0)(0,3,0)

使用 pst-3dplot 绘制的马蹄形磁铁的不完整草图


不应显示的行将被删除。为此,有一个参数invisibleLineStyle,但它没有很好的文档记录,只有半页在这本书里。我尝试用该线条样式覆盖一条线,但是无济于事。

我将接受一个答案,该答案展示了如何处理这个参数invisibleLineStyle并帮助我将它与马蹄形的内部结构一起使用。

编辑:请建议一个巧妙的方法来引入 0.15、0.2 的变量,以便以后可以更改尺寸。

答案1

仅限马蹄形磁铁:

\documentclass[]{article}
\pagestyle{empty}
\usepackage{pst-solides3d}

\begin{document}
\begin{pspicture}(-2,-3)(7,8)
    \psset{viewpoint=20 28 15 rtp2xyz,lightsrc=20 60 60 rtp2xyz,Decran=30,solidmemory}
    \psSolid[incolor=red,fillcolor=red,object=parallelepiped,a=2,b=0.75,c=1.5,grid=false,name=H2](0,-0.375,0.75)
    \psSolid[incolor=red,fillcolor=red,object=parallelepiped,a=2,b=4,c=0.5,grid=false,name=H1](0,2,0.25)
    \psSolid[incolor=red,fillcolor=green,object=parallelepiped,a=2,b=0.75,c=1.5,grid=false,name=H3](0,-0.375,2.25)
    \psSolid[incolor=red,fillcolor=green,object=parallelepiped,a=2,b=4,c=0.5,grid=false,name=H4](0,2,2.75)
\end{pspicture}
\end{document}

在此处输入图片描述

完整示例中的图像(链接在评论中)

在此处输入图片描述

相关内容