AArcNerine
Workflows

Coding workflows · Unit-sphere central angles

03
Built around your work

A concrete starting point

Return the central angle in radians between two unit-sphere positions with latitudes within ±90 and longitudes within ±180 degrees. Test coincident and antipodal points, rejecting nonfinite coordinates rather than assuming an Earth radius.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Unit-sphere central angles

A concrete starting point
from math import asin, cos, isfinite, radians, sin, sqrt
def central_angle(lat1, lon1, lat2, lon2):
    values = (lat1, lon1, lat2, lon2)
    if any(type(x) not in (int, float) or not -limit <= x <= limit
           or not isfinite(x) for x, limit in zip(values, (90, 180, 90, 180))):
        raise ValueError("bounded finite coordinates")
    p, q = radians(lat1), radians(lat2)
    a = sin((q-p)/2)**2 + cos(p)*cos(q)*sin(radians(lon2-lon1)/2)**2
    return 2 * asin(sqrt(min(1.0, max(0.0, a))))

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