# PSTricks: Drawing a Horseshoe Magnet with pst-3dplot

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):

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
\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 :
% First left square :
% Second left square :
% first front bit :
% second front bit :
% Inside square one :
% Inside square three :
% 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)


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.

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}


The image from the complete example (Link in comment)

• I tried to tweak your solution to suit my needs by removing the colors and adding the edges with action=draw. Lots of lines are drawn, but also the lines that should be invisible:( – fborchers Aug 16 '19 at 13:56
• action=draw draws everything! – user187802 Aug 16 '19 at 16:05