答案1
第三版。我尝试编写更简洁的代码。唯一的问题是圆角磁铁。我的方法在这种情况下不正确。使用平面图的工作很有趣,但最好以 2D 形式绘制磁铁,这样更容易填充磁铁。“正面”和“背面”很容易用圆角绘制,但侧面非常无聊。我当然可以改进下一个代码。
\documentclass[]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{arrows,3d,calc,intersections}
\begin{document}
\begin{tikzpicture}[x = {(-0.65cm,-0.45cm)},
y = {(0.65cm,-0.45cm)},
z = {(0cm,0.8cm)},
scale = 2,
color = {lightgray}]
% style of faces
\tikzset{facestyle/.style={shade,line join=round,
bottom color=darkgray!60,
top color=lightgray}}
\path (1.5,1.5,2) coordinate (c);
\path[facestyle] (0,0,2) -- (0,2,2) --(2,2,2)--(2,0,2)--cycle ;
% face "left"
\begin{scope}[canvas is zy plane at x=2]
\path[facestyle] (0,0) rectangle (2,2);
\path (0.2,2)
coordinate (f1) -- (0.2,1.4)
coordinate (f2) -- (1,1)
coordinate (f3) -- (2,1)
coordinate (f4) -- (c)--(2,2)
coordinate (f6);
\end{scope}
% face "right"
\begin{scope}[canvas is zx plane at y=2]
\path[facestyle] (0,0) rectangle (2,2);
\path (0.2,2)
coordinate (g1) -- (0.2,1.4)
coordinate (g2) -- (1,1)
coordinate (g3) -- (2,1)
coordinate (g4) -- (c) -- (2,2)
coordinate (g6);
\end{scope}
%<------------------ other faces ------------------------------>
% face "front or left" magnet 2
\begin{scope}[canvas is zy plane at x=-5]
\path[facestyle] (-0.05,-4.5) rectangle (1.95,-2.5);
\end{scope}
% face arriere magnet 1
\begin{scope}[canvas is zx plane at y=0]
\path[facestyle] (5,4) rectangle (7,7);
\draw[black] (6.98, -0.5) -- (6.98, 4);
\end{scope}
% face front magnet 1
\begin{scope}[canvas is zy plane at x=3]
\path[facestyle] (2.5,-4) rectangle (0.5,-2);
\end{scope}
% face sup magnet 1
\begin{scope}
\draw[facestyle]
(1,-3,3.60) -- (1,-1,3.60) -- (4,-1,3.60) -- (4,-3,3.60);
\draw[facestyle]
(-3.5,-3,3.60) -- (-3.5,-1,3.60) -- (-7,-1,3.60) -- (-7,-3,3.60) ;
\end{scope}
%<------------------ cutout ------------------------------>
\draw[shade,color=gray,double=lightgray,double distance=1pt]%
(f4) to [in=230,out=-15]
(c) to [in=180 ,out = 80]
(g4) to [in=20,out=190]
(g3) to [in=30,out=190]
(g2) to
(g1) to
(f2) to [in=20,out=100]
(f3) to [in=-160,out=-120]
(f4)
;
%<------------------- hole in the box ------------------------------>
\fill[double=lightgray,double distance=1pt,top color=black!80,shade]%
(0,0,.8) circle [x radius=2mm,y radius=1mm, rotate=15];
%<------------------- source of rays -------------------------------->
\fill[black!80] (1,1,0) circle [x radius=2mm,y radius=1mm, rotate=15];
%<------------------- rays Gamma ---------------------------------->
\begin{scope}[black!60,>=open triangle 45,line width =2]
% ray
\draw (.7,.8,0)--++(0,0,1);
\draw[->] ((.7,.8,1.85)--++(0,0,7) ;
% ray
\draw (.8,.7,0)--++(0,0,1);
\draw[->] (.8,.7,1.85)--++(0,0,8) ;
% ray
\draw (1,1,0)--++(0,0,1.4);
\draw[->] (1,1,1.85)--++(0,0,9) node [above]{Gamma};
\end{scope}
%<------------------- end rays Gamma ------------------------------>
%<------------------- rays Beta ---------------------------------->
\begin{scope}[canvas is xz plane at y=1,black!60,>=open triangle 45,
line width =2,rounded corners]
% ray
\draw (1.1,0) -- ++(0,1.4);
\draw[->,] (1.1,1.95) -- (1.1,6) -- (3,11) ;
% ray
\draw (1.2,0) -- ++(0,1.4);
\draw[->] (1.2,1.95) -- (1.2,6) -- (4,10);
% ray
\draw (1.15,0) -- ++(0,1.4);
\draw[->] (1.15,1.95) -- (1.15,6) -- (3.5,10.5)node [above]{Beta};
%<------------------- End rays Beta ------------------------------>
%<------------------- rays Alpha ------------------------------>
\draw (0.9,0) -- ++(0,1.5)
(0.9,1.8) -- (0.9,6) to (-.5,5.8) coordinate (d);
\draw[->,lightgray] (d) -- (-3,5.5) coordinate (d) ;
\draw (0.8,0) -- ++(0,1.45)
(0.8,1.8) -- (0.8,5.7) to (-.5,5.6) ;
\draw[->,lightgray] (-.5,5.6) -- (-3,5.3);
\draw (0.85,0) -- ++(0,1.45)
(0.85,1.8) -- (0.85,5.5) to (-.5,5.4) ;
\draw[->,lightgray] (-.5,5.4) -- (-2.5,5.2);
\end{scope}
%<--------------------------- face right magnet 2 -------------------->
\begin{scope}[canvas is zx plane at y=2]
\path[facestyle,opacity=.8] (5,-4) rectangle (7,-0.5);
\end{scope}
%<---------------------------rays of magnets ------------------------>
\begin{scope}[canvas is zx plane at y=2]
\path[facestyle] (5,4) rectangle (7,7);
\draw[black] (7, -0.5) -- (7, 4)
(5, -0.5) -- (5, 4)
(6, -0.5) -- (6, 4)
(5.5,-0.5) -- (5.5,4)
(6.5,-0.5) -- (6.5,4)
(7.45,-.05)-- (7.45,4.45)
(7.9,.35) -- (7.9,4.85)
(8.35,0.75) node[above right=1cm]{\textcolor{black!50}{NORTH}}%
-- (8.35,5.25) node[below left=1cm]{\textcolor{black!50}{SOUTH}}
(8.8,1.15) -- (8.8,5.65);
\end{scope}
\node[black,right] at (d) {Alpha};
\end{tikzpicture}
\end{document}
我尝试使用圆角磁铁,但效果并不好,而且有很多近似值