npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

polytope-closest-point

v1.0.0

Published

Computes the closest point to a polytope in arbitrary dimensions

Downloads

344,247

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.