I am pleased to announce another minor package of mine that should hit the general registry in a couple of days:
After having implemented the rather long and tedious Fresnel equations several times, I found it in order to wrap it up into a package. FresnelEquations.jl defines 8 functions, seen in the overview below:
||Fraction of energy reflected
||Fraction of energy transmitted
||Change in amplitude of E-field upon reflection
||Change in amplitude of E-field upon transmission
The package content is largely taken from the wikipedia article on the Fresnel Equations.
The main concern of this package is correctness and performance, so if you see any room fore improvement, please open up an issue! Notes on API improvements are of course also welcome.
It seems like you implemented every function twice, once for the complex coefficient and once for its absolute value squared. Why not have the latter simply call the former? e.g.
R_s(n₁, n₂, θᵢ, θₜ=_θₜ(n₁, n₂, θᵢ)) = abs2(r_s(n₁, n₂, θᵢ, θₜ))
You also calculate
1 - R_p, which may suffer catastrophic cancellation if the reflectance is close to one. Using
abs2(t_p) via your
t_p function avoids this.
Another problem is that you should support complex angles. For example, if you have a total-internal-reflected ray, the transmitted angle is complex, but it is still perfectly valid, and the complex reflection coefficient is still useful in telling you the reflected phase. You’ll also a complex transmitted “angle” if the transmission medium is lossy (complex index).
To not clutter the announcement with technical detail, I have continued the discussion in FresnelEquations.jl’s first issue. Thanks for your inputs!