Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rowanwins/smallest-enclosing-circle
An implementation of Welzl's algorithm for calculating the smallest enclosing circle of a set of points
https://github.com/rowanwins/smallest-enclosing-circle
bounding-circle computational-geometry smallest-enclosing-circle
Last synced: 11 days ago
JSON representation
An implementation of Welzl's algorithm for calculating the smallest enclosing circle of a set of points
- Host: GitHub
- URL: https://github.com/rowanwins/smallest-enclosing-circle
- Owner: rowanwins
- License: mit
- Created: 2019-10-31T22:40:21.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-07-21T02:56:58.000Z (over 2 years ago)
- Last Synced: 2024-10-12T04:17:26.219Z (27 days ago)
- Topics: bounding-circle, computational-geometry, smallest-enclosing-circle
- Language: JavaScript
- Homepage:
- Size: 101 KB
- Stars: 11
- Watchers: 3
- Forks: 1
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# smallest-enclosing-circle
A small module for calculating the smallest circle enclosing a series of points using Welzl's algorithm, runs in O(N) time.## Install
````
npm install smallest-enclosing-circle
````## Documentation
Valid inputs: An array of points [{x: 0, y: 0}, {x: 10, y: 10}, {x: 20, y: 20}]
````
const enclosingCircle = require('smallest-enclosing-circle')enclosingCircle([{x: 0, y: 0}, {x: 10, y: 10}, {x: 20, y: 20}])
// => { x: 10, y: 10, r: 14.142135623730951 }
````
Returns an x, y for the centre of the circle, and a radius.*Note* - the result is not 100% consistent across runs there seems to be some floating point anomolies, generally these appear to be very minor though.
*Another Note* - calculating a smallest enclosing circle isn't as fast as calculating a bounding box, it's approx 4 times slower. However there are reasons why a bounding circle is helpful :)
## Acknowledgements
This library was based on a java implementation of Welzl's algorithm by [Bastian Molkenthin](http://www.sunshine2k.de/coding/java/Welzl/Welzl.html)
[MIT Licensed](http://www.sunshine2k.de/license.html)## Further reading
[Wikipedia](https://en.wikipedia.org/wiki/Smallest-circle_problem)[Original Paper](https://link.springer.com/chapter/10.1007/BFb0038202)