# polytope-closest-point

> Computes the closest point to a polytope in arbitrary dimensions

Latest version **1.0.0** (published 2014-11-14) · BOOST license · 0 weekly downloads

## Install

```sh
npm install polytope-closest-point
pnpm add polytope-closest-point
yarn add polytope-closest-point
bun add polytope-closest-point
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2014-11-14 |
| First published | 2013-02-15 |
| Weekly downloads | 0 |
| License | BOOST |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Mikola Lysenko |
| Maintainers | mikolalysenko |
| Keywords | polytope, geometry, closest, point, triangle, line, segment, polygon, polyhedra, convex, math, 3d |

## Links

- npm: https://www.npmjs.com/package/polytope-closest-point
- Repository: https://github.com/mikolalysenko/polytope-closest-point
- Issues: https://github.com/mikolalysenko/polytope-closest-point/issues
- npm.io page: https://npm.io/package/polytope-closest-point

## Dependencies (1)

- [numeric](https://npm.io/package/numeric.md) ^1.2.6

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2014-11-14
- 0.0.0 — 2013-02-15

## README

polytope-closest-point
======================
Computes the closest point in a convex polytope to a given point.

Install
=======
Using npm, type the following command into your shell:

    npm install polytope-closest-point

Usage
=====
Here is an example of how to find the closest point to a triangle in a mesh:

    var mesh = require("bunny");
    var result = new Array(3);
    var sqr_distance = require("polytope-closest-point")(
                          mesh.cells[0],
                          mesh.positions,
                          [0,0,0],
                          result);

Which computes the closest point in the first facet of the mesh to the point `[0,0,0]`, storing the resulting point in `result` and the squared distance in `sqr_distance`.

For more examples, see test/simple.js.

### `require("polytope-closest-point")(cell, positions, x[, result])`

Computes the closest point in a polytope to `x`, storing the result in `result`.

* `cell` is a list of indices into a positions representing the vertices of the polytope.
* `positions` is an array of tuples representing the vertices of the polytope
* `x` is the point we are querying against
* `result` (optional) is the array to store the closest point in.

Returns a float representing the squared Euclidean distance from x to the polytope.  If no such point can be found, it returns Number.NaN

Notes:  For polytopes with fewer than 4 vertices, the code uses hand optimized routines derived from WildMagick.  For higher dimensions, it falls back to a general purpose quadratic programming solver that is ported from somewhat slower R/FORTRAN codes.  If you are planning on using this code to do distance queries on meshed surfaces, it is recommend you triangulate all your polygons first.

Credits
=======
Triangle/tetrahedra closest point code derived from WildMagick (c) David Eberly 1998-2012.

Other dimensions, (c) 2013 Mikola Lysenko

BOOST License.

---
_Source: https://npm.io/package/polytope-closest-point · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
