6

I am attempting to recreate images with horseshoe magnets with PSTricks. I realise there is a question about this with TikZ, but I prefer PSTricks. I would like to draw something like the following with PSTricks (pst-3dplot): small horseshoe magnet in front of a screen cable swing in a horseshoe magnet


I have looked at the pst-3dplot package for guidance. They have a definition of \pstThreeDBox for drawing a simple rectangular cuboid (dt. Quader). Inspired by that and omitting much of the clever definition by cases of different coordinate perspectives (just go with coorType=0 for now) I ended up with this code:

% 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.

and run with

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

incomplete sketch of a horseshoe magnet with pst-3dplot


Lines that are not supposed to be visible are to be removed. To do so there is the parameter invisibleLineStyle, but it is not well documented, just half a page in this book. I have tried overwriting a line with that linestyle, but to no avail.

I will accept an answer that shows how to deal with this parameter invisibleLineStyle and helps me put it in use with the inner structure of the horseshoe shape.

For an edit: Please do suggest a clever way to introduce variables for 0.15, 0.2 so that the dimensions may be changed later.

fborchers
  • 465
  • 2
  • 13

1 Answers1

3

Only the horseshoe magnet:

\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}

enter image description here

The image from the complete example (Link in comment)

enter image description here

user187802
  • 16,850