I struggled a little bit to teach the particle to stop at a collision with a solid object. But now I did it. Above you can see the result. You see 20 particles starting in the area between the tip an the deflectors. The Tip has a Voltage of -100V an the Deflectors 0V. The electrical field in green accelerate the particles. The source code to create image I uploaded to GitHub https://github.com/Chris-deerleg/FEMM-4.2/blob/master/DIY-SEM-G03.lua
https://github.com/Chris-deerleg/FEMM-4.2/blob/master/DIY-SEM-G03.lua
Actually it is no rocked science to calculate a intersection point between 2 lines.
if m of line 1 is different to m of line 2 then the lines have a intersection point. But if you look at the formula for m, you see that if x2 = x1 then occur a division by zero. The 4 different cases to solve this issue are shown in top left corner. The next challenge is to figure out if the intersection point is on both lines. I the image above you see intersection point in gray. But this intersection point is not on both lines. Below the graph you see "nil" "nil" "3" "3". Nil means not on the line. The calculation behind this is just to check if the coordinates of intersection are on the lines.
line 1 x low < x intersection point > line 1 x high and
line 2 x low < x intersection point > line 2 x high and
line 1 y low < y intersection point > line 1 y high and
line 2 y low < y intersection point > line 2 y high
If the statement is ture then is the intersection point on the lines and the particle has to stop.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.