d3-polygon
Operations for two-dimensional polygons.
Last updated 8 years ago by mbostock .
BSD-3-Clause · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install d3-polygon 
SYNC missed versions from official npm registry.

d3-polygon

This module provides a few basic geometric operations for two-dimensional polygons. Each polygon is represented as an array of two-element arrays [​[x1, y1], [x2, y2], …], and may either be closed (wherein the first and last point are the same) or open (wherein they are not). Typically polygons are in counterclockwise order, assuming a coordinate system where the origin ⟨0,0⟩ is in the top-left corner.

Installing

If you use npm, npm install d3-polygon. You can also download the latest release on GitHub. For vanilla HTML in modern browsers, import d3-polygon from Skypack:

<script type="module">

import {polygonHull} from "https://cdn.skypack.dev/d3-polygon@3";

const hull = polygonHull(points);

</script>

For legacy environments, you can load d3-polygon’s UMD bundle from an npm-based CDN such as jsDelivr; a d3 global is exported:

<script src="https://cdn.jsdelivr.net/npm/d3-polygon@3"></script>
<script>

const hull = d3.polygonHull(points);

</script>

API Reference

# d3.polygonArea(polygon) <>

Returns the signed area of the specified polygon. If the vertices of the polygon are in counterclockwise order (assuming a coordinate system where the origin ⟨0,0⟩ is in the top-left corner), the returned area is positive; otherwise it is negative, or zero.

# d3.polygonCentroid(polygon) <>

Returns the centroid of the specified polygon.

# d3.polygonHull(points) <>

Returns the convex hull of the specified points using Andrew’s monotone chain algorithm. The returned hull is represented as an array containing a subset of the input points arranged in counterclockwise order. Returns null if points has fewer than three elements.

# d3.polygonContains(polygon, point) <>

Returns true if and only if the specified point is inside the specified polygon.

# d3.polygonLength(polygon) <>

Returns the length of the perimeter of the specified polygon.

Current Tags

  • 3.0.1                                ...           latest (4 years ago)
  • 2.0.0-rc.1                                ...           next (4 years ago)

20 Versions

  • 3.0.1                                ...           4 years ago
  • 3.0.0                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 2.0.0-rc.1                                ...           4 years ago
  • 1.0.6                                ...           5 years ago
  • 1.0.5                                ...           6 years ago
  • 1.0.4                                ...           6 years ago
  • 1.0.3                                ...           8 years ago
  • 1.0.2                                ...           8 years ago
  • 1.0.1                                ...           8 years ago
  • 1.0.0                                ...           8 years ago
  • 0.3.0                                ...           9 years ago
  • 0.2.1                                ...           9 years ago
  • 0.2.0                                ...           9 years ago
  • 0.1.0                                ...           9 years ago
  • 0.0.5                                ...           9 years ago
  • 0.0.4                                ...           9 years ago
  • 0.0.3                                ...           9 years ago
  • 0.0.2                                ...           9 years ago
  • 0.0.1                                ...           9 years ago
Maintainers (2)
Downloads
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (5)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |