A Taichi-based simulation demonstrating diffraction patterns from a grid of circular apertures.
This project simulates diffraction patterns for multiple aperture-grid lattices (square, triangular, and hexagonal). The simulation displays both the aperture mask and the resulting diffraction pattern side-by-side.
- Square grids: 3x3, 4x4, 5x5
- Triangular grids:
- Small triangular: 8 apertures
- Large triangular: 31 apertures
- Hexagonal grids:
- Small hexagonal: 7 apertures (center + 6 neighbors)
- Large hexagonal: 24 apertures
Use the buttons in the left control panel to switch between grid types.
The simulation implements the physical optics calculation for:
- Single aperture diffraction: Uses Bessel functions to compute the Airy disk pattern
- Multi-aperture interference: Calculates phase differences between apertures in the grid
- Far-field approximation: Assumes Fraunhofer diffraction conditions
- Interactive parameters: Real-time adjustment of aperture size, separation, distance, and wavelength
- Visual comparison: Side-by-side display of aperture mask and diffraction pattern
- Color mapping: Diffraction pattern colored according to the incident light wavelength
- High performance: GPU-accelerated computation using Taichi
- Aperture diameter (W): Size of each circular aperture (meters)
- Center-to-center separation (d): Distance between adjacent apertures (meters)
- Distance to screen (z): Propagation distance from apertures to observation plane (meters)
- Wavelength (λ): Wavelength of incident light (meters)
- Screen size: Physical size of the observation area (meters)
Run the simulation:
python main.pyUse the interactive sliders to adjust:
- Distance (1.0 - 40.0 m)
- Aperture size (0.01 - 0.10 mm)
- Separation (0.0 - 0.2 mm)
- Wavelength (400 - 700 nm)
- Bessel function computation: Custom implementation using series expansion and asymptotic approximation (see
physics.py) - Phase calculation: Accounts for geometric path differences between apertures
- Color rendering: Wavelength-to-RGB conversion for visual representation (see
color.py) - Normalization: Intensity scaling for proper display
main.py: Entry point, configuration, Taichi field definitions, kernels, GUI loopphysics.py: Airy/Bessel-related Taichi functionscolor.py: Wavelength to RGB Taichi functiongrids.py: Grid constants (point sets and offsets) and grid title helper
- Taichi: For high-performance GPU computing
(Install via your Python environment manager or
pip install taichi.)
The diffraction pattern combines:
- Airy pattern from individual apertures:
J₁(x)/xenvelope function - Interference pattern from aperture array: Complex amplitude summation
- Phase factor:
(2π/λ) * (aperture_positions · direction) / z
Where J₁ is the first-order Bessel function of the first kind.
