Skip to content

Instantly share code, notes, and snippets.

@bngsudheer
Created September 27, 2016 18:51
Show Gist options
  • Save bngsudheer/ea5708965116cafa4f59df40c399ee0c to your computer and use it in GitHub Desktop.
Save bngsudheer/ea5708965116cafa4f59df40c399ee0c to your computer and use it in GitHub Desktop.
od.py
from math import sqrt, sin
import numpy as np
import matplotlib.pyplot as plt
d = 0.8
data = []
x_values = []
theta_values = []
n_values = []
d_values = []
for n in np.arange(1, 4, 0.3):
for theta in range(2, 85, 1):
x = d*sin(theta)*(1 - (sqrt(1-pow(sin(theta), 2))) / (sqrt(pow(n, 2)-pow(sin(theta), 2))))
print 'x=%+.2f when n = %.2f, d=%.2f theta=%d' % (x, n, d, theta)
data.append({'x': x, 'n': n, 'd':d, 'theta': theta})
x_values.append(x)
theta_values.append(theta)
n_values.append(n)
d_values.append(d)
plt.gca().set_color_cycle(['red', 'green', 'blue', 'yellow'])
#plt.plot(x_values, theta_values)
plt.plot(x_values, d_values)
plt.ylabel('d')
plt.xlabel('x')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment