AlgoViz

S2 coverings on a sphere

medium 4 min

S2 projects six cube faces onto the sphere and recursively subdivides cells on those faces.

Video lesson · Chapter 1 of 5

A delivery region crosses the date line

0:00 / 4:03

How many cells cover a jagged coastline?

1:12Reel

Theory

Read or listen first. About 1 min.

What it is

S2 maps the sphere onto six cube faces and recursively subdivides each face. A geographic region can be approximated by a collection of cells at different levels.

Refine the cells along a service boundary

Outside2 coarse cells cover the region and extra area.
On this schematic patch of an S2 cube face, the service region crosses two cells. A covering includes both whole cells, including some points outside the region.

Why it exists

Large cells can represent broad interiors cheaply. Refining the irregular edge can reduce the number of points that require an exact polygon check.

Words to know

Boundary cell
A cell that intersects a region while also containing area outside it.

How it works

Step through the idea, or press Play.

Step 1 of 3

Start at cube faces. Choose S2 faces intersecting the service area.

Understand it

Worked example

S2 coverings on a sphere in practice

Cover a long coastal service area using large cells in the interior and smaller ones along the coast. A point in a boundary cell still needs the original polygon predicate.

Related case

Find every charger across a cell boundary

A driver near the edge of a grid cell requests chargers within 800 metres. The closest charger sits across the street in another cell.

Across the street, across the cell
Chargers on both sides of the streetABCOne cell misses charger B

Fetch intersecting cells and check candidates.

Sources