Skip to content

Commit

Permalink
Modified optika.materials.snells_law_scalar() to always return a re…
Browse files Browse the repository at this point in the history
…al result. (#46)
  • Loading branch information
byrdie committed Jun 10, 2024
1 parent c8e85d6 commit 3a018c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions optika/materials/_snells_law.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def snells_law_scalar(
index_refraction_new
The index of refraction in the new medium.
"""
index_refraction = np.real(index_refraction)
index_refraction_new = np.real(index_refraction_new)
sin_incidence = np.sqrt(1 - np.square(cos_incidence))
sin_transmitted = index_refraction * sin_incidence / index_refraction_new
cos_transmitted = np.sqrt(1 - np.square(sin_transmitted))
Expand Down
6 changes: 4 additions & 2 deletions optika/materials/_tests/test_snells_law.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
argnames="index_refraction_new",
argvalues=[
1.5,
1.5 + 0.2j,
na.linspace(1, 2, axis="index_refraction_new", num=4),
],
)
Expand All @@ -35,9 +36,10 @@ def test_snells_law_scalar(
index_refraction=index_refraction,
index_refraction_new=index_refraction_new,
)
assert np.all(np.imag(result) == 0)

n1 = index_refraction
n2 = index_refraction_new
n1 = np.real(index_refraction)
n2 = np.real(index_refraction_new)
result_expected = np.cos(np.arcsin(n1 * np.sin(np.arccos(cos_incidence)) / n2))

assert np.allclose(result, result_expected)
Expand Down

0 comments on commit 3a018c0

Please sign in to comment.