diff --git a/optika/rulings/_rulings.py b/optika/rulings/_rulings.py index f1771026..e57d344a 100644 --- a/optika/rulings/_rulings.py +++ b/optika/rulings/_rulings.py @@ -593,21 +593,43 @@ 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 direction = rays.direction direction = direction - direction @ parallel_rulings - wavelength = rays.wavelength - cos_theta = -direction @ normal amplitude = np.pi / 2 - d = self.depth / amplitude - i = self.diffraction_order + wavelength = rays.wavelength + 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 - gamma = np.pi * d / (wavelength * cos_theta) + 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)))