Introduction to Ray Tracing
1 Learning Objectives
By the end of this lab you will have…
- Set up and understand how to configure optical ray tracing simulations using the Python package RayTracing.
- Perform ray tracing simulations of simple imaging systems and analyze their performance
2 Setup
2.1 Download and Install the RayTracing Package
https://github.com/DCC-Lab/RayTracing
https://raytracing.readthedocs.io/
The first step in this lab is to set up the RayTracing Python package. You may do this using either Spyder on your personal machine or by using a Jupyter notebook either locally or in Google Colaboratory (Colab). In this lab we will use an Jupyter notebook hosted on Google Colab.
To start, open the Colab notebook here and save a copy to your Google Drive. The Jupyter Notebook walks you through the steps necessary to set up and use the RayTracing package to perform a simple simulation. Follow the steps to try it out for yourself and get familiar with the basic interface. You may also find the catalog of examples listed here (accompanying code for easy copy-paste in the GitHub repository here)
3 Analysis of Finite and Infinite Conjugate Optical Systems
3.0.1 Ray Tracing of a Finite Conjugate Optical System
In this section you will perform a simulation of a finite conjugate microscope. This system is composed of two lenses: the microscope objective and the tube lens. The objective forms an intermediate image which is then used by the tube lens to form the final image. This system is called finite conjugate because the intermediate image plane is at a finite distance. This is in contrast to the infinite conjugate system which you will learn more about in the next section.
Set up a new simulation using two lenses with focal lengths of 10 cm (objective lens) and 40 cm (tube lens). Place the object 20 cm in front of the first lens (the objective lens) and separate the lenses by a distance of 70 cm. You may assume that the diameter of the lenses is infinite for this example.
3.0.2 Paper Calculation
First, use basic ray tracing diagrams and calculations to predict the behavior of this system and answer the questions below.
- For the first lens (objective lens) and intermediate image
- Where is the image located?
- Is it real or virtual?
- Upright or inverted?
- What is its magnification?
- For the second lens (tube lens) and final image
- Where is the final image of the imaging system located?
- Is it real or virtual?
- Upright or inverted?
- What is its magnification (with respect to the initial object)?
- Are the rays between the two lenses converging, diverging, or traveling parallel?
3.0.3 Computer Simulation
Next you will simulate the system to confirm your calculations. We will follow steps similar to the tutorial in the Colab notebook.
- Create variables to store the important properties of the system.
obj_h
to store the value of the object.f1
andf2
for the focal lengths of the objectslens_separation
for the distance between the two lensesdiameter
for the diameter of the lenses
- Use the
ObjectRays()
function to create the rays object with a diameter equal to the value specified inobj_h
. You may choose any parameters that you would like for the half angle (halfAngle
), number of rays bundles (H
) and the number of rays per bundle (T
). A good starting point is aroundhalfAngle = 0.05 rad
,H=2
,T=5
. - Create an ImagingPath object and add the lenses to the path.
- Display the imaging path.
Do the results of your ray tracing simulation match your expectations? Why or why not? Upload a screenshot of your ray tracing simulation.
3.0.4 Ray Tracing Analysis of an Infinite Conjugate System
In this section we will analyze an infinite conjugate system. An infinite conjugate system is the most common configuration for microscopes for reasons that we will see shortly. It is a subset of a type of optical system called a 4-f system. The 4-f system is a canonical optical system composed of two lenses separated by the sum of their focal lengths. In this section, you will simulate a 4-f system and investigate how different parameters in it affect its performance.
Give the first lens a focal length of 10 cm and the second with a focal length of 40 cm. Separate the two lenses by a distance given by the sum of their focal lengths (50 cm) and place an aperture at the back focal plane of the first lens in your system (this will also by definition be at the front focal plane of your second lens). Place your object at the front focal plane of the first lens.
3.0.5 Paper Calculation
First, use basic ray tracing diagrams and calculations to predict the behavior of this system and answer the questions below.
- For the first lens (objective lens) and intermediate image
- Where is the image located?
- Is it real or virtual?
- Upright or inverted?
- What is its magnification?
- For the second lens (tube lens) and final image
- Where is the final image of the imaging system located?
- Is it real or virtual?
- Upright or inverted?
- What is its magnification (with respect to the initial object)?
- Are the rays between the two lenses converging, diverging, or traveling parallel?
3.0.6 Computer Simulation
Set up a new simulation with two lenses as in the section before. Launch a set of rays through the optical system to answer the following questions again for the infinite conjugate system:
- For the first lens (objective lens) and intermediate image
- Where is the image located?
- Is it real or virtual?
- Upright or inverted?
- What is its magnification?
- For the second lens (tube lens) and final image
- Where is the final image of the imaging system located?
- Is it real or virtual?
- Upright or inverted?
- What is its magnification (with respect to the initial object)?
- Are the rays between the two lenses converging, diverging, or traveling parallel?
3.0.7 Aperture
How does the aperture at the back focal plane impact what rays can pass through the optical system? (Hint: create a large cone of rays and then see how changing its size impacts the bundle of rays)
Do the results of your ray tracing simulation match your expectations? Why or why not? Upload a screenshot of your ray tracing simulation.
3.0.8 The advantage of infinite conjugate systems
In this section we will investigate the advantages of an infinite conjugate optical system compared to a finite conjugate one. Keep the objects and distances between the lenses at the same distances as you set in the respective sections above.
We will compare the two systems by investigating what happens when we place a slab of glass into the optical path. Add a 5 cm thick slab of glass (\(n=1.5\)) in the space between the two lenses in both systems (making sure that you reduce the amount of space on either side to keep the lens separation the same). You can do this using the DielectricSlab object. Run the simulations again and comment on your observations for each system using the questions below.
- Does the location of the image change?
- Does the magnification of the system change?
- How does the image location and magnification change as the thickness of the glass slab increases?
Based on this analysis, why do you think that infinite conjugate systems are the preferred architecture in modern microscopes?
Consider that it is often advantageous to put filters in the microscope system to, for example, block certain wavelength ranges.
4 Raspberry Pi Camera Module
4.1 Raspberry Pi Camera Module Specs
Explore the datasheet and specifications for the Raspberry Pi v2 camera here and fill in the table below.
Specification | Value | Units | Notes |
---|---|---|---|
Lens focal length | |||
Lens f-number | |||
Sensor pixel size (w x h) | |||
Sensor size (w x h) in physical units | |||
Pixel count (total number of pixels) |
4.2 Ray Tracing Simulation of the 3d-printed Raspberry Pi Microscope
For this section, you will perform a ray tracing simulation of the 3d-printed microscope architecture we will use in later labs. You may find a copy of the paper describing the system here.
This microscope is designed by removing the lens of the Raspberry Pi camera and displacing it from the sensor to create a microscope with a working distance of ~7 mm. Using the parameters of the camera and lens that you found from the datasheet and completed in the table above, set up a simulation to analyze this microscope configuration. Photos of the lens with a scale bar are provided below for your reference.
4.2.1 Camera Lens Questions
- Estimate the diameter of the lens from the photos.
- Does this lens have a front or rear stop?
- Estimate the size of the stop from the photos. Then using the parameters from the lens data sheet that you collected in the table above, calculate the diameter of the stop. Do these values match?
4.2.2 Simulation
Set up a ray tracing simulation of the Raspberry Pi microscope using this single lens as a simple single-lens imaging system. Include any stops as appropriate. For example, you should consider the stop on the lens assembly and the finite size of the camera sensor. You may place the stop on the lens assembly at a distance of 1 mm from the lens. Then, use your simulation to answer the following questions.
- Write an expression to calculate the lateral magnification of the optical system. (Hint: make sure you set the objectHeight property of the ImagingPath object and check out the imageSize function with the useObject parameter set to True.)
- How far in front of the lens should the object be located in order to achieve a lateral magnification of 1.5x?
- At this magnification of 1.5x, what is the image distance (i.e., how far behind the sensor is the image located)?
- What is the maximum object size that you can image? Note that the field of view is normally defined as the diameter of the object where half the cone of rays from the edge of the object passes through the optical system.
- What is the maximum angle that a ray emitted from the center of the object can have with respect to the optical axis such that it still passes through the optical system? This quantity is called the half-angle of the acceptance cone and is used in calculating the numerical aperture (NA) of the optical system using the expression. The NA is an important parameter for determining the resolution of the optical system. What is the NA of this optical system?
- How would you change the optical system to achieve a magnification of 2x?
Save a copy of your simulation figure to submit.
5 Resources
Documentation