JOVANA
Explore Library Glossary Getting Started Three Levels Fields How it works Mission
Join the mission
All guides

How a Camera Catches the World: The Pinhole Model

Trace the rays of light from a 3-D scene through a single tiny hole and discover the simple geometry behind why distant things look small and parallel lines meet at the horizon.

Why a Box with a Tiny Hole Makes a Picture

Imagine a sealed, pitch-dark room with a single tiny hole punched in one wall. On a bright day, something magical happens: a full-colour, upside-down image of the street outside appears, glowing faintly on the wall opposite the hole. No lens, no electronics, no batteries — just a hole. Renaissance artists called this device a camera obscura (Latin for 'dark chamber'), set up their easels inside, traced over the projected scene to nail perspective, and in doing so laid the foundation for every camera that followed.

A camera obscura: light from each point outside passes through the single pinhole and lands as one point on the back wall, building up an inverted image.

A dark box with a small hole in the front wall; straight rays from a tree outside cross at the hole and form an upside-down tree on the back inner wall.

Why does a hole make a picture at all? Think about a single bright point in the scene — say the tip of a candle flame. That point scatters light outward in every direction, like a tiny sun. Almost all of those rays slam into the outside of the box and are blocked. Only the rays aimed exactly at the tiny hole get through. Geometrically, a hole that small lets essentially one ray from the candle-tip reach the wall, landing on one spot. Every other scene point does the same: one point in the world → one ray through the hole → one point on the wall. That clean one-to-one mapping is precisely what an image is — and it is why the picture is sharp. The image is upside-down because a ray from the top of the scene travels in a straight line through the hole and keeps going downward to the bottom of the wall, while a ray from the bottom crosses up to the top.

To do clean geometry, we idealize this setup into the pinhole camera model: a perfect, infinitely small hole at a fixed location (so every scene point maps to exactly one image point, with zero blur), and a flat image plane behind it. The model throws away brightness worries and lens complications and keeps only the pure ray geometry. That stripped-down picture is powerful enough to explain perspective, focal length, and field of view — and, by the end of this guide, why a flat photo simply cannot tell you how far away things are. Everything that follows is just a consequence of this one diagram.

Perspective: Why Distant Things Look Smaller

The single rule hiding inside the pinhole model has a name: perspective projection. It says: to find where any 3-D point lands in the image, draw the straight line (the ray) from that point through the pinhole, and see where it pierces the image plane. That's it. Every visible point in the world is 'flattened' onto the 2-D image along the one ray that passes through the hole. The whole 3-D scene gets funnelled through a single point, then spread back out onto a flat surface.

Two big intuitions fall straight out of this. First: an object twice as far away looks half as big. Picture two identical friends, one standing 5 m away and one 10 m away. The far friend's rays enter the pinhole at a shallower angle, so they land closer to the centre of the image — the whole person is squeezed into half the height. Move them three times as far and they look a third as tall. Image size is inversely proportional to distance. (In the next section we will see this is literally the divide-by-depth in the projection formula.)

Second: parallel lines in the world appear to meet at a single point. Stand between railroad tracks and look down the line — the two rails are perfectly parallel, yet in the image they lean toward each other and seem to touch at a far-off spot called the vanishing point, sitting on the horizon. The same thing happens with the rows of tiles in a long hallway, or the two edges of a straight road. Why? Each point further down the track is more distant, so (by the first intuition) it shrinks toward the image centre; pile up infinitely many ever-more-distant points and the whole rail collapses onto one point. Lines that share a direction in 3-D share a vanishing point in the image.

Perspective projection in action: each 3-D point projects along its straight ray through the pinhole onto the image plane. Rays from farther points arrive at shallower angles and land nearer the centre, so distant things shrink.

Rays from a near tall object and a far tall object both pass through the pinhole; the far object's ray lands closer to the image centre, producing a smaller image.

This is exactly the perspective that Renaissance painters worked out by hand and that your eyes use every waking second — and it is not an artistic choice, it is forced on us by geometry. Because the pinhole collects rays through one point, anything you photograph (or see) obeys these rules automatically. So perspective, vanishing points, and the shrinking of distant things are all the same phenomenon, all flowing from the single-hole picture of the previous section. Next we make it quantitative.

The Projection Equation (from Similar Triangles)

