Lens Ray Tracer Back
Optics Simulator

Convex & Concave Lens Ray Tracing Simulator

Drag sliders to adjust focal length, object distance, and height. Watch 3 principal rays update in real time and see whether a real or virtual image forms.

Parameters
Lens type
Focal length |f|
mm
Object distance |u|
mm
Object height h
mm
Results
Image dist. v (mm)
Magnification m
Image height (mm)
Image type
Real · Inverted
Thin lens equation: $$\frac{1}{v}- \frac{1}{u}= \frac{1}{f}$$ Magnification: $m = -v/u$
Real object: $u < 0$; Real image: $v > 0$
Visualization
Parallel → focal point
Through center
Front focal → parallel
Virtual (dashed)

What is Lens Ray Tracing?

🙋
What exactly is ray tracing for lenses? I see the simulator has a light source and lines bending through a lens.
🎓
Basically, it's a method to predict how light behaves when it passes through a lens. We follow a few key rays from the object. For instance, a ray parallel to the axis will refract through the focal point. Try moving the 'Focal Length' slider above to see how bending changes for a stronger (shorter f) vs. weaker (longer f) lens.
🙋
Wait, really? So the point where all those rays meet is the image? And what's the difference between the convex and concave lens I can select?
🎓
Exactly! For a convex (converging) lens, rays actually meet to form a real image you can project on a screen. A concave (diverging) lens spreads rays apart; they appear to come from a point behind the lens, forming a virtual image. Switch between them in the simulator and watch the ray paths diverge instead of converge.
🙋
So the 'Object Distance' slider changes where the image forms. Is there a simple rule for predicting the image location and size?
🎓
Yes, and it's captured by the lens formula. In practice, as you slide the object closer to a convex lens than its focal point, the image flips from real to virtual. The 'Object Height' slider shows size changes. A common case is a magnifying glass—hold it close (u < f) for a big, upright virtual image.

Physical Model & Key Equations

The fundamental relationship between object distance, image distance, and focal length is given by the Gaussian Lens Formula. This equation governs the ray tracing you see in the simulator.

$$\frac{1}{v}- \frac{1}{u}= \frac{1}{f}$$

Where:
$u$ = Object distance (always negative by sign convention for real objects on the left).
$v$ = Image distance (positive for real images on the right, negative for virtual images on the left).
$f$ = Focal length (positive for convex/converging lenses, negative for concave/diverging lenses).

The magnification m tells you if the image is enlarged or reduced, and upright or inverted. It's derived from the ratio of image height to object height.

$$m = \frac{h_i}{h_o}= \frac{v}{u}$$

Where:
$h_i$ = Image height.
$h_o$ = Object height.
A negative magnification indicates an inverted image (common for real images from convex lenses), while a positive value indicates an upright image (common for virtual images).

Frequently Asked Questions

If the object distance is smaller than the focal length, a concave lens always produces a virtual image, while a convex lens produces a virtual image when the object is inside the focal point. It is also possible that the image is displayed outside the screen, so please move the slider slowly and check the changes in the image position and sign.
A real image is formed at the point where light rays actually converge and can be projected onto a screen. In the simulator, it appears as an inverted image on the right side of the lens. A virtual image is formed along the extension of light rays and appears as an upright image on the left side of the lens.
A concave lens alone cannot produce a real image. Since a concave lens diverges light, it always forms a virtual image (upright and reduced) on the same side of the lens as the object. To create a real image, it must be combined with a convex lens.
In Gauss's lens formula, the distance of a real object located on the left side of the lens is defined as a negative value. In this simulator, the object distance is displayed as an absolute value for intuitive operation via the slider. Internally, it is automatically treated as a negative value in calculations.

Real-World Applications

Digital Camera & Smartphone Lenses: These use complex assemblies of convex lenses to focus light onto a sensor. Engineers use ray tracing simulations to minimize distortions and aberrations, ensuring sharp photos. Adjusting the focal length in the simulator mimics zooming in and out.

Eyeglasses & Contact Lenses: Concave lenses are used to correct nearsightedness (myopia) by diverging light before it enters the eye. The simulator shows how a concave lens creates a virtual image closer to the viewer, which is what the nearsighted eye needs to focus properly.

Magnifying Glasses & Microscopes: A simple convex lens acts as a magnifier when the object is placed within its focal length (u < f). This produces a large, upright virtual image. In the simulator, slide the object very close to a convex lens to see this effect, which is the first stage of a compound microscope.

Projectors & Overhead Projectors: These devices use convex lenses to form a real, inverted, and enlarged image of a slide or LCD panel on a distant screen. The relationship shown in the simulator—where moving the object (slide) changes the image distance and size—is critical for focusing a projector correctly.

Common Misconceptions and Points to Note

First, you might think that "changing the focal length changes the image position and size 'proportionally'," but this is incorrect. Looking at the thin lens formula, the relationship between $u$, $v$, and $f$ involves the subtraction of reciprocals. For example, with a focal length $f=10$ cm and an object distance $u=-20$ cm, the image distance $v$ is 20 cm. If you double $f$ to 20 cm here, $v$ becomes infinity (parallel light). You can see it's not a simple proportional relationship. Try moving the sliders significantly in the simulator to experience this nonlinear change firsthand.

Next, while it's true that "a concave lens always forms only a virtual image," you need to pay attention to how that virtual image appears. The virtual image from a concave lens forms on the same side as the object, is always upright and diminished. You might tend to think, "If I move the object farther away, will it appear larger?" However, no matter how far you move the object, the size of the virtual image will never exceed the object's height. It's always $|m| < 1$. This is one reason why a concave lens cannot be used as a magnifying lens.

Finally, don't forget that the simulator deals with an "ideal thin lens". In practice, lenses have thickness and exhibit aberrations (chromatic aberration, spherical aberration, etc.). Even if you see perfect imaging in this tool, with a real single lens, light rays often don't converge to a single point. For instance, smartphone camera lenses are composed of multiple cemented elements precisely to cancel out these aberrations. Consider the simulator as a first step for understanding the "ideal system."