# \[ANN\] FresnelEquations.jl

**URL:** https://discourse.julialang.org/t/ann-fresnelequations-jl/98693
**Category:** Package Announcements
**Tags:** optics
**Created:** [May 11, 2023, 5:06pm UTC](https://discourse.julialang.org/t/ann-fresnelequations-jl/98693 "2023-05-11T17:06:17Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![TheLateKronos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thelatekronos/32/12824_2.png) [@TheLateKronos](https://discourse.julialang.org/u/TheLateKronos)
#### Post date: [May 11, 2023, 5:06pm UTC](https://discourse.julialang.org/t/ann-fresnelequations-jl/98693/1 "2023-05-11T17:06:17Z")

</div>

I am pleased to announce another minor package of mine that [should](https://github.com/JuliaRegistries/General/pull/83307) hit the general registry in a couple of days:

# [🎉 FresnelEquations.jl 🎉](https://github.com/KronosTheLate/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](https://en.wikipedia.org/wiki/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](https://github.com/KronosTheLate/FresnelEquations.jl/issues/new)! Notes on API improvements are of course also welcome.

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [May 11, 2023, 5:20pm UTC](https://discourse.julialang.org/t/ann-fresnelequations-jl/98693/2 "2023-05-11T17:20:32Z")

</div>

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.

```julia
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).

---

<div class="post-metadata">

### Author: ![TheLateKronos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thelatekronos/32/12824_2.png) [@TheLateKronos](https://discourse.julialang.org/u/TheLateKronos)
#### Post date: [May 11, 2023, 5:54pm UTC](https://discourse.julialang.org/t/ann-fresnelequations-jl/98693/3 "2023-05-11T17:54:03Z")

</div>

To not clutter the announcement with technical detail, I have continued the discussion in [FresnelEquations.jl’s first issue](https://github.com/KronosTheLate/FresnelEquations.jl/issues/1). Thanks for your inputs!
