74 lines
2.0 KiB
Python
74 lines
2.0 KiB
Python
import numpy as np
|
|
from mpl_toolkits.mplot3d import Axes3D
|
|
import matplotlib.pyplot as plt
|
|
from spectro import LightWaveVec, LightDir, diffracted_light
|
|
from math import pi, acos, cos, sqrt
|
|
|
|
from color import wavelength_to_rgb
|
|
|
|
wavelen_min_nm = 380
|
|
wavelen_max_nm = 750
|
|
wavelen_step_nm = 1
|
|
"""
|
|
wavelens = [404.66e-9, 435.83e-9, 546.07e-9, 576.96e-9, 579.00e-9]
|
|
"""
|
|
wavelens = []
|
|
for i in range(wavelen_min_nm, wavelen_max_nm, wavelen_step_nm):
|
|
wavelens.append(i * 10**-9)
|
|
|
|
|
|
beta_i = pi/2
|
|
gamma_i = pi/2
|
|
grating_c = 1400 * 10**-9
|
|
cos_alpha_i = sqrt(1 - cos(beta_i)**2 - cos(gamma_i)**2)
|
|
alpha_i = acos(cos_alpha_i)
|
|
diffraction_orders = [2, 3]
|
|
|
|
colorlist = []
|
|
|
|
sorrow_light = []
|
|
|
|
for wavelen in wavelens:
|
|
light_i = LightWaveVec(pi * 2 / wavelen,
|
|
LightDir(alpha_i, beta_i, gamma_i))
|
|
|
|
"""
|
|
"""
|
|
colorlist.append((0, 0, 0))
|
|
sorrow_light.append([
|
|
-cos_alpha_i,
|
|
-cos(beta_i),
|
|
-cos(gamma_i),
|
|
cos_alpha_i,
|
|
cos(beta_i),
|
|
cos(gamma_i),
|
|
])
|
|
for m in diffraction_orders:
|
|
light_r_list = diffracted_light(light_i, m, grating_c)
|
|
if (len(light_r_list) == 2):
|
|
print("FOUND 2 SOLUTIONS WHEN m IS ", m, " WAVELEN IS ", wavelen)
|
|
elif (len(light_r_list) == 0):
|
|
print("FOUND NO SOLUTION WHEN m IS ", m, " WAVELEN IS ", wavelen)
|
|
for light_r in light_r_list:
|
|
|
|
colorlist.append(wavelength_to_rgb(wavelen))
|
|
sorrow_light .append([0, 0, 0,
|
|
cos(light_r.direction.alpha),
|
|
cos(light_r.direction.beta),
|
|
cos(light_r.direction.gamma),
|
|
])
|
|
|
|
X, Y, Z, U, V, W = zip(*sorrow_light)
|
|
|
|
fig = plt.figure()
|
|
ax = fig.add_subplot(111, projection="3d")
|
|
ax.quiver(X, Y, Z, U, V, W, colors=colorlist, arrow_length_ratio=0)
|
|
|
|
ax.set_xlim([-1, 0])
|
|
ax.set_ylim([-1, 1])
|
|
ax.set_zlim([-1, 1])
|
|
ax.set_xlabel('X Label')
|
|
ax.set_ylabel('Y Label')
|
|
ax.set_zlabel('Z Label')
|
|
plt.show()
|