202610202042

This commit is contained in:
starcells committed 2026-10-20 20:42:51 +08:00
1 parent 1d87570a2c
commit bd8f5458bf
2 files changed
+65 -10

No files matched your search

+61 -8
View File
@@ -7,7 +7,7 @@ grating_c = 1600 * 10**-9
arrow_light = []
colorlist = []
light_len = 36
light_len = 30
"""
raw_source_deg = [pi/2, pi*2/3]
@@ -29,19 +29,28 @@ def calc_degs(vec):
return degs
for i in range(-300, 300, 1):
delta_min = -800
delta_max = 1000
# deltas = [-712, -641, -499, -475, -433, -367, -294, -
# 282, -251, -231, -207, -176, -143, -130, -89, -62, 12, 25] # Ne
deltas = [-734, -662, -263, -135, -75, 133, 183, 210, 242, 289,
334, 358, 381, 424, 471, 513, 608, 665, 702, 708, 730] # Ar
# deltas = [48, 63, 265, 775, 880] # Hg
# deltas = range(-600, 600, 1)
for i in deltas:
delta_z = i/100
scattered_source = [
sqrt(1-cos(raw_source_deg[0])**2-cos(raw_source_deg[1])**2)*light_len,
cos(raw_source_deg[0]) * light_len,
cos(raw_source_deg[1]) * light_len + delta_z
cos(raw_source_deg[1]) * light_len
]
scattered_source_deg = calc_degs(scattered_source)
arrow_light.append([
-scattered_source[0],
-scattered_source[1],
-scattered_source[2] + delta_z,
-scattered_source[2]+delta_z,
scattered_source[0],
scattered_source[1],
scattered_source[2],
@@ -62,16 +71,20 @@ for i in range(-300, 300, 1):
])
color = wavelength_to_rgb(
wavelen(scattered_source_deg[2], scattered_target_deg[2], diffraction_order, grating_c))
wavelen(raw_source_deg[1], scattered_target_deg[2], diffraction_order, grating_c))
colorlist.append(color)
colorlist.append(color)
X, Y, Z, U, V, W = zip(*arrow_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)
fig = plt.figure(figsize=(10, 9))
# ================= 1. 上方 3D 图 =================
ax = fig.add_subplot(211, projection="3d")
ax.quiver(X, Y, Z, U, V, W, colors=colorlist,
arrow_length_ratio=0, linewidth=1.5)
ax.set_xlim([-light_len, light_len])
ax.set_ylim([-light_len, light_len])
@@ -79,4 +92,44 @@ ax.set_zlim([-light_len, light_len])
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
# ================= 2. 下方离散光谱图 =================
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
ax_spec = fig.add_subplot(212)
ax_spec.set_title("Spectro")
# 【关键修改】按真实数值从小到大排序
sorted_deltas = sorted(deltas)
# 找到这些真实值在原始 deltas 中的原始索引,用来取对应颜色
# 因为 colorlist 的顺序是和未排序的 deltas 严格对应的
min_d = min(sorted_deltas)
max_d = max(sorted_deltas)
# 把 X 轴的显示范围稍微留点边距
margin = (max_d - min_d) * 0.1 if max_d != min_d else 10
ax_spec.set_xlim(min_d - margin, max_d + margin)
ax_spec.set_ylim(0, 1)
for d in sorted_deltas:
# 找到当前 d 在原始 deltas 里的位置(原始索引)
original_idx = deltas.index(d)
# 根据原始索引 * 2 取出正确的颜色
c = colorlist[original_idx * 2]
# 用真实的 d 值作为 X 坐标画线
ax_spec.axvline(x=d, color=c, linewidth=4)
# 标注文字
ax_spec.text(d, 1.05, str(d), ha='center', va='bottom', fontsize=12)
ax_spec.set_xticks([])
ax_spec.set_yticks([])
ax_spec.set_xlabel("")
ax_spec.set_ylabel("")
plt.tight_layout()
plt.show()
+4 -2
View File
@@ -19,7 +19,7 @@ light_len = 36
grating_c = 1600 * 10**-9
diffraction_orders = [-5, 5, -4, 4, -3, 3, -2, 2, -1, 1]
diffraction_orders = [1]
# Order that rended earlier might be covered by other orders
# So lower order should be placed at the tail
@@ -51,10 +51,12 @@ for dir in dirs:
colorlist.append((0, 0, 0))
arrow_light.append([
dir[0], dir[1], dir[2],
-cos_alpha_i*light_len,
-cos(beta_i)*light_len,
-cos(gamma_i)*light_len,
cos_alpha_i*light_len,
cos(beta_i)*light_len,
cos(gamma_i)*light_len,
])
light_r_list = diffracted_light(light_i, m, grating_c)