Calculate the smallest enclosing circle of a point cloud on a (hemi)sphere in linear time with a Welzl-type algorithm.
Project description
secots - smallest enclosing circles on the sphere
Given a point cloud on a sphere this Python package computes center and radius of the smallest (spherical) circle enclosing the point cloud. The algorithm takes linear time and automatically detects whether the point cloud is contained in a hemisphere. If so, the smalles enclosing circle is returned. Else, an exception is raised.
See A simple linear time algorithm for smallest enclosing circles on the (hemi)sphere for details on the algorithm.
Installation
Run
pip install secots
or copy secots.py
from this repo to your working directory.
Usage
Put your point cloud into a list of longitude-latitude pairs or into a corresponding (n, 2)-shaped NumPy array. Then call secots.smallest_circle(points)
. This will return three floats: longitude and latitude of the circle's center as well as the radius. Example:
import secots
points = [
(-30, 10),
(0, 20),
(20, -40),
(10, 10),
(20, 30)
]
lon, lat, r = secots.smallest_circle(points)
print(f'center: ({lon}, {lat}), radius: {r}')
More examples are in the repo's example
directory.
The smallest_circle
function raises NotHemisphereError
if the point cloud is not contained in a hemisphere. In this case the algorithm is not able to compute a smallest enclosing circle. See above mentioned paper for details.
The smallest_circle
function accepts an additional keyword argument hemitest
. Use hemitest=False
if you are very sure that your point cloud is contained in a hemisphere. This saves (an almost negligible amount of) computation time. Example:
lon, lat, r = secots.smallest_circle(points, hemitest=False)
Contributing
Open a GitiHub issue for bug reports. File pull requests against the dev
branch.
The dev
branch contains the code for next release, whereas the main
branch holds the current release.
Licence
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file secots-0.1.1.tar.gz
.
File metadata
- Download URL: secots-0.1.1.tar.gz
- Upload date:
- Size: 1.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24c51127938c7a160e361c0b562bfa0a729f9e23c8671f1127ba7c7058ae253b |
|
MD5 | 08f670e6fee264624828981bff2ff85b |
|
BLAKE2b-256 | f5b4afcad75e6435f44715cd6d5ad811ddb5726ce3ae47436173e6cf95a9f825 |
File details
Details for the file secots-0.1.1-py2.py3-none-any.whl
.
File metadata
- Download URL: secots-0.1.1-py2.py3-none-any.whl
- Upload date:
- Size: 29.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5442d6d26912a8054ce82244801ae4a566f293bf18e061810646e3dced4cec8 |
|
MD5 | a91a655a07def6319e88e5afdc0fb907 |
|
BLAKE2b-256 | 290ea962c2af7821316ba9fd396ac602ca07ca9afa0e242e51f9016f8c564ff7 |