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

pts-to-graph

v0.0.253

Published

generate nearest neighbors for a set of 3d points. convert triangle mesh to graph. convert set of 3d points into an graph / ngraph.

Downloads

20

Readme

pts-to-graph

generate nearest neighbors for a set of 3d points.

convert triangle mesh to graph.

convert set of 3d points into an ngraph.

Installation

npm i pts-to-graph

Usage - list of points

var listOfPts = [];

var nPts = 1000;
var size = 1024;

for(var i=0; i<nPts; i++){
    var pt = [Math.random()*size, Math.random()*size, Math.random()*size]
    listOfPts.push(pt);
}

var minimumDist = 200; //can either set minimumDist, or leave out the parameter and set pt[i].scale=distance to have each pt have a different neighbor radius
p2g.setOfPtsNeighborsOctree(listOfPts, minimumDist); //fast - get neighbors using octree data structure [npm yaot] - 20ms
//p2g.setOfPtsNeighborsRTree(listOfPts, minimumDist); //fast - get neighbors using rtree data structure [npm rbush-3d] - 31 ms
//p2g.setOfPtsNeighborsDelaunay(listOfPts); //very slow - get neighbors using delaunay triangulation - 2144 ms on m1 mac

//var myNGraph = p2g.setOfPtsToNGraph(listOfPts); //convert points with neighbors into ngraph graph

//results
//listOfPts[0].neighbors -- array of points nearby [by reference]
//listOfPts.octree -- octree from require('yaot')
//listOfPts.rtree -- rtree from require('rbush-3d')

Usage - triangle mesh

var p2g = require('pts-to-graph');
var mesh = require('bunny');
var sop = p2g.mesh2PtsWithNeighbors(mesh);
console.log(sop);

//conver to ngraph with p2g.setOfPtsToNGraph

//      [
//         [ 1.301895, 0.122622, 2.550061, neighbors: [Array], i: '0' ],
//         [ 1.045326, 0.139058, 2.835156, neighbors: [Array], i: '1' ],
//         [ 0.569251, 0.155925, 2.805125, neighbors: [Array], i: '2' ],
//         ... ]

Usage - set of line segments

var p2g = require('pts-to-graph');

//a set of 3d pts...
var a = [0,0,0];
var b = [0,0,1];
var c = [0,1,1];
var d = [0,1,0];

//a set of 3d line segments...
var lines = [
    [a,b],
    [b,c],
    [c,d],
    [d,a]
]

// note - also works with raw coords - points get de-duplicated
// var lines = [
//     [[0,0,0],[0,0,1]],
//     [[0,0,1],[0,1,1]],
//     [[0,1,1],[0,1,0]],
//     [[0,1,0],[0,0,0]]
// ]

//linesToSetOfPtsNeighbors(lines, eps=0.01, deCleanup=true) 
//      - eps used for point de-duplicating and rtree radius padding
//      - if doCleanup=false, pt[i] will contain .origPt and .ptIndex [used internally by algorithm]
var ptsWithNeighbors = p2g.linesToSetOfPtsNeighbors(lines);
console.log(ptsWithNeighbors);
// [
//     [ 0, 0, 0, neighbors: [ [Array], [Array] ], i: '0' ],
//     [ 0, 0, 1, neighbors: [ [Array], [Array] ], i: '1' ],
//     [ 0, 1, 1, neighbors: [ [Array], [Array] ], i: '2' ],
//     [ 0, 1, 0, neighbors: [ [Array], [Array] ], i: '3' ]
// ]


// >> you can also do the reverse - convert points-with-neighbors back into list of line segments

var lines2 = p2g.setOfPtsNeighborsToLines(ptsWithNeighbors);

console.log(lines2);
// a list of line segments, made from the same points [note how they still have neighbors added]
// [
//     [
//         [ 0, 0, 0, neighbors: [Array], i: '0' ],
//         [ 0, 0, 1, neighbors: [Array], i: '1' ]
//     ],
//     [...

// >> convert a mesh into a set of lines [triangle edges become lines, eg if we want to disgard some edges before converting into a graph]

var mesh = require('bunny');
var lines3 = p2g.meshToLines(mesh);

See Also

stonks