Ray Diagram Simulator
Draw the principal rays through a converging or diverging lens and watch the image switch from real and inverted to virtual and upright.
Simulator
Drag the object along the axis, or move it with the left and right arrow keys. Space plays and pauses.
- Image type A real image can be caught on a screen. A virtual one only exists by looking through the lens.
- Real, inverted
- Image distance Measured from the lens. A virtual image sits on the same side as the object.
- 15 cm
- Magnification Negative means inverted. Magnitude above 1 means enlarged.
- -0.5
- Image height
- 2 cm
- Focal length Positive converges, negative diverges. The sign is what makes one equation cover both.
- 10 cm
- Power Dioptres, one over the focal length in metres. This is what an optician prescribes.
- 10 D
Citing this tool
Last updated . Add the date you accessed it as well, which a citation of a page that can change asks for. If a specific result matters, cite the permalink from the tool’s share row instead of this page: it reproduces the exact parameters.
The equation
Gaussian optics, thin-lens and mirror equations
One equation, one sign convention, no special cases
Every disagreement between optics textbooks is a disagreement about signs, and every student
who finds this topic hard has met three of them. Fix the convention once and the whole subject
collapses into a single equation, 1/f = 1/v + 1/u, with no separate rules for
virtual images and none for diverging lenses.
- Light travels left to right, and the object sits on the left.
- u is the object distance, positive for a real object.
- v is the image distance, positive to the right of the lens and therefore real. Negative means the image is on the object’s side, and therefore virtual.
- f is positive for a converging lens, negative for a diverging one.
- m = −v/u. Negative magnification means inverted.
That is the entire ruleset. A negative answer for v is not an error to be corrected, it is the equation telling you the image is virtual.
Why three rays, and why these three
Two rays locate a point, so two are enough and the third is a check. These three are the useful ones because their paths after the lens are known without doing any arithmetic at all:
- A ray arriving parallel to the axis leaves through the far focal point. A diverging lens instead spreads it out as if it had come from the near focal point.
- A ray through the centre of the lens carries straight on, undeviated.
- A ray through the near focal point leaves parallel to the axis. For a diverging lens the matching ray is the one aimed at the far focal point, and the simulator leaves it out, so a diverging lens is drawn with two rays.
Wherever they cross is the image. That is what makes the diagram a construction rather than a picture of an answer you already calculated, and it is why the rays here are drawn from those three rules and then checked against the equation rather than the other way round.
Move the object inside the focal length and the third ray disappears. That is not a bug: a ray heading from the object towards the near focal point is travelling away from the lens and never reaches it, so drawing it would be inventing a ray that does not exist.
The four cases for a converging lens
Drag the object along the axis and it passes through all of them. With a focal length of 10 cm:
- Beyond 2F, past 20 cm. Real, inverted, smaller. This is a camera.
- At exactly 2F. Real, inverted, same size, at the same distance on the other side. The one case where object and image match.
- Between F and 2F. Real, inverted, larger. This is a projector.
- Inside F, closer than 10 cm. Virtual, upright, larger. This is a magnifying glass.
At exactly F nothing forms. Every ray leaves parallel to every other, so they never meet, and the image is at infinity. Infinity is the correct answer there, not a failure.
What virtual really means
When the image is virtual the outgoing rays diverge. They are not converging anywhere, so putting a screen in their path shows nothing. What your eye does is trace them backwards, and the point they appear to come from is the virtual image. That is why those extensions are drawn dashed here: the dashed lines carry no light, and they are the only lines that cross.
A diverging lens does this for every object position, at any distance, which is why its magnification never leaves the range 0 to 1. It cannot project, and that is exactly what makes it useful for correcting short sight.
Dioptres, and why opticians use them
Lens power is 1/f with f in metres, measured in dioptres. A 10 cm converging lens
is +10 D and a 25 cm diverging lens is −4 D. The reason prescriptions use power rather than
focal length is that powers add: put two thin lenses together and the combination is simply
the sum, which focal lengths do not do.
What this diagram assumes
The lens is thin, so its thickness is ignored and both refractions are treated as happening at one plane. Rays stay close to the axis, which is what makes the focal point a point at all; a real lens focuses off-axis rays slightly differently, which is spherical aberration. And the light is one colour, since the refractive index varies with wavelength and a real lens focuses blue slightly closer than red.
The vertical scale is also exaggerated, as it is in every textbook ray diagram, because the axis spans a metre while the object is a few centimetres tall. Stretching one axis is safe here: these are straight lines, and scaling the axes independently does not move the point where straight lines cross. Only the angles look steeper than they are.
Common mistakes
- Treating a negative v as an arithmetic error. It means virtual, and it is the answer.
- Using 1/f = 1/v − 1/u. Which sign convention you adopt is up to you, but mixing two of them in one calculation is what produces images on the wrong side.
- Expecting a screen to show a virtual image. No light reaches it.
- Thinking a bigger lens magnifies more. Magnification depends on the focal length and the object distance. A larger lens gathers more light and gives a brighter image of the same size.
- Assuming half the lens gives half the image. Cover half of it and the whole image remains, just dimmer, because every part of the lens forms a complete image.
- Forgetting that the object can be inside F. That is the magnifying glass case, and it is the one worth understanding properly.
Model and assumptions
- Method
- Exact expression, no time stepping
- Repeatability
- Deterministic. The same link gives the same numbers on any machine.
What it assumes
- Paraxial geometric optics: the thin lens and mirror equations, solved exactly with no time stepping.
- Rays are traced by geometry, and the lens has no thickness and no chromatic dispersion.
- A single wavelength, so there is no colour fringing.
Where it stops holding. Rays far from the axis, where spherical aberration matters and the paraxial approximation stops holding.
Numerical accuracy
No method error to report: the result is a closed-form expression evaluated directly, with no time stepping to accumulate error. What remains is double-precision rounding, of order one part in 10^16 per operation.
Common questions
What is the difference between a real and a virtual image?
A real image is formed where light rays actually converge, so it can be caught on a screen placed at that point. A virtual image is where the rays only appear to come from when traced backwards; no light passes through it and no screen will show it. A converging lens gives a real image whenever the object is beyond the focal point, and a virtual one when it is closer than that, which is exactly how a magnifying glass works.
Why do I only need three rays?
You only need two, and the third is a check. The three are useful because their paths after the lens are known without any arithmetic: for a converging lens, a ray arriving parallel to the axis leaves through the focal point, a ray through the centre carries straight on, and a ray through the near focal point leaves parallel. Wherever any two of them cross is the image. That is what makes it a construction rather than a plot of an answer you already had.
Can a diverging lens ever make a real image?
Not of a real object, at any distance. The image is always virtual, upright and smaller, which is why the magnification stays between 0 and 1 no matter where you put the object. That is the defining behaviour of a diverging lens and the reason it is used to correct short sight rather than to project anything.
Does this work for mirrors too?
The arithmetic is identical: a concave mirror behaves like a converging lens and a convex mirror like a diverging one, with a focal length of half the radius of curvature. What differs is the drawing, because a mirror reflects light back, so a real image forms on the same side as the object and a virtual one forms behind the mirror. This simulator draws lenses, where the rays pass through, rather than showing a mirror with transmitted rays that would be wrong.