cga.js is a collection of basic computational geometry algorithms written in javascript. A couple algorithms include the convex hull of points, line intersection, triangulation, and polygon expansion. It also contains many of the smaller algorithms found in Computational Geometry in C by Joseph O'Rourke
The library contains small functions that help calculate geometry properties of points, lines and shapes. The example below shows how to calculate the convex hull of a nested array of 2D points:
// Given an array of points in cartesian coordinates [x,y]
var positions = [[x,y],[x,y],[x,y],...];
var cga = require('cga');
// This function will return a list of indices the represents the convex hull
var results = cga.convexHull2(positions);
The example below shows how to triangulate a simple polygon made from a nested array of 2D points:
// Given an array of points in cartesian coordinates [x,y]
var positions = [[x,y],[x,y],[x,y],...];
var cga = require('cga');
// This function will return a nested array of triangle vertex indices.
var results = cga.triangulatePolygon2(positions);
The example below shows how to offset a simple polygon made from a nested array of 2D points:
// Given an array of points in cartesian coordinates [x,y]
var positions = [[x,y],[x,y],[x,y],...];
var cga = require('cga');
// This function will return a nested array of triangle vertex indices.
var results = cga.expandPolygon(positions);
This library is part of a larger project / series of libraries that aspires to bring computational and parametric design to the web. This library aspires to be the mathematical mind that powers all types of complex geometry operations that enable higher level computational design, 3d printing, g-code generation, cnc milling tool path creation, laser cutting paths, robotic motion planning, and more.
node.js (4.4.0+) & npm
You can add this library to your project by running:
npm install --save https://github.com/YCAMInterlab/cga.js.git
or via npm:
npm install --save cga
See https://github.com/rezaali/webgl-sketches/tree/master/hull
Copyright 2015-2016 Reza Ali co-developed by YCAMInterLab during the Guest Research Project v.3
Apache-2.0