The SphericalPolygon package is an archive of scientific routines for handling spherical polygons. Currently, operations on spherical polygons include:
- Calculate the area or mass(if the area density is given)
- Calculate the perimeter
- Identify the centroid
- Compute the geometrical or physical moment of inertia tensor
- Determine whether one or multiple points are inside the spherical polygon
On Linux, macOS and Windows architectures, the binary wheels can be installed using pip by executing one of the following commands:
pip install sphericalpolygon
pip install sphericalpolygon --upgrade # to upgrade a pre-existing installation
Spherical polygons can be created from a 2d array in form of [[lat_0,lon_0],..,[lat_n,lon_n]]
with unit of degrees, or from a boundary file, such as those in Plate boundaries for NNR-MORVEL56 model. The spherical polygon accepts a latitude range of [-90,90] and a longitude range of [-180,180] or [0,360].
from sphericalpolygon import Sphericalpolygon
# build a spherical polygon for Antarctica Plate
polygon = Sphericalpolygon.from_file('NnrMRVL_PltBndsLatLon/an',skiprows=1)
print(polygon)
<SphericalPolygon | ORIENTATION='Counterclockwise', NorthPoleInside=False, SouthPoleInside=True>
Calculate the area(or the solid angle) of a spherical polygon over a unit sphere.
print(polygon.area())
1.4326235943514618
Calculate the mass of the spherical polygon shell with a thickness of 100km and density of 3.1g/cm3 over the Earth.
from astropy import units as u
Re = 6371*u.km
thickness, density = 100*u.km, 3.1*u.g/u.cm**3
rho = thickness * density # area density
print(polygon.area(Re,rho))
18026399988.685192 km3 g / cm3
Calculate the perimeter of a spherical polygon over a unit sphere.
print(polygon.perimeter())
6.322665941435134
print(polygon.compactness())
0.39900007344929683
Identify the centroid of a spherical polygon over a unit sphere.
print(polygon.centroid())
(-83.61081032380652, 57.80052886741478, 0.13827778179537864)
It shows that the centroid is close to the South Pole.
Compute the geometrical moment of inertia tensor of a spherical polygon over a unit sphere. The tensor is symmetrical and has six independent components. The first three components are located diagonally, corresponding to
print(polygon.inertia())
[ 1.32669154 1.17471081 0.36384484 -0.05095381 0.05246122 0.08126929]
Compute the physical moment of inertia tensor of the spherical polygon shell over the Earth.
print(polygon.inertia(Re,rho))
[ 6.77582335e+17 5.99961081e+17 1.85826792e+17 -2.60236820e+16
2.67935659e+16 4.15067357e+16] g km5 / cm3
Determine if a single point or multiple points are inside a given spherical polygon.
print(polygon.contains_points([[75,152]]))
[False]
print(polygon.contains_points([[-85,130],[35,70]]))
[True, False]
- 1.2.3 — Aug 22, 2025
inside_polygon
is fully vectorized to handle multiple points and a single polygon efficiently.
- 1.2.2 — Mar 3, 2021
- Add the
compactness()
method, which reflects the deviation of a polygon from a spherical cap.
- Add the
- 1.2.1 — Feb 23, 2021
- Replace the function create_polygon for building a spherical polygon object from a 2d array with methods
from_array
andfrom_file
.
- Replace the function create_polygon for building a spherical polygon object from a 2d array with methods
- 1.2.0 — Mar 20, 2020
- Add the
perimeter()
method that may calculate the perimeter of a spherical polygon. - Add the
centroid()
method that may determaine the centroid location for a spherical polygon.
- Add the
Chunxiao, Li. "Inertia Tensor for MORVEL Tectonic Plates." ASTRONOMICAL RESEARCH AND TECHNOLOGY 13.1 (2016).