Skip to content

Use haversine formula for great-circle distance#90

Merged
AndGem merged 1 commit into
mainfrom
fix/haversine-distance
May 20, 2026
Merged

Use haversine formula for great-circle distance#90
AndGem merged 1 commit into
mainfrom
fix/haversine-distance

Conversation

@AndGem
Copy link
Copy Markdown
Owner

@AndGem AndGem commented May 20, 2026

The spherical law of cosines loses numerical precision for short distances, since acos operates near 1.0 (the min(1, cos_val) clamp was a symptom of this). Adjacent OSM nodes are typically metres apart, so this is the dominant case for the tool.

Switch to the haversine formula, which is numerically stable for short distances. The Earth radius constant (6373000 m) is unchanged so edge lengths stay comparable to previous output.

The spherical law of cosines loses numerical precision for short
distances, since acos operates near 1.0 (the min(1, cos_val) clamp was
a symptom of this). Adjacent OSM nodes are typically metres apart, so
this is the dominant case for the tool.

Switch to the haversine formula, which is numerically stable for short
distances. The Earth radius constant (6373000 m) is unchanged so edge
lengths stay comparable to previous output.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@AndGem AndGem merged commit 05b8a5a into main May 20, 2026
2 checks passed
@AndGem AndGem deleted the fix/haversine-distance branch May 20, 2026 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant