Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/brunoimbrizi/circumcircle

Fast algorithm to calculate the circumcircle of a triangle
https://github.com/brunoimbrizi/circumcircle

Last synced: 17 days ago
JSON representation

Fast algorithm to calculate the circumcircle of a triangle

Awesome Lists containing this project

README

        

circumcircle
============

Fast algorithm to calculate the circumcircle of a 2D triangle.

[![demo](https://user-images.githubusercontent.com/880280/98715483-23e71700-2382-11eb-9026-65e09b46ff50.png)](https://brunoimbrizi.github.io/circumcircle/demo/index.html)

## Install
```
npm install circumcircle
```

## Example
```js
const circumcircle = require('circumcircle');

const points = [ [0.0, -0.5], [0.5, 0.5], [-0.5, 0.5] ];
console.log(circumcircle(points));
```
Output:

```js
{ x: 0, y: 0.125, r: 0.625 }
```

## Demo

[circumcircle demo](https://brunoimbrizi.github.io/circumcircle/demo/index.html)

## Usage

### `circumcircle(points, radiusSq = false)`

- `points` an array with 3 points `[ [x,y], [x,y], [x,y] ]`

- `radiusSq` returns the radius squared - faster because it skips `Math.sqrt()`

**Returns** an object with circumcenter and circumradius `{ x, y, r }`

## Credits

[Lingjia Liu](https://gist.github.com/mutoo/5617691) and [Joseph O'Rourke](https://web.archive.org/web/20071030134248/http://www.exaflop.org/docs/cgafaq/cga1.html)

## See Also

- [circumradius](https://github.com/mikolalysenko/circumradius)
- [circumcenter](https://github.com/mikolalysenko/circumcenter)

## License

MIT, see [LICENSE](LICENSE) for details.