Skip to content

Optimization: replace iterative Aitoff inverse with closed-form inverse#4796

Open
robertkleffner wants to merge 2 commits into
OSGeo:masterfrom
glossopoeia:feature/aitoff-closed-form
Open

Optimization: replace iterative Aitoff inverse with closed-form inverse#4796
robertkleffner wants to merge 2 commits into
OSGeo:masterfrom
glossopoeia:feature/aitoff-closed-form

Conversation

@robertkleffner

Copy link
Copy Markdown
  • AI (Copilot or something similar) supported my development of this PR. See our policy about AI tool use. Use of AI tools must be indicated.
  • Tests added
  • Added clear title that can be used to generate release notes
  • Fully documented, including updating docs/source/*.rst for new API

Justification

In a side project I've been working on, I uncovered the existence of an exact closed-form inverse for the Aitoff projection (in part thanks to an AI agent I was having help build the project). It's fairly straightforward to derive: squaring and adding the forward equations eliminates φ and λ from the right-hand side with some trig identities, leaving the identity (x/2)² + y² = α². Then α in terms of x and y, and thus derivations of φ and λ, follow directly:

α = √((x/2)² + y²)
φ = asin(y·sin α / α)
λ = 2·atan2((x/2)·sin α, α·cos α)

This replaces the nested Newton–Raphson inverse in use since 2015. The closed form matches the iterative result to machine precision, is noticeably faster, needs no special case at the poles, and returns longitudes in [−π, π] by construction.

Winkel Tripel shares this file and unfortunately has no closed-form inverse I'm aware of, despite my attempts. I also attempted seeding the Winkel Tripel iteration with the closed-form inverse, but this ended up hampering performance a bit since the iteration converges so quickly in most cases. So, its Newton–Raphson solver and verification loop are retained, and its results are unchanged.

Correctness

  • Every existing Aitoff and Winkel Tripel gie case passes unchanged.
  • Added Aitoff round-trip tests over the interior, poles, and anti-meridian, as well as explicit interior inverse tests and a domain-rejection case.

Performance

Measured on an M2 MacBook Air with test/benchmark/bench_proj_trans, inverting via a pipeline:

bench_proj_trans -l 5000000 --noise-x 2000000 --noise-y 1000000 \
  -p "+proj=pipeline +step +inv +proj=aitoff +R=6400000" 5000000 2500000

~1.8 → ~11 M coordinates/s = ~6× speedup end-to-end through proj_trans.

References

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