HeadlinesBriefing favicon HeadlinesBriefing.com

Hengefinder Calculates Sun-Aligned Street Phenomena Using Binary Search

Hacker News •
×

Twice yearly, Manhattan's grid creates Manhattanhenge when the sunset aligns perfectly with east-west streets. A developer at the Recurse Center built Hengefinder to calculate these alignments anywhere on Earth. The tool determines when a street's bearing matches the sun's azimuth at sunset, creating those photogenic moments framed by buildings.

The first challenge involved calculating accurate road bearings. Simple latitude-longitude differences fail because degrees of longitude represent shrinking distances toward the poles. The solution scales longitude by cos(latitude), putting both measurements in comparable units before applying atan2. This correction accounts for Earth's spherical geometry rather than assuming flat surfaces.

The second hurdle required precise timing for when the sun sits exactly on the horizon, not when it disappears below. The Astral library's astronomical sunset definition proved too late for perfect alignment. Instead, the developer implemented a boundary binary search to find the last moment the sun remains above a target altitude threshold.

Hengefinder demonstrates how seemingly simple astronomical calculations demand careful attention to geographic mathematics and temporal precision. The project transforms an urban curiosity into a globally applicable tool for predicting sun-aligned street phenomena.