Let's pin down coordinates so we can compute, not just gesture. Put the pinhole at the origin — the centre of our little universe. Set up three axes measured from the camera: X points to the camera's right, Y points up, and Z points straight out in front of the camera, into the scene. So a point's Z value is simply how far in front of the camera it is — its depth. Now place the flat image plane a fixed distance f in front of the pinhole, perpendicular to the Z axis. (To avoid the upside-down flip, we use the standard trick of drawing this 'virtual' image plane in front of the hole instead of behind it; the geometry is identical but the picture comes out right-way-up.)

Now look from the side, at just the X and Z directions, and draw two triangles that share the pinhole as their tip. The big triangle runs from the pinhole out to the 3-D point: it is Z long (the depth) and X tall (how far right the point is). The small triangle runs from the pinhole to the image plane: it is f long (the focal length) and x' tall (where the point lands on the image). Because both triangles are formed by the same ray meeting the same pinhole, they are similar — same shape, different size — so their matching sides are in the same ratio. That single fact, the ratio of similar triangles, gives us the whole formula.

\frac{x'}{f} = \frac{X}{Z} \;\Longrightarrow\; x' = f\,\frac{X}{Z}, \qquad y' = f\,\frac{Y}{Z}

The perspective projection equations, read straight off the similar triangles.

Read it slowly. The similar-triangle ratio says x'/f (the small triangle's height-over-length) equals X/Z (the big triangle's height-over-length); multiply both sides by f and you get the projection. Symbol by symbol: X, Y are the point's sideways and up-down positions in the camera's frame (in metres, say); Z is its depth — how far in front of the camera it sits; f is the focal length, the fixed pinhole-to-image-plane distance; and x', y' are the coordinates where that point lands on the image. The Y equation is identical to the X one, just done in the up-down direction. The heart of it all is the division by Z: the deeper the point (bigger Z), the smaller x' and y' become, so far things shrink toward the centre. This single divide-by-depth is perspective projection, made exact.

Let's run a real point. Take a 50 mm lens, so f = 0.05 m, and a point sitting 1 m to the right of the optical axis (X = 1, Y = 0) at a depth of 5 m (Z = 5). Then x' = f·X/Z = 0.05 × 1 / 5 = 0.01 m = 10 mm to the right of the image centre. Now shove the same point twice as far, to Z = 10 m: x' = 0.05 × 1 / 10 = 0.005 m = 5 mm — exactly half. Double the depth, halve the image size, just as our 'twice as far looks half as big' intuition promised. Notice this map is nonlinear: because Z sits in the denominator, doubling Z doesn't add or subtract a fixed amount, it divides. That awkward division is what makes perspective hard to handle with plain matrix algebra — and it is exactly the wrinkle that homogeneous coordinates in the next guide will iron out, turning this division into clean matrix multiplication.

def project(X, Y, Z, f):
    # Pinhole at the origin, camera looking down +Z, image plane at distance f.
    # The single division by depth Z is the whole essence of perspective.
    x_img = f * X / Z
    y_img = f * Y / Z
    return x_img, y_img

f = 0.05  # 50 mm focal length, in metres
print(project(1.0, 0.0, 5.0,  f))  # (0.01, 0.0)  -> 10 mm right of centre
print(project(1.0, 0.0, 10.0, f))  # (0.005, 0.0) -> same point, twice as far, half the size
The projection equation in code. Push the same point deeper and watch the image coordinate shrink in proportion.

Focal Length: The Zoom Knob

We have been writing f without dwelling on it. Physically, the focal length is simply that distance from the pinhole to the image plane — the length of the little box, if you like. It is the one knob the camera-maker (and you, when you zoom) gets to turn, and in our formula it is the number multiplying everything: x' = f·X/Z. So whatever the geometry hands you for X/Z, the focal length scales it up or down before it lands on the image.

That multiplication gives focal length its operational meaning. A larger f multiplies every x' and y' by a bigger number, so the same scene spreads across more of the image — objects look bigger and you see only a narrow slice up close. That is a telephoto or 'zoomed-in' lens. A smaller f shrinks everything toward the centre, packing more of the world into the frame — that is a wide-angle lens. Same scene, same pinhole geometry; only f changed, and the picture zoomed.

You feel this every time you pinch-to-zoom on a phone. 'Zooming in' optically is the camera lengthening its effective focal length: distant faces swell to fill the screen, but you can no longer fit the whole room in. 'Zooming out' shortens f: the room reappears but everyone is tiny. So when you read f = 0.05 m (a 50 mm lens) in the projection equation, picture a modest, natural-looking zoom — close to what the human eye sees — and a 200 mm telephoto as roughly four times that magnification. The symbol f in the formula and the zoom slider on your phone are the same thing.

Field of View: How Much of the World Fits

Focal length tells you the magnification; the field of view (FOV) tells you the angle. It is the angular width of the cone of scene the camera can capture, measured in degrees, from one edge of the image to the other. A security camera covering a whole lobby has a wide FOV; a birdwatcher's spotting scope picking out one distant owl has a tiny FOV. Crucially, FOV depends on two things at once: the focal length f and the size of the sensor (or film, or image plane) that catches the rays. A long lens on a big sensor and a short lens on a tiny sensor can give the very same angle.

\text{FOV} = 2\,\arctan\!\left(\frac{d}{2f}\right)

Field of view from sensor size d and focal length f.

Here is where it comes from, symbol by symbol. d is the sensor's size along the direction you care about — its width for horizontal FOV, its height for vertical FOV. f is the focal length again. Look at the half-triangle from the pinhole to one edge of the sensor: its 'opposite' side is half the sensor, d/2, and its 'adjacent' side is f, so the ratio (d/2)/f = d/(2f) is the tangent of the half-angle. Applying arctan (the inverse of tangent) converts that ratio back into an actual angle — the half-FOV. Finally the factor 2 doubles the half-angle into the full angle, because the sensor sticks out by d/2 on both sides of the centre. So the recipe is: take half the sensor, divide by focal length, arctan it, double it.

Let's compute. Take a full-frame sensor 36 mm wide (d = 36) with a 50 mm lens (f = 50). Then d/(2f) = 36 / 100 = 0.36, and arctan(0.36) ≈ 19.8°, so FOV = 2 × 19.8° ≈ 39.6° — a natural, eye-like view. Now halve the focal length to a 25 mm wide-angle lens: d/(2f) = 36 / 50 = 0.72, arctan(0.72) ≈ 35.7°, so FOV ≈ 71.5°. Halving f nearly doubled the angle of view — the lens now drinks in far more of the world. This is the inverse f-versus-FOV relationship: longer focal length → narrower view (telephoto), shorter focal length → wider view (wide-angle), exactly matching the zoom intuition from the previous section. (It is not perfectly 2× because arctan is nonlinear, but the direction and rough magnitude hold.)

import math

def fov_degrees(sensor_mm, focal_mm):
    # half-angle = arctan( (half the sensor) / focal length )
    half_angle = math.atan(sensor_mm / (2 * focal_mm))
    return math.degrees(2 * half_angle)   # double it for the full angle

print(round(fov_degrees(36, 50),  1))  # 39.6  -> a normal 50 mm lens
print(round(fov_degrees(36, 25),  1))  # 71.5  -> halve f, view nearly doubles (wide-angle)
print(round(fov_degrees(36, 200), 1))  # 10.3  -> long telephoto, a narrow slice
Field of view for a 36 mm sensor at three focal lengths — shorter f, wider view.

The Inversion Problem: From 2-D Back to 3-D

Now the twist that launches half of computer vision. Look again at x' = f·X/Z. To make the image we divided by Z — and in doing so we threw Z away. The equation keeps the ratio X/Z but not X and Z separately. So every 3-D point lying along a single ray through the pinhole — near or far, it doesn't matter — produces the same x' and y', and therefore lands on the same pixel. A flat image faithfully records which ray each pixel came from, but is utterly silent about how far along that ray the object sat. This is the price of perspective projection: it is a one-way street that discards depth.

Make it concrete. A toy car 10 cm long held 1 m from the lens, and a real car 4 m long parked 40 m away, can cast pixel-for-pixel identical images: both have the same X/Z ratio, so both fill the same patch of the frame. From that single view, neither your eye nor the sensor can tell them apart. This is exactly the trick behind forced-perspective photos — a tourist 'holding up' the Leaning Tower of Pisa, or 'pinching' the sun at sunset. The camera is not fooled; it is just faithfully reporting that both objects sit on the same rays.

This loss is called the depth ambiguity, and it is why you cannot, in general, recover a 3-D scene from one photo — the math literally erased the information. To get depth back you must add something: a second viewpoint (two eyes, or two cameras = stereo, where the small shift between views betrays distance), motion over time, a depth sensor that measures Z directly, or learned priors — a neural network that has seen so many cars and rooms that it can guess plausible depth from cues like familiar size, blur, and shading. Every one of these is a way to break the tie that the divide-by-Z created.