Welcome to the Virtual Optics Laboratory! This is an educational project developed with Streamlit that brings together a collection of interactive simulators to study and visualize light diffraction phenomena. The application is designed for students, educators, and physics enthusiasts who wish to explore the Fresnel (near-field) and Fraunhofer (far-field) diffraction regimes in an intuitive and visual way.
Streamlit link: https://virtual-optics-laboratory-plcbvaadq4hdtm6zv75c2h.streamlit.app/
This laboratory contains different tools that allow for the simulation of diffraction patterns for various apertures. Each simulator offers interactive controls to modify key physical parameters such as aperture geometry, light wavelength, and observation distances, enabling a deep understanding of how these elements influence the final result.
The laboratory consists of the following simulators:
- File:
pages/2_Simulador_Difraccion.py
- Allows you to upload any black and white image to be used as an arbitrary aperture.
- Calculates the Fraunhofer diffraction pattern using the Fast Fourier Transform (FFT), which numerically models the physical phenomenon.
- Provides controls to scale, rotate, and invert the aperture, as well as adjust padding to improve the resolution of the resulting pattern.
- File:
pages/1_Simulador_Cruz.py
- Simulates the Fraunhofer diffraction pattern for an asymmetrical cross-shaped aperture.
- Uses the analytical solution derived from the Fourier transform to calculate the intensity with high precision.
- Includes a far-field condition validator to ensure that the chosen parameters are consistent with the Fraunhofer approximation.
- File:
pages/3_Simulador_Rendija_Fresnel.py
- Shows the continuous transition of the diffraction pattern from the Fresnel to the Fraunhofer regime as the distance
D
between the slit and the screen changes. - Graphically compares both patterns for a given distance and calculates the Fresnel Number (NF).
- Includes a heatmap that visualizes the evolution of intensity along the propagation axis.
- File:
pages/4_Simulador_Borde_Fresnel.py
- Focuses specifically on Fresnel diffraction for simple geometries.
- Allows simulating the pattern generated by a semi-infinite edge or by a slit (by enabling a second edge).
- Calculates intensity patterns using the Fresnel integrals from the
SciPy
library.
- Main Framework: Streamlit
- Numerical Calculation: NumPy & SciPy
- Visualization: Matplotlib
- Image Processing: Pillow
To run this laboratory on your local machine, follow these steps:
-
Clone the repository:
git clone [https://github.com/Rypsor/optica.git](https://github.com/Rypsor/optica.git) cd optica
-
Create and activate a virtual environment (recommended):
python -m venv venv # On Windows venv\Scripts\activate # On macOS/Linux source venv/bin/activate
-
Create a
requirements.txt
file with the following content:streamlit numpy scipy matplotlib Pillow
-
Install the dependencies:
pip install -r requirements.txt
-
Run the Streamlit application:
streamlit run app.py
-
Open your web browser and go to the local URL provided by the terminal (usually
http://localhost:8501
).
(You can add screenshots of each simulator here to show what they look like)
Example: Cross Aperture Simulator
Example: Fresnel to Fraunhofer Evolution
This project is licensed under the MIT License. See the LICENSE
file for more details.