Lens Ray TracingBeta

Follow each ray to see where a convex or concave lens forms its image

This tool is a beta version still being stabilized. Please let us know if a result looks off.

The film sits fixed at the back of the camera. Slide the lens back and forth until the candle lands sharply on it.

Goal Get the blur on the film below 0.25 cm

Getting the light ready…

  • rays from the tip
  • rays from the base
  • where your eye thinks it came from
  • lens
  • focus F
  • screen / film
  • the image

Object distance a
–
Image distance b
–
Magnification
–
Kind of image
–
Image size
–
Blur on screen
–
f-number
–

More to play with
Construction rays use the ideal thin lens of the textbook
Why does it work this way?

Light meets the glass more steeply near the rim than at the centre, and the steeper it enters the more it bends (Snell's law). So in a convex lens the outer rays are turned inward the hardest and the whole bundle lands on one point. This simulation never uses the thin-lens formula: it bends each ray at the front and back surface and follows it.

When the light leaving one point of the object comes back together at another point, that place is a real image. When it spreads out instead, your eye reads it as coming from somewhere behind, and you see a virtual image there. That is exactly what a magnifier gives you.

Open the aperture and the edge rays bend more than the formula expects, pulling the focus towards the lens. That is spherical aberration, and whatever fails to meet becomes blur — the reason a stopped-down photo looks crisper.

  • 1/a + 1/b = 1/f
  • m = −b/a
  • 1/f = (n−1)(1/R₁ − 1/R₂)
  • f-number = f / diameter

About Lens Ray Tracing

This tool does more than plug numbers into the thin lens equation. Each lens is built from two real spherical surfaces, and every ray is bent at the front and back surface by Snell's law. That is why the image the formula predicts and the place where rays actually cross drift apart, and the gap between them is lens aberration made visible. Lengths are in centimeters.

The lens shape comes from the lensmaker's equation. For an equiconvex lens with the same radius on both sides and negligible thickness, 1/f = (n − 1)·2/R, so R = 2(n − 1)f. The tool goes one step further and solves the thick-lens equation 1/f = (n − 1)(2/R − (n − 1)d/(nR²)), which includes the center thickness d, so the paraxial focal length equals the f on the slider exactly. With the default f = 20 cm, n = 1.52 and a 3 cm aperture radius, R ≈ 20.7 cm (20.8 cm in the thin-lens approximation) and the lens is about 0.69 cm thick. A negative f gives a negative R, and the tool draws a concave lens that is thinner in the middle.

1/a + 1/b = 1/f and the sign conventions behind it

The tool measures object distance a as a positive number to the left of the lens. A positive image distance b means a real image on the right; a negative b means a virtual image on the same side as the object. Magnification is m = −b/a, and a negative value means the image is upside down. This real-is-positive convention is the one most US introductory textbooks use, written there as 1/s_o + 1/s_i = 1/f.

Many British texts and university optics courses use the Cartesian convention instead. Every distance is measured from the lens in the direction light travels, so a real object on the left has a negative distance, and the equation becomes 1/v − 1/u = 1/f. Substitute u = −a and v = b and the two are the same equation. If a worked solution you found online disagrees with yours only in sign, this is nearly always why. With two or more lenses the Cartesian form tends to prevent mistakes, because the image from one lens becomes the object for the next without any sign flipping.

Measuring from the focal points gives an even shorter form. If the object is x beyond the front focal point and the image is x′ beyond the back focal point, then x·x′ = f², Newton's form of the lens equation. It shows at a glance why the image races away as the object approaches the focal point.

Where rays and formula disagree: spherical aberration

The thin lens equation only holds for rays close to the axis. A spherical surface over-bends rays near its rim, so marginal rays cross the axis closer to the lens than central rays do. Tracing parallel light through the same shape the tool uses (f = 20 cm, n = 1.52, R ≈ 20.7 cm on both faces) with a 3 cm aperture radius, rays near the axis cross about 20.1 cm from the lens center while rays at a height of 3 cm cross at about 19.4 cm. Open the aperture to 6 cm (R ≈ 20.4 cm) and a ray at 5 cm height is pulled in to about 18.2 cm.

The near-axis rays meet at 20.1 cm rather than 20, and that is not a focal-length error. The tool draws the lens with a real center thickness of twice the sag plus 0.25 cm, not as an infinitely thin sheet. For a thick lens, distances are measured from the principal planes rather than the lens center, and in a symmetric lens the two principal planes sit a distance δ in front of and behind the center (about 0.12 cm here). The focus lies exactly f = 20 cm behind the rear principal plane, which is 20.12 cm from the center. In ray-bundle mode the tool's “where the formula puts it” readout also measures from the principal planes, so with a narrow aperture it matches the traced focus almost exactly (about 0.02 cm apart at a 0.3 cm aperture) and whatever gap remains is spherical aberration. The F marks on screen sit at the same points. Construction-ray mode uses an ideal zero-thickness lens and measures from the center.

This is why shrinking the aperture slider in the camera scenario shrinks the blur spot on the screen. Stopping down blocks the rim rays, reduces spherical aberration and deepens depth of field, at the cost of light. The f-number, N = f/D with D the aperture diameter, is the single figure that captures that trade.

Aberrations this tool leaves out

The refractive index is a single fixed number, so there is no chromatic aberration. Real glass bends blue light more than red, so blue focuses closer to the lens. Achromatic doublets, which cement a crown and a flint element with different dispersion, have been used since the mid-18th century to cancel most of that error. Rays are also traced only in one plane containing the axis, so coma, astigmatism and distortion, which show up for off-axis rays in three dimensions, do not appear.

What the formula does in each scenario

A magnifier keeps the object inside the focal length so that b is negative and the image is upright and virtual. A projector puts the object just outside the focal length to throw a large inverted real image far away. The telephoto scenario shows that a longer focal length gives a bigger image but forces the lens to sit about f away from the sensor, which is why telephoto barrels are long. The telescope scenario is a Keplerian layout: the focal points of the objective (f₁ = 40 cm) and the eyepiece (f₂) coincide, so the light leaves parallel again. Angular magnification is −f₁/f₂, and the minus sign means the view is inverted.

Worked examples

Getting an upright 3× image with the magnifier

Input
f = 12 cm, object 8 cm from the lens
Output
1/b = 1/12 − 1/8 = −1/24, so b = −24 cm (virtual) and m = −(−24)/8 = +3

The scenario starts with a = 20 cm, giving 1/b = 1/12 − 1/20 = 1/30 and a real inverted image at b = 30 cm. Only when the object moves inside the 12 cm focal length does the image turn virtual. At a = 10 cm the result is b = −60 cm and m = +6, but close to the focal point the image runs off so quickly that it leaves the range your eye can accommodate.

Placing the telescope eyepiece

Input
Objective at x = 40 cm, f₁ = 40 cm, eyepiece f₂ = 5 cm
Output
Separation f₁ + f₂ = 45 cm, so the eyepiece belongs at x = 85 cm; light exits parallel and the angular magnification is −40/5 = −8

At the starting position of 70 cm the separation is only 30 cm and the exit light is not parallel. With f₂ = 4 cm the correct spacing is 44 cm (x = 84 cm) and the magnification becomes −10.

Autofocus: a closer subject pushes the lens forward

Input
f = 10 cm, sensor at x = 150 cm, subject distance 129 cm → 45 cm
Output
At 129 cm, b = 10.84 cm (lens at x ≈ 139.2 cm). At 45 cm, b = 12.86 cm (lens at x ≈ 137.1 cm)

A closer object forms its image farther behind the lens, so a camera with a fixed sensor moves the lens about 2 cm forward to refocus. It is the reason macro lenses extend so far.

How to use it

  1. Choose a scenario such as camera, magnifier or telescope.
  2. Use the sliders to move the lens or object, or change the focal length and aperture.
  3. Switch between the ray bundle and the three construction rays to compare the formula position with where real rays meet.
  4. In free mode, try other refractive indices and a concave lens (negative f).

Frequently asked questions

What does a negative image distance mean?

The rays leaving the lens are diverging and never actually meet. Their backward extensions meet on the object side. The result is a virtual image that you can see through the lens but cannot project on a screen.

What changes when I raise the refractive index?

Less curvature is needed for the same focal length (R = 2(n − 1)f). The lens gets thinner, rays bend less sharply at the rim, and spherical aberration drops. It is the same reason high-index eyeglass lenses are thinner.

Does a concave lens always make a small upright virtual image?

For a real object, yes. With a negative f, 1/b = 1/f − 1/a is always negative, so b < 0 and the magnification is a positive number between 0 and 1.

The formula position and the ray crossing differ. Which one is right?

The ray trace is closer to a real spherical lens. The formula position is the paraxial value with the lens thickness (principal planes) already accounted for, so the gap between them is spherical aberration. It grows with a wider aperture and shrinks to nearly zero when you stop down.

Sources

Last reviewed:

Privacy and how data is handled