forked from LennyJove/optic_simulation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspherewave_3D.py
More file actions
74 lines (64 loc) · 2.28 KB
/
spherewave_3D.py
File metadata and controls
74 lines (64 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
matplotlib.rcParams['axes.unicode_minus'] = False
# 设置波长
wavelength = 0.5 # 单位:微米
# 计算波数
k = 2 * np.pi / wavelength
# 创建网格
x = np.linspace(-4 * wavelength, 4 * wavelength, 400)
y = np.linspace(-4 * wavelength, 4 * wavelength, 400)
X, Y = np.meshgrid(x, y)
# 设置源点位置(位于网格中心)
xc, yc = 0 * wavelength, 0 * wavelength
# 计算球面波
R = np.sqrt((X - xc) ** 2 + (Y - yc) ** 2)
A = 1.0 / R # 球面波的振幅随距离增加而减小
P = np.exp(1j * k * R) # 球面波的相位随距离增加而变化
U = A * P # 复振幅
# 计算强度和相位
intensity = np.abs(U) ** 2
phase = np.angle(U)
# 创建三维图形
fig = plt.figure(figsize=(18, 12))
# 绘制复振幅的实部
ax1 = fig.add_subplot(221, projection='3d')
surf1 = ax1.plot_surface(X, Y, np.real(U), cmap='viridis', alpha=0.7)
fig.colorbar(surf1, ax=ax1, label='Real(U)')
ax1.set_title('复振幅的实部')
ax1.set_xlabel('x/um')
ax1.set_ylabel('y/um')
ax1.set_zlabel('Real(U)')
ax1.view_init(elev=30, azim=45)
# 绘制复振幅的虚部
ax2 = fig.add_subplot(222, projection='3d')
surf2 = ax2.plot_surface(X, Y, np.imag(U), cmap='viridis', alpha=0.7)
fig.colorbar(surf2, ax=ax2, label='Imag(U)')
ax2.set_title('复振幅的虚部')
ax2.set_xlabel('x/um')
ax2.set_ylabel('y/um')
ax2.set_zlabel('Imag(U)')
ax2.view_init(elev=30, azim=45)
# 绘制强度图(对数尺度)
ax3 = fig.add_subplot(223, projection='3d')
surf3 = ax3.plot_surface(X, Y, np.log(intensity), cmap='viridis', alpha=0.7)
fig.colorbar(surf3, ax=ax3, label='Intensity (log scale)')
ax3.set_title('强度(对数尺度)')
ax3.set_xlabel('x/um')
ax3.set_ylabel('y/um')
ax3.set_zlabel('Intensity (log scale)')
ax3.view_init(elev=30, azim=45)
# 绘制相位图
ax4 = fig.add_subplot(224, projection='3d')
surf4 = ax4.plot_surface(X, Y, phase, cmap='hsv', alpha=0.7)
fig.colorbar(surf4, ax=ax4, label='Phase (radians)')
ax4.set_title('相位')
ax4.set_xlabel('x/um')
ax4.set_ylabel('y/um')
ax4.set_zlabel('Phase (radians)')
ax4.view_init(elev=30, azim=45)
plt.tight_layout()
plt.show()