apollonius
Advanced tools
Comparing version 1.1.0 to 1.2.0
{ | ||
"name": "apollonius", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Solves Apollonius' problem by finding a fourth circle tangent to three given circles", | ||
"type": "module", | ||
"main": "./index.js", | ||
"main": "./dist/index.cjs", | ||
"module": "./index.js", | ||
"types": "./index.d.ts", | ||
"exports": { | ||
"import": "./index.js", | ||
"require": "./index.cjs" | ||
"require": "./dist/index.cjs" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
@@ -32,2 +36,3 @@ "build": "rollup --config", | ||
"apollonius", | ||
"apollonian", | ||
"tangent", | ||
@@ -46,2 +51,3 @@ "math", | ||
"devDependencies": { | ||
"@rollup/plugin-terser": "^0.4.4", | ||
"rollup": "^4.24.0", | ||
@@ -48,0 +54,0 @@ "standard": "^17.1.2", |
@@ -9,5 +9,6 @@ # apollonius | ||
![NPM Type Definitions](https://img.shields.io/npm/types/apollonius?color=green) | ||
![Dependency status](https://img.shields.io/badge/dependencies-none-lightgrey) | ||
The `apollonius` module provides a function to find a circle that touches three known circles. The resulting circle is a solution to the [Problem of Apollonius](https://en.wikipedia.org/wiki/Problem_of_Apollonius). In other words, it finds a circle that is *tangent to* each of the known three circles. The function is robust: the three known circles can be placed freely and are allowed to overlap each other. | ||
The `apollonius` module provides a function to find a circle that touches three known circles. The resulting circle is an exact solution to the [Problem of Apollonius](https://en.wikipedia.org/wiki/Problem_of_Apollonius) also known as *Apollonian problem*. In other words, it finds a circle that is *tangent to* each of the known three circles. The function is robust: the three known circles can be placed freely and are allowed to overlap each other. | ||
@@ -18,7 +19,9 @@ Because a circle can be either internally or externally tangent to another circle, the problem of Apollonius has eight solutions in total, one for each combination of tangency rules of the three circles. The function here finds only one solution per call but can be used to find all eight. | ||
[Installation](#installation) – [Usage](#usage) – [API](#api) – [Contribute](#contribute) | ||
## Usage | ||
Install via [NPM](https://www.npmjs.com/package/apollonius) or [Yarn](https://yarnpkg.com/package?name=apollonius): | ||
## Installation | ||
Install via [NPM](https://www.npmjs.com/package/apollonius) or [Yarn](https://yarnpkg.com/package?name=apollonius). The package supports [CommonJS](https://en.wikipedia.org/wiki/CommonJS), [ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules), and [UMD](https://github.com/umdjs/umd) module formats and ships with [TypeScript](https://www.typescriptlang.org/) type declarations. | ||
``` | ||
@@ -28,10 +31,35 @@ $ npm install apollonius | ||
Specify your three known circles as `{ x, y, r }` objects, where `x` and `y` are the circle center coordinates and `r` is the radius. Then call the function `apollonius.solve` with the circles. The order of the circles does not matter. | ||
Then import the module in one of the following ways: | ||
``` | ||
// ESM wildcard | ||
import * as apollonius from 'apollonius' | ||
// OR import solve from 'apollonius' | ||
// OR import { solve } from 'apollonius' | ||
// OR const apollonius = require('apollonius') | ||
// ESM default export | ||
import solve from 'apollonius' | ||
// ESM named export | ||
import { solve } from 'apollonius' | ||
// CommonJS module | ||
const apollonius = require('apollonius') | ||
``` | ||
Alternatively, install via a [script tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script). Download the minified UMD bundle `apollonius-1.2.3.min.js` at [releases](https://github.com/axelpale/apollonius/releases) or at [unpkg.com](https://www.unpkg.com/apollonius@1.2.0/dist/apollonius.min.js) and host it alongside your HTML: | ||
``` | ||
<script src="apollonius-1.2.3.min.js" defer></script> | ||
<script> | ||
document.addEventListener('DOMContentLoaded', () => { | ||
// ... | ||
var c = apollonius.solve(...) | ||
}) | ||
</script> | ||
``` | ||
The bundle declares the global variable `window.apollonius`. Above we wrote the script tag with [defer](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#defer) to allow browsers to continue parsing the page while loading the bundle. The `DOMContentLoaded` event is fired after the browser has loaded all the asset files. The usage of `defer` and `DOMContentLoaded` is not required but is a good convention when your app has lots of assets. | ||
## Usage | ||
Specify your three known circles as `{ x, y, r }` objects, where `x` and `y` are the circle center coordinates and `r` is the radius. Then call the function `apollonius.solve` with the circles. The order of the circles does not matter. | ||
``` | ||
// Prepare three known circles. | ||
@@ -62,7 +90,7 @@ const c1 = { x: 3, y: 2, r: 1 } | ||
The code above is illustrated below: | ||
The circle configuration above is illustrated as follows: | ||
![Figure: Internally Tangent Circles](doc/example_internal.png "The result circle must be internally tangent to the circles 1 and 3 and externally tangent to the circle 2.") | ||
The resulting circle is internally tangent to the known circles `c1` and `c3` and externally tangent to the known circle `c2`. Note that while the known circles can have negative radii, the output circle always has positive or zero radius. | ||
The resulting circle `c` is internally tangent to the known circles `c1` and `c3` and externally tangent to the known circle `c2`. Note that while the known circles can have negative radii, the output circle always has positive or zero radius. | ||
@@ -141,4 +169,13 @@ | ||
## Acknowledgements | ||
The following tools, works, and projects had important role in the development of the package. | ||
- [Maxima](https://maxima.sourceforge.io/) symbolic algebra tookit was used during formulation of the algorithm. | ||
- [Affineplane](https://github.com/axelpale/affineplane) geometry library provided reference to data structures and documentation. | ||
- [A theorem on circle configurations](https://arxiv.org/abs/0706.0372) by *Jerzy Kocik* provided general insight to the theory of the problem and its special cases. | ||
## License | ||
The apollonius source code is released under [MIT](LICENSE) license. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
177
20673
5
5
229
1