A mirror or lens is a transformation from incoming ray to outgoing ray. Ray diagrams let you trace that transformation without simulating every electromagnetic wave. They are useful only when the object, aperture, and surfaces are large compared with the light's wavelength.
For a thin converging lens, the paraxial ray model says
\[\frac{1}{f}=\frac{1}{d_{\mathrm{o}}}+\frac{1}{d_{\mathrm{i}}}\]Here f is positive focal length, dₒ is positive object distance, and dᵢ is signed image distance. Solve it as a function whose special case is explicit:
function imageDistance(objectDistance: number, focalLength: number) {
const inverseImageDistance = 1 / focalLength - 1 / objectDistance;
return Math.abs(inverseImageDistance) < Number.EPSILON * 32
? null // parallel rays: image at infinity in this ideal model
: 1 / inverseImageDistance;
}
The magnification check is
\[m=\frac{h_{\mathrm{i}}}{h_{\mathrm{o}}}=-\frac{d_{\mathrm{i}}}{d_{\mathrm{o}}}\]At dₒ = 30 cm and f = 10 cm, the equation gives dᵢ = 15 cm and m = −0.5. The minus sign predicts an inverted image half as tall as the object. At dₒ = 5 cm and the same focal length, dᵢ = −10 cm: the rays diverge after the lens but their backward extensions meet on the object side, so the image is upright and virtual.
Move the object and focal length. Distances are in centimetres. The object and lens are idealized; arrow directions show image orientation.
Real image: 20.0 cm beyond the lens; magnification -0.67.
The diagram uses only a few principal rays. That is deliberate. Its goal is to make the equation's branches visible, not to render photorealistic glass. The accompanying tests ask for the 2f case, the focal-plane null case, and a virtual-image case so a drawing cannot silently hide a sign mistake.
Prediction: Moving the object from beyond twice the focal length toward the lens makes a real image move farther away and grow before it becomes virtual.
Set the focal length to 12 cm. Compare object distances of 36 cm, 24 cm, 18 cm, 12 cm, and 8 cm. Before moving each slider, predict the image type, orientation, and whether its distance should increase or decrease. At 12 cm, explain why the result is not a huge finite number.Ray optics makes an optical system testable: trace a few labelled rays, solve a signed distance equation, and compare the diagram with focal-point limiting cases. Treat “image at infinity” and “virtual image” as model outputs with meaning, not UI errors.
Treat the lesson as a small function before treating it as a fact to memorize. Give every value a unit, keep only the state needed for the next step, and make the output easy to inspect.
\[\text{observable output} = f(\text{inputs},\,\text{state})\]For Mirrors and Lenses, write down the quantities you can control, the values your program must retain, and the result a reader could inspect. In Geometric and Wave Optics, the useful program is not the drawing: it is the smallest explicit model that makes a prediction you can test.
Prediction: changing one declared input while holding the others fixed should change only the outputs that the model connects to that input. Choose one input, predict the direction of change, then check a limiting case such as zero, a symmetric arrangement, or a familiar low-speed or small-change approximation.
This lesson is a teaching model, not a complete simulator. Before using it outside the stated question, check which interactions, scales, uncertainties, boundary conditions, and measurement limits it leaves out.
Treat Mirrors and Lenses as a contract: named inputs and units enter a rule, the rule produces an observable result, and a known limit or invariant checks whether the implementation deserves trust.
Compose ideal optical elements as explicit ray-transform functions with focal reference tests.