# [ANN] FresnelEquations.jl

I am pleased to announce another minor package of mine that should hit the general registry in a couple of days:

# FresnelEquations.jl

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:

Function Description Physical meaning
`R_s` and `R_p` Reflectance Fraction of energy reflected
`T_s` and `T_p` Transmittance Fraction of energy transmitted
`r_s` and `r_p` Reflection coefficient Change in amplitude of E-field upon reflection
`t_s` and `t_p` Transmission coefficient 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.

3 Likes

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 `T_p` via `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).

1 Like

To not clutter the announcement with technical detail, I have continued the discussion in FresnelEquations.jl’s first issue. Thanks for your inputs!

1 Like