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

triangles-distance-fast

v1.0.76

Published

signed or unsigned distance function for triangles using r-tree and/or bvh and/or kd-tree

Downloads

35

Readme

triangles-distance-fast

signed or unsigned distance to triangles mesh using rtree and/or bvh tree

uses bvh-tree-plus for the bvh tree and rbush-3d for the rtree.

we use the rtree to quickly get a list of triangles potentially inside a bounding box, and the bvh tree to determine if a point is inside/outside the mesh via raycasting.

npm i triangles-distance-fast
//triangle = [[x,y,z],[x,y,z],[x,y,z]]
//aabb = [[x,y,z],[x,y,z]] //axis aligned bounding box, [min, max]

//newest, no need for dist limit
// trianglesDistanceKnn(pt, triangles, nNeighbors=10, trisRTree)

//older ones 
// trianglesDistance(tris, radius, rtree?) // unsigned distance function(x,y,z) sampling over radius, use optional cached rtree - returns >9999 if no triangles within radius
// trianglesDistance_signed(tris, radius, rtree?, bvh?) // signed distance function(x,y,z) sampling over radius, use optional cached rtree and bvh tree - returns abs() > 9999 if no triangles within radius
// trianglesDistanceStable(pt, triangles, trisRTree, eps=0.1, S=1000) unsigned, sampling over 3 narrow bounding boxes along the XYZ axis 
// trianglesDistanceBruteForce(pt, triangles) //brute force / naive approach, testing each triangle
// trianglesIntersectingAABB(tris, aabb, rtree?) // get set of triangles whose bounding boxes intersect the aabb
// triangles2RTree(tris) //get rtree for triangles 
// triangles2BvhTree(tris) //get bvh for triangles 
// trianglesFlatten(tris) //flatten tris into 1-d float32 array

// funcs using a kd-tree based on loading triangle verts [note that searching using the vertices of the triangles rather than 'bounding volumes' may introduce edge cases that the r-tree does not]
// trianglesDistance_KdTree(tris, maxDist=Infinity, existingTree) //unsigned dist using a kd tree
// triangles2KdTree(tris) //convert tris to static-kdtree

// stochastic kd tree generates random pts on the surface of the mesh rather than just using the triangle verts 
// trianglesDistance_KdTree_stochastic(tris, radius=Infinity, _existingStochasticTreeDescriptor=null, nPtsSampler=tris.length*5)
// triangles2KdTreeStochastic(tris, nPtsToSample, skipAddVerts = false) //result may be less 'biased' if we dont add the triangle verts themselves

var tdf = require('triangles-distance-fast'); 
var fs = require("fs");
var stl = require('stl');
var path = require('path');

//load tris from stl file
var triangles = stl.toObject(fs.readFileSync(path.join(__dirname,'Bitey_Reconstructed_5k.stl'))).facets.map(function(f){return f.verts});

//make distance function
var df = tdf.trianglesDistance(triangles,20.0);

//use it
var dist = df(10,10,10);
console.log(dist); //5.114792068071368

//returns >9999 if nothing found within the radius [or < -9999 if using signed distance inside mesh]

stonks