Thin Lens Ray Tracer Back
Optics · Lens Design

Thin Lens Ray Tracer & Optics Simulator

Drag sliders to watch three principal rays update in real time. Instantly see image distance, magnification, and whether the image is real or virtual for convex and concave lenses.

Optical Settings
Mode
Focal Length f₁ (mm)
mm
Object Distance dₒ (mm)
mm
Object Height hₒ (mm)
mm
Presets
Results
— mm
Image Distance dᵢ
—×
Magnification m
— mm
Image Height hᵢ
Image Type
Lens
Parallel → through F'
Through F → parallel
Through center
Virtual image (dashed)
Theory & Key Formulas
$$\frac{1}{f}= \frac{1}{d_o}+ \frac{1}{d_i}$$

Magnification: $m = -\dfrac{d_i}{d_o}$

$d_i \gt 0$: real image   $d_i \lt 0$: virtual image

$|m| \gt 1$: magnified   $|m| \lt 1$: reduced

What is Thin Lens Ray Tracing?

🙋
What exactly is the "thin lens equation" I see in the simulator? It looks like a simple formula, but how does it predict where an image will form?
🎓
Basically, it's the master rule for a single, simple lens. The equation $1/f = 1/d_o + 1/d_i$ relates three distances: the focal length $f$, the object distance $d_o$, and the image distance $d_i$. In practice, if you know any two, you can solve for the third. Try it in the simulator: set a positive focal length (like 100 mm) and drag the "Object Distance" slider. Watch how the traced rays converge to form the image at the exact $d_i$ the equation predicts.
🙋
Wait, really? So if I move the object really close to the lens, the image goes far away? And what does a negative $d_i$ mean in the "Image Info" panel?
🎓
Exactly! That's the beauty of the equation. A negative $d_i$ means the image is virtual—the rays appear to diverge from a point on the same side of the lens as the object. You can't project it on a screen. A common case is a magnifying glass. Try it: use a convex lens ($f \gt 0$) but put the object inside the focal point ($d_o \lt f$). The rays won't converge on the other side; the image distance will turn negative, indicating a virtual, upright, and magnified image.
🙋
Okay, that makes sense for one lens. But the simulator has a "Two-Lens System" mode. How does that work? The rays look way more complicated!
🎓
Great question! For two lenses, we apply the thin lens equation sequentially. The image from the first lens becomes the object for the second lens. The key is the "Lens Separation" $d$ parameter. Change it and watch the rays bend. For instance, in a simple telescope, you have two lenses separated by the sum of their focal lengths. The simulator calculates this step-by-step, tracing the rays in real time so you can see how the final image position and magnification emerge from the interaction.

Physical Model & Key Equations

The fundamental law governing a single ideal thin lens is the Gaussian Lens Formula. It assumes the lens thickness is negligible and uses the paraxial approximation (small angles).

$$\frac{1}{f}= \frac{1}{d_o}+ \frac{1}{d_i}$$

$f$: Focal length of the lens. $f \gt 0$ for converging (convex) lenses, $f \lt 0$ for diverging (concave) lenses.
$d_o$: Object distance (positive if object is on the side from which light is coming).
$d_i$: Image distance. $d_i \gt 0$ indicates a real image (formed on the opposite side of the lens). $d_i \lt 0$ indicates a virtual image (formed on the same side as the object).

The lateral magnification $m$ tells you the size and orientation of the image relative to the object. It is derived from similar triangles in the ray diagram.

$$m = -\frac{d_i}{d_o}= \frac{h_i}{h_o}$$

$m$: Magnification. $|m| \gt 1$ means the image is larger than the object. The sign of $m$ indicates orientation: $m \gt 0$ means the image is upright , $m \lt 0$ means the image is inverted.
$h_o$, $h_i$: Object height and image height, respectively.

Frequently Asked Questions

