Code Monkey home page Code Monkey logo

cga.js's Introduction

Computational Geometry Algorithms in Javascript

Synopsis

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

Code Example

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);

Motivation

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.

Build Requirements

node.js (4.4.0+) & npm

Installation

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

Examples

See https://github.com/rezaali/webgl-sketches/tree/master/hull

Contribution

Copyright 2015-2016 Reza Ali co-developed by YCAMInterLab during the Guest Research Project v.3

License

Apache-2.0

cga.js's People

Contributors

rezaali avatar konnokeina avatar

Stargazers

 avatar SHUKE avatar L.E. avatar Feifei He avatar IAY avatar zhiqing pan avatar İlker Demir  avatar Jimmy Shen avatar Mark P avatar Darrel Ronald avatar Nico avatar huangdade avatar  avatar WellsLiao avatar  avatar  avatar Mike Abolarin avatar  avatar Christodoulos Fragkoudakis avatar Tristan Schlötel avatar Siavash Habibi avatar  avatar asdass avatar LeekingWeng avatar  avatar Daniel Clarke avatar Avneesh Sarwate avatar  avatar Yihan Kim avatar Paul G avatar Totoro avatar Ashish Sarode avatar Max(im) Beketov avatar Rob Sawyer avatar liuyan avatar Alberto Harres avatar ◢◢ avatar Alejandro V. Rojas avatar  avatar wandergis avatar Yuki Kodama avatar Ayumu Nagamatsu avatar Alexander Rulkens avatar Simon Willmann avatar Diego Montesinos avatar Mike Luan avatar Alberto avatar RJ Duran avatar Jose Luis Garcia del Castillo avatar George Mandis avatar Zac Ioannidis avatar Szymon Kaliski avatar Jinjin-Tao avatar Tim Pulver avatar Mark Hindess avatar Mark Moissette avatar 子龙 avatar zhoubo avatar Gottfried Haider avatar  avatar Tom avatar Dimitrie Stefanescu avatar Yannick Assogba avatar  avatar Kurt Ward avatar AKA avatar  avatar Marshall Jones avatar Davide Prati avatar Mikhail Dudarev avatar Giulian Drimba avatar Ryan avatar  avatar Seth avatar 2bit avatar mactkg avatar

Watchers

Takayuki Ito avatar James Cloos avatar mincau avatar  avatar zhoubo avatar  avatar

cga.js's Issues

Infinite loop from triangulatePolygon2

The following code hangs in an infinite loop:

const cga = require("cga")
cga.triangulatePolygon2([[392,114],[216,179],[159,295],[215,267]])

As far as I know, this is a pretty normal polygon:

screen shot 2018-07-02 at 2 24 50 am

I'm not sure what's going on.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.