| ACTUAL | POLYGON | CIRCLE | |
|---|---|---|---|
| ARRIVAL | — | — | — |
| DEPARTURE | — | — | — |
| DWELL | — | — | — |
| FALSE EVENTS | — | — | — |
UNDER THE HOOD
Polygon test — ray casting
Cast a ray from the truck's GPS ping to the edge of the map and count how many fence edges it crosses. odd = inside, even = outside. It's O(n) per ping and works for any shape — including boundaries with notches, easements, and a neighbor's driveway carved out. Flip on "show the math" and watch the crossings while the truck moves.
Circle test — one distance check
Measure the ping's distance to the fence center and compare it to the radius: d < r = inside. On a real globe that distance comes from the haversine formula on lat/lon; this sandbox projects everything onto a flat local plane in meters first — which is exactly what production geofence engines do before testing millions of pings.
Why anyone cares
A fence that fires from the freeway inflates dwell time, corrupts detention data, and buries dispatchers in alerts they learn to ignore. Shrinking the radius doesn't fix it — it just trades false arrivals for missed ones (try the slider). The fix is a boundary that follows the property line. And a hand-drawn polygon is only as good as the hand that drew it — drag a green corner into the freeway and watch it start lying too.
Scale: 1 unit = 1 meter on a local planar projection anchored at 29.7215° N, 95.2810° W (Houston's East End — the plat is fictional). Exports convert back to WGS-84 lat/lon. No libraries, no map tiles: one HTML file and math from scratch.