If the object is inside the focal length of the lens, a concave lens always produces a virtual image, while a convex lens produces a virtual image on the object side. In this simulator, virtual images are displayed with dashed lines. It may also be outside the screen, so move the slider slowly to check the image position.
A real image is formed on the opposite side of the lens where solid light rays converge, and it can be projected onto a screen. A virtual image is formed on the same side as the object where the extensions of light rays (dashed lines) converge, and it cannot be projected onto a screen. In the simulator, real images are drawn with solid lines and virtual images with dashed lines to distinguish them.
The sign of the magnification indicates the orientation of the image. A negative value means the image is inverted (upside down), while a positive value indicates an upright image. For example, when an object is placed beyond the focal length of a convex lens, the real image is inverted, so the magnification becomes negative.
A concave lens always produces a virtual image, and the absolute value of its magnification is 1 or less (reduced image). On the other hand, with a convex lens, if the object is placed closer than the focal length, a magnified virtual image is produced. By moving the slider to make the object distance smaller than the focal length, you can also observe a magnified image with a convex lens.

Real-World Applications

Camera Lens Design: Engineers use these exact ray-tracing principles to design lens elements. By combining multiple lenses with different focal lengths and separations, they correct for aberrations and focus light precisely onto a camera sensor. The "Two-Lens System" mode in this simulator is a foundational model for such compound lenses.

Microscopes & Telescopes: These instruments are essentially precise arrangements of two or more lenses. A microscope uses a short-focal-length objective lens to create a magnified real image, which is then viewed through an eyepiece (acting as a magnifying glass). The overall magnification is the product of the magnifications of each stage.

Vision Correction (Eyeglasses): A prescription lens is designed to take an object at a desired distance (e.g., a book at 25 cm for a presbyopic eye) and form a virtual image at the eye's own far point, allowing the eye to focus it properly. This simulator helps visualize how concave or convex lenses shift the apparent image location.

Illumination & Optical Sensor Systems: In automotive lighting, projectors, or barcode scanners, engineers use geometrical optics to direct light from a source (like an LED) through lenses to create a specific beam pattern or to focus light onto a detector. This is a core CAE application for ensuring efficiency and performance before physical prototyping.

Common Misconceptions and Points to Note

First, understand that the "thin lens" concept does not negate real-world lenses. Actual lenses have thickness and aberrations. This simulator is an "ideal first-order approximation model." For example, smartphone camera lenses use multiple cemented elements to cancel aberrations, but their initial design is based on this thin lens model. Next, strict adherence to sign conventions is critically important. If you input a positive focal length for a concave lens or consider the distance to a virtual image as positive, all calculations will be off. Even when using professional optical design software, this convention is often the default setting. Third, avoid setting the lens separation too extremely in "Two-Lens Mode." For instance, bringing a 10cm and a 5cm focal length lens as close as 1cm causes rays to bend sharply, making the image appear behind the lens. This is an unrealistic combination; in actual microscopes, there is a specific fixed distance called the "tube length" between the objective and eyepiece lenses.

How to Use

  1. Set the focal length of Lens 1 using focalLen1Num (range: 50–500 mm for converging/diverging lenses)
  2. Adjust object distance objDistNum to position the object relative to Lens 1 (typical range: 100–1000 mm)
  3. If using a two-lens system, set Lens 2 focal length (focalLen2Num) and separation distance (lensSepNum) to trace rays through both surfaces
  4. Observe real-time ray paths and read Image Distance dᵢ, Magnification m, and Image Type (real/virtual) from output labels
  5. Drag sliders to vary parameters and watch how image position and size change instantaneously

Worked Example

Converging lens with f₁ = 100 mm, object distance = 250 mm. Using thin lens equation 1/f = 1/dₒ + 1/dᵢ: 1/100 = 1/250 + 1/dᵢ gives dᵢ ≈ 166.7 mm (real image, inverted). Magnification m = −dᵢ/dₒ = −166.7/250 ≈ −0.67. If object height = 30 mm, image height hᵢ = 30 × (−0.67) ≈ −20 mm. For compound lens (f₁ = 100 mm, f₂ = 80 mm, separation = 150 mm), intermediate image from Lens 1 becomes object for Lens 2, requiring sequential ray tracing calculations.

Practical Notes

  1. When object distance equals focal length (dₒ = f), image distance approaches infinity—the simulator displays "virtual/parallel rays" to indicate this critical condition
  2. For diverging lenses (negative focal length), all real objects produce virtual, upright images; adjust objDistNum below f to verify magnification remains < 1
  3. In two-lens systems, if Lens 1 projects an image beyond Lens 2's position, that intermediate image acts as a virtual object (negative dₒ) for the second lens—check Image Type output for correct classification
  4. Chromatic aberration is neglected; assume monochromatic light (e.g., 589 nm sodium yellow line) for educational accuracy