It's implemented with python and matlab, Only the incident and refractive directions on a surface are realized, without considering the amplitude size of the TEM wave
Wiki has page about Snell's law
in this code, it use time 't' to contral the length of line of light, like s+t*v surface has eqution, so light & surface will get the meeting point p and time t0 then build some equtions for transmisson and reflection, solve the vector of transmisson v_t and reflection light v_r
finally plot them all in a figure
Class: Light, Surface will have this attributes, and Math will do something to get right calculating.
This picture will show the Algorithm of Snell's Law. the Core method is lightrun()
as alternative, for transmisson and reflection, we have transmisson2() and reflection2(),transmisson2 works good, reflection2 maybe have bugs, not very reliable .
at last, we will show you some detail of this Algorithm.
- Dont't have metting point :
we get 2 eqautions to solve, if no meeting point, we consider it on first and set t0 = 0, it also has a situation that t0<0 , it means also not hit. so can only judge if t0>0.
for the really hit surface, t0 must be the minimal of list_t0.
- Special case for transmisson:
for run case2 , case3, we use some if command to get transmisson light
- How to judge the reflection index.
we can calculate surface.get_n()*light.get_v() , if >0 , then from n1 to n2, else from n2 t0 n1.
- What's tree looks like in few times refecltion
it has been tested working suitable for Matlab2019b, for 2020a or later, it may have errors in solve(), should change the eqn with vertor type into 3 different linear eqn.
it has a lot of Comments to unterstand the programm
I first done it in Matlab, so python's version is only copy for matlab, I recommand first to see the code in matlab and then in python.
to get the result, should run test_snell.py.
programm has been tested in Win10, Python3.8
have 3 package installed:
- Numpy
- Matplotlib
- Sympy
Test Framework is pytest.
in the test file we do some test to make sure the Algorithm works right, in fact, this test file building after the run file.
test1 is for speicial case that don't hit.
test2 is for vertically hits.
test3 is for total internal reflection TIR.
test4 is for a normal case,
by this 4 tests we can almost make sure that the algorithm are works good, and for more complicated case we can use
Physical().run_plot()
to get a figure to watch.
- case1:
The light and surface is parallel
- case2:
The light hits the Surface vertically
- case3:
Total internal reflection TIR case, in code comments we call it burst, it's a mistake
- case4:
The light source is on the plane, we set it don't do anything
- case5:
no light only a point, we don't see anything
- case6:
we test the Surface().plot in special case , if the plane equation is Ax+By+C=0, we make sure when any of A,B,C=0 can plot on figure.
- case7:
The light hits the Surface vertically almost
- case 8:
We have realized the reflection and refraction(in this demo we call it transmisson) of light in any number of planes, and the number of reflections and refractions is also adjustable
But as you can see, we still get some problem to plot the Surface, it has bugs , we are working on it
- case 9:
We have simulated the route of light in non-transparent media or electromagnetic waves in metal conductors, and we have not considered TEM waves