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}

在此輸入影像描述

完整範例中的圖像(評論中的連結)

在此輸入影像描述

相關內容