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

@derschmale/tympanum

v1.3.6

Published

A Typescript library for generating multidimensional convex hulls and delaunay triangulations.

Downloads

36

Readme

Tympanum

A Typescript library for generating multidimensional convex hulls and delaunay triangulations.

Documentation

Examples:

Basic Types

Tympanum has the following building blocks to form shapes:

Any N-dimensional shape such as a simplex is a collection of Facets.

  • Facet: This is a polygonal face of dimension N-1: a line, a triangle, or a tetrahedron in 2D, 3D or 4D respectively. Each facet is bounded by a set of ridges.
  • Ridge: This is an edge of dimension N-2: a point (vertex), a line (edge), or a triangle in 2D, 3D or 4D respectively. A ridge has N-1 vertices (ie: 1 vertex, 2 line end points, 3 triangle corners).
  • Vertex: These are represented as an index into a list of points (fe: the list of points used to generate a convex hull). This is so that we can easily map points to other data sets from which the points were extracted, or they can be used to construct 3D meshes for use in WebGL.

Convex Hull

To generate a convex hull using the quickHull algorithm:

import { quickHull } from "@derschmale/tympanum";

const points = [];

for (let i = 0; i < 5000; ++i) {  
    points[i] = [Math.random(), Math.random(), Math.random()];
}

const hull = quickHull(points);

hull will contain an array of Facet.

Delaunay Triangulation

To generate the delaunay triangulation:

import { delaunay } from "@derschmale/tympanum";

const points = [];

for (let i = 0; i < 500; ++i) {  
    points[i] = [Math.random(), Math.random(), Math.random()];
}

const triangulation = delaunay(points);

triangulation will contain an array of Facet, but of a higher dimension than the convex hull would.

Delaunay triangulations allow searching for facets containing a point efficiently using the vibility walk algorithm:

import { visibilityWalk } from "@derschmale/tympanum";

const pos = [ 0.5, 0.2, 0.7 ];
const facet = visibilityWalk(pos, triangulation, points);

When a facet has been found, we can calculate the point's barycentric coordinates. The barycentric coordinates can be used to interpolate values associated to each respective point.

import { barycentricCoords } from "@derschmale/tympanum";

// for example: every point has an RGB color assigned to it:
let colors = [];

// any color at index N is associated with the point at points[N]
for (let i = 0; i < 5000; ++i) {  
    colors[i] = { 
      r: Math.random() * 0xff, 
      g: Math.random() * 0xff, 
      b: Math.random() * 0xff
    };
}

if (facet) {
  const bary = barycentricCoords(pos, facet, points);
  const color = { r: 0, g: 0, b: 0 };
  
  for (let i = 0; i < bary.length; ++i) {
    // get the index of the point
    let index = facet.verts[i];
  
    // get the color at that index
    let c = colors[index];
    
    // add the weighted colors together
    color.r += bary[i] * c.r; 
    color.g += bary[i] * c.g; 
    color.b += bary[i] * c.b; 
  }
}