Skip to the workspace
Pebellslearn by building
Computational Geometry  ›  Lesson

Capstone: Meridian's Coverage Map

50 minCombine this section's convex hull with the shoelace formula to report a depot's actual service area, not just a list of stops

dsa / Capstone: Meridian's Coverage Map

Explore each scene at your own pace.

01 · A depot's service boundary, with a number attached

A depot's service boundary, with a number attached

Capstone: Meridian's Coverage Map

Definition
This capstone builds the convex hull of a depot's stops to get its service boundary, then applies the shoelace formula, which sums cross terms of consecutive vertices and halves the absolute value, to find the area that boundary encloses.
In plain words
Draw a fence around the outermost stops, then measure how much ground it covers. The fence is the hull, and the shoelace formula turns its corner coordinates into a single area figure for the dashboard.

In short: this capstone puts two things from this section together into one report a depot manager would actually read. The convex hull (lesson 3) turns a scattered list of stops into the boundary Meridian's service area actually draws on the map. The shoelace formula turns that boundary into one number: the area it encloses, found from the vertices alone — sum x_i * y_{i+1} - x_{i+1} * y_i around every edge, take the absolute value, halve it. No new geometry idea here, just the orientation test and the hull it builds, read all the way through to a number a dashboard can show.

A depot's eight stops plotted on a coordinate plane, five of them connected by a solid boundary line labelled "coverage boundary" and shaded lightly inside, with the three interior stops marked as dots with no line touching them and a small area readout in the corner

A depot's service boundary, with a number attached

Eight of Meridian's stops, four of them sitting inside wherever the others end up:

step through it
1def orientation(a, b, c):
2 cross = (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0])
3 if cross > 0:
4 return 1
5 if cross < 0:
6 return -1
7 return 0
8 
9def half_hull(points):
10 hull = []
11 for p in points:
12 while len(hull) >= 2 and orientation(hull[-2], hull[-1], p) <= 0:
13 hull.pop()
14 hull.append(p)
15 return hull
16 
17def convex_hull(points):
18 pts = sorted(set(points))
19 if len(pts) < 3:
20 return pts
21 lower = half_hull(pts)
22 upper = half_hull(list(reversed(pts)))
23 return lower[:-1] + upper[:-1]
24 
25def shoelace_area(polygon):
26 n = len(polygon)
27 total = 0
28 for i in range(n):
29 x1, y1 = polygon[i]
30 x2, y2 = polygon[(i + 1) % n]
31 total += x1 * y2 - x2 * y1
32 return abs(total) / 2
33 
34def coverage_report(stops):
35 hull = convex_hull(stops)
36 area = shoelace_area(hull)
37 return hull, area
38 
39stops = [(0, 0), (8, 0), (8, 6), (0, 6), (4, 3), (2, 5), (6, 1), (3, 7)]
40print(coverage_report(stops))

Five stops make the boundary; three — (4,3), (2,5), (6,1) — sit inside it and never show up in hull at all. The area comes out to exactly 52.0, found without ever drawing anything: just the hull's five vertices, fed through one formula.

Scene 1 of 5
Project context and further resources
You're building a piece ofMeridian — service areas & coverage
This piece — coverage_report(): Reports a depot's service boundary and the area it covers, over a real stop set.
Scenario A depot manager wants one report: here is the boundary your stops actually draw on the map, and here is how much ground it covers.
Additional resources
coverage_report.py
Call the function you wrote — just like your app's frontend would. Edit the inputs and hit Call.
coverage_report(stops) → tupleThe depot's service boundary (convex hull of its stops) and the area it covers.
try:
returned
Press Run to execute your code.
Press Check to run the tests for this lesson.
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.