From c8d27e6352b472a6160a6070d95cd8a6f01d13f6 Mon Sep 17 00:00:00 2001 From: Roy Smart Date: Sun, 23 Feb 2025 09:35:26 -0700 Subject: [PATCH 1/2] Fixed a bug in the child classes of `optika.rulings.AbstractRulings` where the optical path difference was not being calculated correctly. --- optika/rulings/_rulings.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/optika/rulings/_rulings.py b/optika/rulings/_rulings.py index f177102..0727fa5 100644 --- a/optika/rulings/_rulings.py +++ b/optika/rulings/_rulings.py @@ -593,8 +593,13 @@ def efficiency( grating, :math:`\lambda` is the free-space wavelength of the incident light, and :math:`\theta` is the angle of incidence inside the medium. """ + i = self.diffraction_order + d = self.depth - normal_rulings = self.spacing_(rays.position, normal).normalized + spacing = self.spacing_(rays.position, normal) + + L = spacing.length + normal_rulings = spacing.normalized parallel_rulings = normal.cross(normal_rulings).normalized @@ -603,11 +608,12 @@ def efficiency( wavelength = rays.wavelength cos_theta = -direction @ normal - amplitude = np.pi / 2 - d = self.depth / amplitude - i = self.diffraction_order + sin_theta = np.sin(np.arccos(cos_theta)) + sin_beta = i * wavelength / L - sin_theta + cos_beta = np.cos(np.arcsin(sin_beta)) + n1 = (1 / cos_theta + 1 / cos_beta) / np.pi - gamma = np.pi * d / (wavelength * cos_theta) + gamma = np.pi * d * n1 / (wavelength * cos_theta) result = np.square(np.sin(np.pi * gamma * u.rad) / (np.pi * (gamma + i))) From 25d407324347957c291db3175baf6cbf37e8181e Mon Sep 17 00:00:00 2001 From: Roy Smart Date: Mon, 24 Feb 2025 10:57:36 -0700 Subject: [PATCH 2/2] idk what I'm doing --- optika/rulings/_rulings.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/optika/rulings/_rulings.py b/optika/rulings/_rulings.py index 0727fa5..e57d344 100644 --- a/optika/rulings/_rulings.py +++ b/optika/rulings/_rulings.py @@ -606,14 +606,30 @@ def efficiency( direction = rays.direction direction = direction - direction @ parallel_rulings + amplitude = np.pi / 2 wavelength = rays.wavelength - cos_theta = -direction @ normal - sin_theta = np.sin(np.arccos(cos_theta)) - sin_beta = i * wavelength / L - sin_theta - cos_beta = np.cos(np.arcsin(sin_beta)) - n1 = (1 / cos_theta + 1 / cos_beta) / np.pi + cos_alpha = -direction @ normal + # alpha = np.arccos(cos_alpha) + # print(f"{alpha.to(u.deg)=}") + # sin_theta = np.sin(alpha) + # sin_beta = i * wavelength / L - sin_theta + # beta = np.arcsin(sin_beta) + # print(f"{beta.to(u.deg)=}") + # cos_beta = np.cos(beta) + # n1 = (1 + cos_beta) / (np.pi) + n1 = 1 / amplitude + + cos_theta = optika.materials.snells_law_scalar( + cos_incidence=cos_alpha, + index_refraction=rays.index_refraction, + index_refraction_new=rays.index_refraction + n1, + ) + # cos_theta = cos_alpha + + print(f"{cos_theta=}") gamma = np.pi * d * n1 / (wavelength * cos_theta) + print(f"{gamma=}") result = np.square(np.sin(np.pi * gamma * u.rad) / (np.pi * (gamma + i)))