Ray diagrams, the lens equation and the mirror equation
In the multimedia tutorial Geometrical Optics, we made a ray diagram using rays of light.
Below we show just a schematic, so that we can label the geometry and use it to derive the lens equation, i.e. we shall relate object distance d_{o},
image distance d_{i} and focal length f.
To start, we locate the bottom of the object on the optical axis of the lens, as shown, a distance d_{o} from the lens. A ray on the axis is undeflected, so the base of the image will also lie on that line. From the top of the object (height h_{o}), we take one ray through the centre of the lens. This ray too is undeflected by the lens. Then we take a ray from the top of the object and parallel to the axis of the lens. By definition of the focus, this ray is refracted to pass through the focus. The top of the image is located where this ray intersects the other ray from the same point on the object. The intersection point determines both the image distance d_{i} and the image height h_{i}.

A ray diagram for a converging lens, used to derive the lens equation 
Look first at the two right angle triangles having angle θ at the lens. These are similar triangles, so
h_{i}/h_{o} = d_{i}/d_{o}
.
which incidentally gives us the magnitude of the magnification. Then look first at the two right angle triangles have angle φ at the focus. These are also similar triangles, so
h_{i}/h_{o} = (d_{i} − f)/f ._{}
Setting the two expressions for h_{i}/h_{o}equal gives
d_{i}/d_{o} = (d_{i} − f)/f , which we can rearrange as:
1/d_{o} = (d_{i} − f)/d_{i}f = 1/ f − 1/d_{i}
And that gives us the lens equation:
1/d_{o} + 1/d_{i} = 1/f , or 1/(object distance) + 1/(image distance) = 1/(focal length)
If
we replace this converging lens with a converging (ie concave) mirror, facing right, then the object would have to be on the right, and the rest of the diagram could be the same. So this equation works for lenses, too.
In more complicated examples involving two or more lenses, mirrors or combinations, it is helpful to use a cartesian convention for the distances and heights involved. 