I am writing a program to calculate light refraction using snell’s law, however, when I run the program it prints -0.7076118148 rather than the correct value of 22
JavaScript
x
7
1
import numpy as np
2
theta_1 = 30
3
n1 = 1
4
n2 = 1.33
5
theta_2 = np.arcsin(n1 / n2 * np.sin(theta_1))
6
print(theta_2)
7
Advertisement
Answer
You’re using degrees instead of radians.
You’ll have to convert, e.g like this:
JavaScript
1
9
1
import numpy as np
2
theta_1 = 30;
3
n1 = 1
4
n2 = 1.33
5
theta_1_rad = np.radians(theta_1)
6
theta_2_rad = np.arcsin(n1 / n2 * np.sin(theta_1_rad))
7
theta_2 = np.degrees(theta_2_rad)
8
print(theta_2)
9
=> 22.082413194472252