📡 LiDAR Scanning
A 2D rotating LiDAR ray-marches against walls to build a point cloud and an occupancy grid. Adjust angular resolution, max range, noise and speed; drag the sensor around rooms.
About this simulation
This simulation models a 2D rotating LiDAR sensor that measures distance by ray casting: at each angle it tests the ray against every wall segment with a real ray–segment intersection formula and keeps the nearest hit as the range, just like a time-of-flight range sensor picking the first surface a laser pulse reflects from. Each hit becomes a point in a growing point cloud, while cells along the ray are marked free and the hit cell is marked occupied in a log-odds occupancy grid — the same probabilistic mapping technique used in real SLAM systems. Gaussian noise is added to every range reading to mimic real sensor imprecision.
🔬 What it shows
A rotating beam sweeps 360° around a sensor placed inside one of several wall layouts. Each ray's hit point is plotted on the left as a point cloud and accumulated on the right into an occupancy grid, where green cells are occupied (probably a wall) and dark cells are free space the beam has swept through unobstructed.
🎮 How to use
Drag the yellow sensor dot around the room to rescan from a new position (this clears the map). Use the sliders to change rays per scan (angular resolution), max range, range noise σ and rotation speed, and switch environments with the preset buttons: Empty room, Cluttered, Corridor and Single obstacle. Click "Clear map" to reset the accumulated point cloud and grid.
💡 Did you know?
Real LiDAR units on self-driving cars and robots work on this exact principle at much higher speed and precision: they fire thousands of laser pulses per second, time how long each takes to bounce back (or measure phase shift), and convert that into range. Stitching ranges from many angles together is exactly how the occupancy grid in this simulation — and real robot mapping software — builds a map of its surroundings.
Frequently asked questions
What does LiDAR stand for and how does it measure distance?
LiDAR stands for Light Detection and Ranging. It works by emitting a laser pulse and measuring how long it takes to travel to an object and reflect back (time-of-flight), or by measuring the phase shift of a continuous beam. Since light travels at a known constant speed, that time (or phase difference) converts directly into a distance measurement. This simulation approximates the same idea in 2D using geometric ray casting instead of a real time-of-flight measurement.
What is ray casting and why does it need ray-segment intersection?
Ray casting fires an imaginary line from the sensor in a chosen direction and finds where it first meets an obstacle. To find that point, the simulation solves for the intersection between the ray and every wall segment in the scene using their parametric line equations, then keeps only the closest valid intersection (t and u both within range). This is the same core geometric operation used in real-time rendering, 2D games and robotics range-sensor models.
What is a point cloud?
A point cloud is simply the collection of 3D (or, here, 2D) coordinates where a sensor's rays actually struck something. Every ray in this simulation that hits a wall contributes one point at that location; over many rotations, thousands of these points accumulate into a shape that traces the outline of the room and obstacles — exactly how real LiDAR units used in robotics and autonomous vehicles build up a picture of their surroundings.
What is an occupancy grid and how is it built from noisy readings?
An occupancy grid divides the environment into cells and tracks, per cell, the probability that it is occupied. This simulation uses a log-odds representation: every time a ray passes through a cell without stopping, that cell's free-space evidence is added; when a ray terminates in a cell, occupied evidence is added. Because each range reading includes Gaussian noise, no single scan is perfectly reliable, but averaging many noisy scans over time makes the grid converge toward an accurate map — the same principle used in real SLAM (simultaneous localization and mapping) systems.
Why does increasing "rays per scan" improve the map, and what is the trade-off?
More rays per scan means finer angular resolution, so thinner obstacles and sharper corners are less likely to be missed between two adjacent beams, and the resulting point cloud and occupancy grid look more detailed. The trade-off, just as in real hardware, is cost: more rays per revolution demands more measurements to be taken and processed in the same amount of time, which in a physical LiDAR unit means a faster (and typically more expensive) scanning mechanism or a lower maximum rotation speed.
A rotating 2D LiDAR fires rays that ray-march to walls, building a noisy point cloud and a log-odds occupancy grid (free along the ray, occupied at the hit). Drag the sensor around rooms and corridors.
3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install