spheresmooth.geometry#

geometry.py — Public spherical geometry utilities for spheresmooth

This module provides the same functionality as the exported functions in the R package spheresmooth. The functions here define the public-facing API, while internal components such as gradient and penalty computations are encapsulated inside _internal.py.

Features provided:

  • Basic vector operations (dot, cross, norm2)

  • Vector/matrix normalization (normalize_lower, normalize)

  • Spherical distance computation (spherical_dist)

  • Exponential map (exp_map, identical to the R version)

  • Geodesic path computation (geodesic_lower, geodesic)

  • Piecewise geodesic construction (piecewise_geodesic)

This module works closely with smoothing.py and follows the same piecewise-geodesic structure as the original R implementation in spheresmooth.

Functions

cross(u, v[, normalize_vec])

Compute the cross product u × v.

dot(u, v)

Compute the dot product of two vectors.

exp_map(x, v)

Exponential map on S^2.

geodesic(t, p, q, a, b)

Compute geodesic on S2 between p and q at times t ∈ [a,b].

geodesic_lower(t, p, q, a, b)

Compute a single geodesic point on S^2 between points p and q at a specific time t ∈ [a, b].

norm2(u)

Compute the L2 norm of a vector.

normalize(X)

Normalize a vector OR each row of a matrix.

normalize_lower(v)

Normalize a single vector using the L2 norm.

piecewise_geodesic(t, control_points, knots)

Replicates EXACT R behavior of piecewise_geodesic(): - Iterate segments j = 1..K-1 - For each segment, take t satisfying knots[j] <= t < knots[j+1] - Compute geodesic_lower for each t_sub in order - Append in the same order (rbind in R) - Does NOT reorder gamma to match global t order

spherical_dist(x, y)

Spherical distance between x and y on the unit sphere: