HomeOptics & LightMirrors & Lenses

Mirrors & Lenses

Interactive geometric optics: trace rays through converging and diverging lenses and mirrors. See real and virtual images form with the thin-lens equation 1/f = 1/do + 1/di.

Optics & Light3DEasy60 FPS
mirrors-lenses ↗ Open standalone

About this simulation

This ray tracer demonstrates geometric optics: how a single lens or mirror forms an image of an upright object. It draws the three principal rays and solves the thin-lens (and mirror) equation 1/f = 1/do + 1/di, then computes the magnification m = -di/do. By switching between converging and diverging elements you can watch real and virtual images appear, flip orientation, and grow or shrink as the object crosses the focal point.

🔬 What it shows

For a chosen optical element the simulator applies a sign convention (converging f > 0, diverging f < 0), solves 1/di = 1/f - 1/do for the image distance, and derives magnification m = -di/do and image height. A positive image distance gives a real, projectable image; a negative one gives a virtual image seen by looking into the element.

🎮 How to use

Pick the element from the dropdown (converging or diverging lens, concave or convex mirror). Use the three sliders to set focal length f (40-250 px), object distance do (30-450 px) and object height (20-120 px). The panel reports image distance, magnification and height live, and a badge labels the image real or virtual, upright or inverted.

💡 Did you know?

A converging lens only makes a magnified upright (virtual) image when the object sits inside the focal length - that is exactly how a magnifying glass works. Move the object past the focal point and the image flips, becoming real and inverted.

Frequently asked questions

What is the difference between a real and a virtual image?

A real image forms where light rays actually converge, so it can be projected onto a screen and the simulator marks it with a solid green arrow. A virtual image forms where rays only appear to come from, behind the lens or mirror; it cannot be projected and is drawn as a dashed yellow arrow. In the maths a positive image distance di means real, while a negative value means virtual.

How does the simulation calculate where the image forms?

It uses the thin-lens and mirror equation 1/f = 1/do + 1/di, rearranged to 1/di = 1/f - 1/do. Converging elements take a positive focal length and diverging ones a negative focal length. The magnification is then m = -di/do, and image height is m times the object height.

What do the three coloured rays represent?

They are the standard principal rays used to construct an image. The red ray travels parallel to the optical axis and then passes through the focal point F'. The green ray goes straight through the centre of the lens (or to the centre of a mirror) undeviated. The blue ray passes through the near focal point F and emerges parallel to the axis. Dashed segments are virtual extensions used to locate virtual images.

Why does a diverging lens or convex mirror never make a real image?

A diverging lens has a negative focal length, so 1/di = 1/f - 1/do is always negative for a real object. That makes the image distance negative, meaning the image is always virtual, upright and reduced in size. A convex mirror behaves the same way, which is why it is used for wide-angle car and shop mirrors.

How accurate is this model compared with real optics?

It uses the ideal thin-lens approximation, which assumes the lens is infinitely thin and rays stay close to the axis (the paraxial regime). That makes it a faithful teaching model, but it ignores real-world effects such as spherical and chromatic aberration, lens thickness and finite aperture. Distances are shown in pixels rather than physical units, so it illustrates the relationships rather than predicting a specific camera or telescope.

⚙ Under the hood

Interactive geometric optics ray tracer. Choose converging/diverging lenses or concave/convex mirrors, adjust focal length and object distance, and watch three principal rays form real or virtual images.

Canvas 2DGeometric OpticsThin Lens EquationRay TracingFocal LengthMagnification

3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)