Timing a beam of light
LiDAR (Light Detection and Ranging) measures distance by timing a laser pulse's round trip to a surface and back. Because light travels at roughly 3×10⁸ m/s, timing electronics need picosecond-scale precision to resolve centimetre distances — the round trip to a wall 15 metres away takes only about 100 nanoseconds. A rotating 2D unit spins this ranging system continuously, firing thousands of pulses per second at slightly different angles, and each returned range paired with its firing angle becomes one point in a 360° scan.
distance = c · t_roundtrip / 2 c = speed of light ≈ 3×10⁸ m/s t_roundtrip = time between pulse emission and detected return
Ray marching and the point cloud
In a simulated or software model of a LiDAR, the physical timing measurement is replaced with geometry: each ray is stepped (or intersected analytically) outward from the sensor until it meets the nearest obstacle, exactly reproducing what a real beam's return would report. Every ray's endpoint — converted from the sensor's local polar coordinates (angle, range) into world Cartesian coordinates using the sensor's own position and heading — becomes one point in a point cloud, a raw, unstructured scatter of surface samples with no explicit connectivity between them.
From points to a grid: the occupancy map
A point cloud alone is noisy and sparse — real sensors misfire, reflect off glass, or catch a moving obstacle. Robots instead accumulate scans into an occupancy grid: the environment divided into small cells, each holding a belief about whether it is free or occupied. A single ray provides two kinds of evidence at once — its endpoint is likely occupied, and every cell it passed through on the way there was, by definition, unobstructed enough for the beam to reach the endpoint, so those cells are evidence for free space.
Log-odds: fusing evidence cheaply
Combining repeated, independent, noisy observations of the same cell with Bayes' rule directly means multiplying probabilities together — numerically awkward and slow. The standard trick, used in essentially every mapping system from Elfes' original occupancy grid work (1989) onward, is to track each cell's log-odds instead, because Bayesian updates in log-odds space collapse to simple addition:
l(cell) = log( p(occupied) / (1 − p(occupied)) ) on a ray passing through a free cell: l += l_free (l_free < 0) on a ray ending (hit) at the endpoint cell: l += l_hit (l_hit > 0) recover probability any time: p = 1 / (1 + e^(−l))
Every new scan just adds a small positive or negative increment to each affected cell's running total. Cells that repeatedly see free-space evidence drift toward strongly negative log-odds (confidently free); cells repeatedly hit by ray endpoints drift positive (confidently occupied); cells rarely observed stay near zero (unknown). Because it is additive and reversible, the same scheme naturally lets a cell flip from occupied back to free if the environment changes — a chair moves, a door opens — without any special-case logic.
Frequently asked questions
How does LiDAR actually measure distance?
Most rotating 2D LiDAR units use time-of-flight: they emit a laser pulse and measure the time until its reflection returns, then convert that time to distance using the speed of light, distance = c times time / 2. Some shorter-range units instead measure the phase shift of a continuously modulated beam, trading maximum range for finer resolution at short distances.
Why does an occupancy grid use log-odds instead of raw probabilities?
Log-odds turns the Bayesian update from repeated multiplication of probabilities, which is numerically unstable and slow, into simple addition — each new ray's evidence is just added to the cell's running log-odds value. It also naturally handles conflicting evidence over time: cells accumulate confidence gradually and can flip from occupied back to free if enough new free-space observations arrive, which is exactly the behaviour you want when a room's furniture moves.
Why do cells along a LiDAR ray get marked free, not just the endpoint?
A returned range measurement tells you two things at once: the endpoint is likely occupied, and every cell the ray passed through before that endpoint must have been unobstructed, or the laser would have reflected earlier. Marking the whole ray, not just its tip, is what lets a handful of scans clear out large open areas instead of leaving them permanently unknown.
Try it live
Everything above runs in your browser — open LiDAR Scanning and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.
▶ Open LiDAR Scanning simulation