/js-convex-hull

gets the convex hull of 2D points using the "gift-wrapping" (AKA "Jarvis march") algorithm

Primary LanguageJavaScript

⚠️ NOTE: ⚠️ This project is being merged into a monorepo here. This repo will soon be archived.


Introduction

js-convex-hull gets the convex hull of a set of 2D points using the "gift-wrapping" (AKA "Jarvis march") algorithm.

Installation

npm install --save @jrc03c/js-convex-hull

Usage

Add the script to your page:

<script src="path/to/js-convex-hull.js"></script>

Or require it for use with bundlers:

const getConvexHull = require("@jrc03c/js-convex-hull")

Then call the getConvexHull function (which returns the subset of points that represents the hull), passing in an array of 2D points:

let points = [
  [0, 5],
  [7, 2],
  [-3, 8],
  [4, -5],
  ...
]

let hull = getConvexHull(points)

Check out the demo to see it in action!