New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

apollonius

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollonius - npm Package Compare versions

Comparing version 0.3.0 to 1.0.0

2

index.d.ts

@@ -11,6 +11,6 @@ // Type declaration for apollonius library

export default apollonius;
export function apollonius(c1: Circle2, c2: Circle2, c3: Circle2): Circle2 | null;
export function solve(c1: Circle2, c2: Circle2, c3: Circle2): Circle2 | null;
export namespace options {
export let epsilon: number;
}

@@ -216,3 +216,6 @@ const defaultEpsilon = 0.0000000001 // precision from affineplane

export { apollonius, options }
export default apollonius
// Aliases
const solve = apollonius
export { apollonius, solve, options }
export default solve
{
"name": "apollonius",
"version": "0.3.0",
"version": "1.0.0",
"description": "Solves Apollonius' problem by finding a fourth circle tangent to three given circles",

@@ -13,3 +13,3 @@ "type": "module",

"scripts": {
"build": "rollup index.js --file index.cjs --format cjs",
"build": "rollup --config",
"lint": "standard",

@@ -16,0 +16,0 @@ "test:unit": "node test/index.js",

@@ -10,5 +10,5 @@ # apollonius

The `apollonius` function finds 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 if such a circle exists and it usually does. 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 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.
Because a circle can be either internally or externally tangent to another circle, the problem of Apollonius has eight solutions, one for each combination of tangency rules of the three circles. The function here finds one solution at a time but can be used to find all eight.
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.

@@ -26,7 +26,9 @@ The function is extremely efficient. It has time complexity of O(1) and does not call any trigonometric functions.

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 apollonius function with the circles. The order of the circles does not matter.
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.
```
import apollonius from 'apollonius'
// OR const apollonius = require('apollonius').default
import * as apollonius from 'apollonius'
// OR import solve from 'apollonius'
// OR import { solve } from 'apollonius'
// OR const apollonius = require('apollonius')

@@ -39,3 +41,3 @@ // Prepare three known circles.

// Compute a fourth circle that touches the three.
const c = apollonius(c1, c2, c3)
const c = apollonius.solve(c1, c2, c3)

@@ -45,3 +47,3 @@ // Result equals { x: 4.367544..., y: 3.5, r: 1.029822... }

The result is a circle object `{ x, y, r }`. By default, the resulting circle is **externally tangent** to each of the three given circles. To find a circle that is **internally tangent** to some of the circles, specify those circles with negative radius. See below for an example.
The result is a circle object `{ x, y, r }` or `null` if such a circle cannot be found. By default, the resulting circle is **externally tangent** to each of the three given circles. To find a circle that is **internally tangent** to some of the circles, specify those circles with negative radius. See below for an example.

@@ -55,3 +57,3 @@ ```

// Compute the fourth circle.
const c = apollonius(c1, c2, c3)
const c = apollonius.solve(c1, c2, c3)

@@ -77,6 +79,11 @@ // Result equals { x: 2.732213..., y: 3.5, r: 2.523715... }

The fourth circle may reduce to a point (a circle with zero radius) in some configurations of known circles. These configurations may appear when there are:
- **identical stacked circles:** The known circles are exact copies of each other. Then the externally tangent circle reduces to an arbitrary point on the shared circumference of the known.
- **circles intersect at a single point:** The known circles share only one common point. Then the externally tangent circle reduces to that point.
## API
### apollonius(c1, c2, c3)
### apollonius.solve(c1, c2, c3)

@@ -94,6 +101,16 @@ This function finds a circle that is tangent to three other circles. If no such circle exists, it returns null.

Returns:
- an object `{ x, y, r }`.
- `null` if no circle can be found or if the radius of the circle is infinite.
- an object `{ x, y, r }` where `r` is always positive or zero.
- `null` if no tangent circle exists or if the radius of the circle is infinite.
### apollonius.options.epsilon
The function `apollonius.solve` handles various (special cases)[#specialcases] by switching to alternative algorithms when certain internal variables turn zero. However, the variables rarely exactly equal zero because of rounding errors caused by floating point arithmetics. Computation with near-zero numbers would cause arbitrary results and therefore a margin of safety is needed.
The `epsilon` defines the numerical margin in which an almost zero number is treated as zero. The default value for epsilon is `1e-10`. You can adjust it if needed. For example, if you know the properties of your circles will be large numbers then a larger epsilon may yield more robust behavior near the special cases:
```
apollonius.options.epsilon = 1e-4
```
## Contribute

@@ -100,0 +117,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc