Giter VIP home page Giter VIP logo

quickhull3d's Introduction

quickhull3d

NPM version Build Status Codecov Status FOSSA Status

A robust quickhull implementation to find the convex hull of a set of 3d points in O(n log n) ported from John Lloyd implementation

Additional implementation material:

This library was incorporated into ThreeJS!. Thanks to https://github.com/Mugen87 for his work to move the primitives to ThreeJS primitives, the quickhull3d library will always be library agnostic and will operate with raw arrays.

Features

  • Key functions are well documented (including ascii graphics)
  • Faster than other JavaScript implementations of convex hull

Demo

Edit mQ7AgN1n

Installation

$ npm install --save quickhull3d

Usage

var qh = require('quickhull3d')

qh(points, options)

params

  • points {Array} an array of 3d points whose convex hull needs to be computed
  • options {Object} (optional)
  • options.skipTriangulation {Boolean} True to skip the triangulation of the faces (returning n-vertex faces)

returns An array of 3 element arrays, each subarray has the indices of 3 points which form a face whose normal points outside the polyhedra

Constructor

var QuickHull = require('quickhull3d/dist/QuickHull')

instance = new QuickHull(points)

params

  • points {Array} an array of 3d points whose convex hull needs to be computed

instance.build()

Computes the quickhull of all the points stored in the instance

time complexity O(n log n)

instance.collectFaces(skipTriangulation)

params

  • skipTriangulation {Boolean} (default: false) True to skip the triangulation and return n-vertices faces

returns

An array of 3-element arrays (or n-element arrays if skipTriangulation = true) which are the faces of the convex hull

Example

import qh from 'quickhull3d'
const points = [
  [0, 1, 0],
  [1, -1, 1],
  [-1, -1, 1],
  [0, -1, -1]
]

qh(points)
// output:
// [ [ 2, 0, 3 ], [ 0, 1, 3 ], [ 2, 1, 0 ], [ 2, 3, 1 ] ]
// 1st face:
//   points[2] = [-1, -1, 1]
//   points[0] = [0, 1, 0]
//   points[3] = [0, -1, -1]
//   normal = (points[0] - points[2]) x (points[3] - points[2])

Using the constructor:

import QuickHull from 'quickhull3d/dist/QuickHull'
const points = [
  [0, 1, 0],
  [1, -1, 1],
  [-1, -1, 1],
  [0, -1, -1]
];
const instance = new QuickHull(points)
instance.build()
instance.collectFaces()   // returns an array of 3-element arrays

Benchmarks

Specs:

MacBook Pro (Retina, Mid 2012)
2.3 GHz Intel Core i7
8 GB 1600 MHz DDR3
NVIDIA GeForce GT 650M 1024 MB

Versus convex-hull

// LEGEND: program:numberOfPoints
quickhull3d:100 x 6,212 ops/sec 1.24% (92 runs sampled)
convexhull:100 x 2,507 ops/sec 1.20% (89 runs sampled)
quickhull3d:1000 x 1,171 ops/sec 0.93% (97 runs sampled)
convexhull:1000 x 361 ops/sec 1.38% (88 runs sampled)
quickhull3d:10000 x 190 ops/sec 1.33% (87 runs sampled)
convexhull:10000 x 32.04 ops/sec 2.37% (56 runs sampled)
quickhull3d:100000 x 11.90 ops/sec 6.34% (34 runs sampled)
convexhull:100000 x 2.81 ops/sec 2.17% (11 runs sampled)
quickhull3d:200000 x 5.11 ops/sec 10.05% (18 runs sampled)
convexhull:200000 x 1.23 ops/sec 3.33% (8 runs sampled)

quickhull3d vs convexhull

License

Copyright (c) 2015 Mauricio Poppe. Licensed under the MIT license.

FOSSA Status

quickhull3d's People

Contributors

mauriciopoppe avatar fossabot avatar

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.