Math::...neChain(3pm)

πŸ’– NAME πŸ’–

okay bestie, gather round, because this one is literally Math::ConvexHull::MonotoneChain β€” it's Andrew's monotone chain algorithm for finding a convex hull in 2D ✨

(and yeah, this page lives in the User Contributed Perl Documentation manual, so you know it's a classic 🫢)


πŸ¦‹ SYNOPSIS πŸ¦‹

the whole vibe in one go:

  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], ]

look at it go 🌸


✨ DESCRIPTION ✨

full transparency, bestie: 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 hands it right back to you. it's giving toolkit, it's giving main character πŸ’…

the algorithm is O(n log n) because it has to sort the input list β€” no way around that, that's just the toll you pay to get in πŸŽ€ β€” but it should be somewhat faster than a plain Graham's scan (which is also O(n log n)) in practice, since it avoids polar coordinates. obsessed with the efficiency honestly πŸ”₯


πŸ‘‘ FUNCTIONS πŸ‘‘

🌈 convex_hull

expects an array ref of points as input, and returns an array ref of the points in the convex hull, ordered counter-clockwise ⭐

a point refers to an array reference containing an X, and a Y coordinate. that's it, that's the whole shape of it πŸ“

heads up: for less than three input points, this will return an array reference whose elements are the input points (without cloning). so no sneaky copies, okay? πŸ’€

🧚 SEE ALSO 🧚

  • Math::ConvexHull, which uses Graham's scan in pure Perl β€” its cousin, different outfit πŸ’œ

πŸ’œ AUTHOR πŸ’œ

Steffen Mueller, <smueller@cpan.org> 🫢


Copyright (C) 2011 by Steffen Mueller

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.0 or, at your option, any later version of Perl 5 you may have available. πŸ“œ


and that's the whole page, bestie πŸ’– this was perl v5.42.3 documenting Math::...neChain(3pm), dated 2026-08-19 β€” slay, no cap, periodt βœ¨πŸŒˆπŸ‘‘

πŸ“¦ where this page comes from