📚 Single Slit Interference Simulation: A Computational Approach | 单缝干涉的计算机模拟方法
In physics, the phenomenon of light passing through a narrow slit and forming a distinctive pattern of bright and dark fringes is a cornerstone of wave optics. For IB Computer Science students, this single slit interference – more precisely single slit diffraction – offers a perfect opportunity to apply computational thinking, numerical methods, and visualisation techniques. This article walks through the process of simulating a single slit diffraction pattern from scratch, linking physics concepts with programming practice in a way that aligns with the IB's emphasis on modelling and problem-solving.
在物理学中,光通过一条窄缝并形成明暗相间的独特图样,这是波动光学的基石现象。对于IB计算机科学的学生来说,这种单缝干涉——更准确地说是单缝衍射——提供了一个绝佳的机会来应用计算思维、数值方法和可视化技术。本文将从零开始逐步拆解单缝衍射图样的模拟过程,将物理概念与编程实践结合起来,贴合IB课程对建模与问题解决能力的重视。
1. Understanding Single Slit Interference | 理解单缝干涉现象
When a coherent light source, such as a laser, illuminates a single slit of width a, the light waves emerging from different points within the slit interfere with one another. This self-interference produces a central bright fringe that is twice as wide as the secondary fringes, flanked by alternating dark and bright bands. The pattern is described by the intensity distribution derived from the superposition of Huygens wavelets.
当一束相干光(如激光)照射宽度为 a 的单缝时,从缝内不同点发出的光波会相互干涉。这种自干涉产生一条中央亮纹,其宽度是次级亮纹的两倍,两侧交替分布暗纹和亮纹。该图样可由惠更斯子波叠加得出的强度分布来描述。
2. The Physics Behind the Pattern | 干涉图样背后的物理原理
/λ and λ is the wavelength. The intensity I is then proportional to the square of this term.
关键量是来自于缝中心和边缘的子波之间的相位差。对于相对原始方向的角度 θ,光程差为 (a sin θ)/2。将所有贡献叠加后,振幅正比于 (sin β)/β,其中 β = (π a sin θ)/λ,λ 为波长。强度 I 则正比于该项的平方。
3. Why Simulate with Computer Science? | 为什么用计算机科学进行模拟?
IB Computer Science encourages the creation of computational models to explore scientific problems. Simulating single slit interference allows students to practise iterative algorithms, use trigonometric functions for wave superposition, and generate graphical output. It reinforces abstract concepts like interference by making them visible, and it introduces performance considerations when dealing with large-scale numerical computations.
IB计算机科学鼓励通过创建计算模型来探索科学问题。模拟单缝干涉可以让学生练习迭代算法、使用三角函数进行波的叠加,并生成图形输出。它通过直观可视化的方式强化干涉等抽象概念,同时在处理大规模数值计算时引入性能考量。
4. Setting Up the Coordinate System and Parameters | 建立坐标系与参数
imulation will loop over a range of y values, compute β, and then calculate the intensity.
我们在距离狭缝 D 处定义屏幕。屏幕上的垂直位置 y 与角度 θ 的关系为 tan θ = y/D。对于小角度,可近似 sin θ ≈ tan θ ≈ y/D,从而将 β 简化为 β = (π a y)/(λ D)。模拟将循环遍历一系列 y 值,计算 β,再算出强度。
β = (π a y) / (λ D)
I = I₀ ( sin β / β )²
5. Computing Intensity: The Sinc Function | 计算强度:Sinc函数
-statement in the loop: if abs(β) < 1e-9, set intensity directly to I₀. Otherwise, compute using the formula. The central maximum occurs when all wavelets are in phase, giving maximum constructive interference.
函数 sinc(β) = sin β / β 在信号处理和光学中频繁出现。在我们的模拟中,需要处理 β = 0 处的奇点,此时 sinc(0) = 1。可以在循环中使用 if 语句实现:如果 |β| < 1e-9,直接设强度为 I₀;否则按公式计算。中央极大出现在所有子波同相时,产生最强的相长干涉。
6. Implementing the Simulation in Python | 用Python实现模拟
The Python implementation starts by importing libraries like NumPy for numerical operations and Matplotlib for plotting. A typical code structure initialises parameters (a, λ, D, I₀), defines an array of y positions, computes β array using vectorised operations, and calculates intensity array. The result can be plotted as a line graph of intensity versus position.
Python实现首先导入NumPy进行数值运算和Matplotlib用于绘图。典型的代码结构包括初始化参数(a, λ, D, I₀),定义 y 位置数组,利用向量化运算计算 β 数组,再计算出强度数组。结果可绘制成强度随位置变化的线图。
- Declare slit width a = 0.1 mm, wavelength λ = 632.8 nm, screen distance D = 1.0 m.
- 声明狭缝宽度 a = 0.1 mm,波长 λ = 632.8 nm,屏幕距离 D = 1.0 m。
- Create array y = np.linspace(-0.05, 0.05, 2000) (in metres) to resolve fine fringes.
- 创建数组 y = np.linspace(-0.05, 0.05, 2000)(单位:米)以分辨细小的条纹。
- Compute beta = (np.pi * a * y) / (lambda * D) and intensity using where condition.
- 计算 beta = (np.pi * a * y) / (lambda * D),并使用条件判断计算强度。
7. Visualising the Diffraction Pattern | 可视化衍射图样
Plotting intensity against y reveals the sinc-squared profile. The central peak dominates, with secondary peaks decreasing in height. To create a more physical representation, one can simulate the actual fringe pattern by mapping intensity to a colour scale (e.g., grayscale) and displaying it as a horizontal strip. This reinforces the connection between computed data and observed reality.
绘制强度随 y 变化的曲线图可展现 sinc 平方的轮廓。中央峰占主导地位,次级峰高度依次递减。为了更贴近物理表现,可以将强度映射到灰度色彩上,并以水平条纹的形式显示出来,从而强化计算数据与现实观察之间的联系。
8. Adding Real-world Imperfections | 添加真实世界的不完美因素
Real diffraction patterns are affected by finite source size, non-monochromatic light, and sensor noise. A computational model can incorporate these effects by convolving the ideal intensity with a Gaussian spread to simulate blurring, and adding random noise to each pixel. Such additions teach students about approximation, error handling, and the limitations of idealised models.
真实的衍射图样会受有限光源尺寸、非单色光以及传感器噪声的影响。计算模型可以通过将理想强度与高斯分布卷积来模拟模糊,并为每个像素添加随机噪声来体现这些效应。这些处理让学生了解近似方法、错误处理以及理想化模型的局限性。
Ireal(y) = Iideal(y) ∗ G(y) + ε
其中 G(y) 为高斯核,ε 为随机噪声。
9. Performance Optimisation Techniques | 性能优化技术
When scaling the simulation to higher resolutions or 2D grids, performance becomes critical. Students can explore loop vectorisation in NumPy, use of precomputed lookup tables for trigonometric functions, and parallel processing with multiprocessing. Profiling the code allows identification of bottlenecks, a key skill in computational science.
当将模拟扩展到更高分辨率或二维网格时,性能变得至关重要。学生可以探索NumPy中的循环向量化、使用预计算的三角函数查找表,以及通过多进程进行并行处理。通过分析代码性能找出瓶颈,是计算科学中的一项关键技能。
10. Extending to Two-Dimensional Patterns | 扩展至二维图样
A single slit is essentially a one-dimensional problem, but real-world slits have height as well. A 2D simulation considers the aperture as a rectangular opening and computes the intensity at each point (x, y) on the screen. The intensity becomes the product of two sinc functions: one for each direction. This cross-disciplinary challenge deepens understanding of both optics and nested array manipulations.
单缝本质上是一个一维问题,但现实中的狭缝还有高度。二维模拟将孔径视为矩形开口,计算屏幕上每个点 (x, y) 的强度。强度变为两个方向上 sinc 函数的乘积。这一跨学科挑战既加深了对光学的理解,也强化了嵌套数组操作技能。
I(x,y) = I₀ [sinc(βₓ) × sinc(βᵧ)]²
11. Analysis and Interpretation of Results | 结果分析与解读
h the theoretical formula a sin θ = mλ, with m = ±1, ±2, ... For small angles this gives ymin culated values checks for rounding errors and discretisation artifacts. Discussion can also cover why the central peak is twice as wide.
完成模拟后,学生应验证第一级暗纹的位置是否符合理论公式 a sin θ = mλ,其中 m = ±1, ±2, ... 对于小角度,得到 ymin = mλD / a。将模拟值与计算值进行比较,可排查舍入误差和离散化伪影。还可以讨论为什么中央峰宽是其他亮纹的两倍。
12. Conclusion and Further Exploration | 结论与延伸探索
Simulating single slit interference bridges physics and computer science, offering a rich context for practising algorithms, data visualisation, and performance tuning. IB Computer Science students can extend this project to double-slit interference, diffraction gratings, or even build an interactive web app using JavaScript and Canvas. The key takeaway is that computational modelling transforms abstract wave phenomena into tangible, analysable data.
模拟单缝干涉连接了物理与计算机科学,为练习算法、数据可视化和性能调优提供了丰富的场景。IB计算机科学学生可以将本项目扩展到双缝干涉、衍射光栅,甚至使用JavaScript和Canvas构建交互式网页应用。关键启示在于:计算建模将抽象的波动现象转化为可触摸、可分析的数据。
Published by TutorHao | Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)

或截图后用「扫一扫 → 相册」选择本图