绘制光门装置

绘制光门装置

有没有办法改进 PhotoGate 设备的示意图?这些仪器在物理学中被广泛使用,因此获得良好的示意图将会很有趣。

我想要寻求一个 Tikz 解决方案,并且如果可能的话,改善艺术眼光。

我的第一个代码:

\startMPcode
path left_cell, right_cell, p, ball, texas;
numeric u,v;
u := 1cm; v:=.5cm;
picture photogate, photogate_inactive;

photogate := image (
texas := unitsquare xscaled 2v yscaled 2u shifted(4u,v);
ball := fullcircle scaled 1.5cm;
left_cell := unitsquare xscaled v yscaled u;
right_cell := left_cell shifted (2.5u, .5v);
p := (center left_cell) -- (center right_cell);
draw left_cell;
draw right_cell;
draw p dashed evenly withcolor red;
draw texas;
draw urcorner left_cell .. urcorner left_cell + (0,2v) .. urcorner right_cell + (0,1.5v) .. center texas;
draw urcorner right_cell .. center texas + (0,-.1u);
fill ball shifted (center  p + (0,3v)) withcolor red;
draw ball shifted (center  p + (0,3v));
);

photogate_inactive := image (
texas := unitsquare xscaled 2v yscaled 2u shifted(4u,v);
ball := fullcircle scaled 1.5cm;
left_cell := unitsquare xscaled v yscaled u;
right_cell := left_cell shifted (2.5u, .5v);
p := (center left_cell) -- (center right_cell);
draw left_cell;
draw right_cell;
%draw p dashed evenly withcolor red;
fill ball shifted center  p withcolor red;
draw ball shifted (center  p);
draw texas;
draw urcorner left_cell .. urcorner left_cell + (0,2v) .. urcorner right_cell + (0,1.5v) .. center texas;
draw urcorner right_cell .. center texas + (0,-.1u);
);


draw photogate;
draw photogate_inactive shifted (7cm , 0);
\stopMPcode

在此处输入图片描述

更新(根据瑟斯顿的建议)

我的新代码:

\startMPcode
numeric u,v;
u := 1cm; v:=.5cm;

vardef photogate_base (expr ative) =
path left_cell, right_cell, p, ball, texas;
texas := unitsquare xscaled 2v yscaled 2u shifted(4u,v);
ball := fullcircle scaled 1.5cm;
left_cell := unitsquare xscaled v yscaled u;
right_cell := left_cell shifted (2.5u, .5v);
p := (center left_cell) -- (center right_cell);

image 
(
 draw left_cell;
 draw right_cell;
 draw urcorner left_cell .. urcorner left_cell + (-1u,3v) .. urcorner right_cell + (0,2v) .. center texas + (0,.6u) cutafter texas;
 draw urcorner right_cell .. urcorner right_cell + (0,.001v) .. center texas cutafter texas;
if ative == 1:
 draw ball shifted (center  p + (0,2.5v));
 fill ball shifted (center  p + (0,2.5v)) withcolor red;
 draw p dashed evenly withcolor red;
else:
 fill ball shifted (center  p + (0,.5v)) withcolor red;
 draw ball shifted (center  p + (0,.5v));
fi;
 draw texas;)
enddef;


draw photogate_base(1);
draw photogate_base(0) shifted (7cm , 0);
\stopMPcode

相关内容