Skip to content

DonKarlssonSan/Delaunay.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

alt text

About

This is a JavaScript library for performing Delaunay triangulation for a set of points. It is implemented using the Bowyer-Watson algorithm.

Live demos

  • Colorful Triangle Pattern Generator, draws a pattern using canvas in the browser: live demo, (source code)
  • Striped Triangles Pattern Generator, draws striped triangles using SVG in the browser: live demo, (source code)

Installation

npm install delaunay.js

Usage

The bowyerWatson function takes two parameters:

  • superTriangle is a triangle that encloses all the points in the list, an instance of Triangle
  • pointList is a list of points, instances of Vector
let triangles = bowyerWatson(superTriangle, pointList);

A more complete example:

import { bowyerWatson, Triangle } from 'delaunay.js';
import Vector from 'vectory-lib';

function getRandomPoints() {
  let points = [];
  let nrOfPoints = 10;
  for(let i = 0; i < nrOfPoints; i++) {
    points.push(new Vector(
      Math.random() * 100,
      Math.random() * 100
    ));
  }
  return points;
}

let pointList = getRandomPoints();

let superTriangle = new Triangle(
    new Vector(-1000, 1000),
    new Vector(1000, 1000),
    new Vector(0, -1000)
);

let triangles = bowyerWatson(superTriangle, pointList);
// Do something exciting with the triangles!
  • vectory-lib is another library written by me, it contains basic vector math, exposed via the Vector JavaScript class.
  • Triangle is included in the delaunay.js library, it contains math operations on triangles like circumcenter, centroid and pointIsInsideCircumcircle which are needed by the Bowyer-Watson algorithm.

Referenses

https://en.wikipedia.org/wiki/Delaunay_triangulation

https://en.wikipedia.org/wiki/Bowyer%E2%80%93Watson_algorithm

https://en.wikipedia.org/wiki/Circumscribed_circle

About

A JavaScript library for performing Delaunay triangulation for a set of points. It is implemented using the Bowyer-Watson algorithm.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors