geometry
drones
computer vision
From Pixel to Map: Why Casting a Ray to the Terrain Is So Hard
A drone sees a person. Finding where they stand on the map sounds like one line of geometry. It isn’t, and one degree can cost you 200 metres.
A drone sees a person. Simple question: where exactly on the map are they?
Not “somewhere over there”. A latitude and a longitude you could send someone to.
The obvious answer
It looks like three steps.
- Pixel: find the person in the image.
- Ray: turn that pixel into a direction leaving the camera.
- Ground: follow the ray until it touches the terrain.
The first two steps are solved problems. Camera calibration tells you which direction each pixel looks at. The drone’s GPS and attitude tell you where the camera is and where it points. The hard part hides in one word: touches.
The terrain is not a formula
If the ground were a perfect plane, the intersection would be one line of algebra. Real ground is a height grid: millions of cells, each holding one number, its elevation. There is no equation to solve. You have to walk.
So you walk the ray. Take a step and ask: is the ray still above the ground here? Take another. The moment the answer flips to “no”, the ray crossed the ground somewhere inside the last step.
Then you refine. Cut that step in half, keep the half where the crossing is, repeat. That’s bisection. About ten halvings take a 30-metre step down to a few centimetres.
An error that moves the point 200 metres
There’s one error in this pipeline that can move your point 200 metres. It isn’t a bug. Every input can be almost right and it still happens.
Hold that thought. First, a more ordinary trap.
Problem 1: jumping over a crest
Walking the ray with big steps is fast. It’s also how you miss things. A thin ridge, a wall or a cliff edge can fit entirely between two samples. Both samples say “above ground”, and the ray goes straight through the crest without noticing. You still get a hit, just in the wrong valley.
The fix is to stop picking a step size at all. Walk the grid cell by cell, visiting every cell the ray passes over, in order. That traversal is called DDA, the same trick early 3D games used to cast rays through a tile map. No cell is skipped, so no crest can hide.
The 200 metres: it’s the angle
Now the promised number. It has nothing to do with the terrain. It’s about how steep the ray is.
Put the drone m above flat ground. A ray looking down at an angle below the horizon lands at a distance
Looking 45° down, the point is 200 m away. If your angle is off by one degree, 44°, it lands at 207 m. Seven metres of error. Annoying, but fine.
Now look almost at the horizon: 8° down. The point is 1,423 m away. One degree off, 7°, and it lands at 1,629 m. Same one-degree error. 206 metres of difference.
Near the horizon the ray skims the ground, so a tiny rotation slides the hit point a long way. One degree is not a big error once you add up the attitude sensor, the gimbal and the timing. That’s why a good system rejects grazing rays: below some angle, the answer is too sensitive to trust.
Not a point: a region
Which leads to the honest answer. Every input carries a small error: the GPS position, the angles, the photo’s timestamp against the GPS fix, the exact pixel. Instead of pretending they’re zero, you cast hundreds of rays, each with its own small random nudge to those inputs, and look at where they land.
The hits form a cloud, stretched along the direction the camera looks, because that’s where angle error turns into distance. Draw the ellipse that holds 95% of them and you have the real output: the person is in here, with 95% confidence.
A point on a map looks precise. An ellipse is precise about how imprecise it is. That’s the better answer.
Your turn
Which one surprised you more, the hidden crest or the one degree? And what should I explain next: why your GPS height isn’t height above sea level, or why your compass doesn’t point north?
Also in Spanish and Portuguese.