Math::ConvexHull::MonotoneChain(3pm)

Math::ConvexHull::MonotoneChain3pm

Andrew's monotone chain algorithm for finding a convex hull in 2d

Usage

  use Math::ConvexHull::MonotoneChain 'convex_hull';
  my $ch = convex_hull(
    [
      [0, 0],
      [0, 1],
      [1, 0],
      [0.5, 0.5],
      [1, 1],
    ]
  );
  
  # $ch is now:
  # [ [0, 0],
  #   [1, 0],
  #   [1, 1],
  #   [0, 1], ]

Overview

This is somewhat experimental still.

This (XS) module optionally exports a single function "convex_hull" which calculates the convex hull of the input points and returns it. The algorithm is "O(n log n)" due to having to sort the input list, but should be somewhat faster than a plain Graham's scan (also "O(n log n)") in practice since it avoids polar coordinates.

Functions

convex_hull

Expects an array ref of points as input, returns an array ref of of the points in the convex hull, ordered counter-clockwise.

point refers to an array reference containing an X, and a Y coordinate.

For less than three input points, this will return an array reference whose elements are the input points (without cloning).

Releases

6 releases since Debian 8 (Jessie); the text changed 5 times.

  1. 8
  2. 9
  3. 10
  4. 11
  5. 12
  6. 13

Author

Steffen Mueller, <[email protected]>

From libmath-convexhull-monotonechain-perl 0.1-2+b4 in Debian 13 (Trixie). Parsed by carta from the page's man source.