Skip to content

sphere

sphere #

Great-circle separation on a sphere, shared by the solar and location metrics.

haversine_radians(latitudes_a, longitudes_a, latitudes_b, longitudes_b) #

The n × m great-circle arcs between two sets of sphere points.

The haversine form stays accurate for the small separations that dominate scheduling, where the spherical cosine rule loses precision.

Parameters:

Name Type Description Default
latitudes_a ndarray

Latitudes (or solar altitudes) of the first set, in radians.

required
longitudes_a ndarray

Longitudes (or solar azimuths) of the first set, in radians.

required
latitudes_b ndarray

Latitudes of the second set, in radians.

required
longitudes_b ndarray

Longitudes of the second set, in radians.

required

Returns:

Type Description
ndarray

The arc between every pair, in radians.

Source code in capturegraph-lib/capturegraph/scheduling/distance/sphere.py
def haversine_radians(
    latitudes_a: np.ndarray,
    longitudes_a: np.ndarray,
    latitudes_b: np.ndarray,
    longitudes_b: np.ndarray,
) -> np.ndarray:
    """The ``n × m`` great-circle arcs between two sets of sphere points.

    The haversine form stays accurate for the small separations that dominate
    scheduling, where the spherical cosine rule loses precision.

    Args:
        latitudes_a: Latitudes (or solar altitudes) of the first set, in radians.
        longitudes_a: Longitudes (or solar azimuths) of the first set, in radians.
        latitudes_b: Latitudes of the second set, in radians.
        longitudes_b: Longitudes of the second set, in radians.

    Returns:
        The arc between every pair, in radians.
    """
    delta_latitude = latitudes_b[np.newaxis, :] - latitudes_a[:, np.newaxis]
    delta_longitude = longitudes_b[np.newaxis, :] - longitudes_a[:, np.newaxis]

    chord = np.square(np.sin(delta_latitude / 2)) + (
        np.cos(latitudes_a)[:, np.newaxis]
        * np.cos(latitudes_b)[np.newaxis, :]
        * np.square(np.sin(delta_longitude / 2))
    )
    return 2 * np.arcsin(np.sqrt(np.clip(chord, 0, 1)))