1Math::Polygon::Calc(3)User Contributed Perl DocumentationMath::Polygon::Calc(3)
2
3
4
6 Math::Polygon::Calc - Simple polygon calculations
7
9 Math::Polygon::Calc
10 is a Exporter
11
13 my @poly = ( [1,2], [2,4], [5,7], [1, 2] );
14
15 my ($xmin, $ymin, $xmax, $ymax) = polygon_bbox @poly;
16
17 my $area = polygon_area @poly;
18 MY $L = polygon_perimeter @poly;
19 if(polygon_is_clockwise @poly) { ... };
20
21 my @rot = polygon_start_minxy @poly;
22
24 This package contains a wide variaty of relatively easy polygon
25 calculations. More complex calculations are put in separate packages.
26
28 polygon_area(@points)
29 Returns the area enclosed by the polygon. The last point of the
30 list must be the same as the first to produce a correct result.
31
32 The algorithm was found at
33 <http://mathworld.wolfram.com/PolygonArea.html>, and sounds:
34
35 A = abs( 1/2 * (x1y2-x2y1 + x2y3-x3y2 ...)
36
37 polygon_bbox(@points)
38 Returns a list with four elements: (xmin, ymin, xmax, ymax), which
39 describe the bounding box of the polygon (all points of the polygon
40 are within that area.
41
42 polygon_beautify( [\%options], @points )
43 Polygons, certainly after some computations, can have a lot of
44 horrible artifacts: points which are double, spikes, etc. The
45 optional HASH contains the %options.
46
47 -Option --Default
48 remove_spikes <false>
49
50 remove_spikes => BOOLEAN
51 Spikes contain of three successive points, where the first is on
52 the line between the second and the third. The line goes from
53 first to second, but then back to get to the third point.
54
55 At the moment, only pure horizontal and pure vertical spikes are
56 removed.
57
58 polygon_centroid(@points)
59 Returns the centroid location of the polygon. The last point of
60 the list must be the same as the first to produce a correct result.
61
62 The algorithm was found at
63 http://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon
64
65 polygon_clockwise(@points)
66 Be sure the polygon points are in clockwise order.
67
68 polygon_contains_point($point, @points)
69 Returns true if the point is inside the closed polygon. On an edge
70 will be flagged as 'inside'. But be warned of rounding issues,
71 caused by the floating-point calculations used by this algorithm.
72
73 polygon_counter_clockwise(@points)
74 Be sure the polygon points are in counter-clockwise order.
75
76 polygon_distance($point, @polygon)
77 [1.05] calculate the shortest distance between a point and any
78 vertex of a closed polygon.
79
80 polygon_equal( \@points1, \@points2, [$tolerance] )
81 Compare two polygons, on the level of points. When the polygons are
82 the same but rotated, this will return false. See polygon_same().
83
84 polygon_format($format, @points)
85 [1.07] Map the $format over all @points, both the X and Y
86 coordinate. This is especially useful to reduce the number of
87 digits in the stringification. For instance, when you want
88 reproducible results in regression scripts.
89
90 The format is anything supported by printf(), for instance "%5.2f".
91 Or, you can pass a code reference which accepts a single value.
92
93 polygon_is_clockwise(@points)
94 polygon_is_closed(@points)
95 polygon_perimeter(@points)
96 The length of the line of the polygon. This can also be used to
97 compute the length of any line: of the last point is not equal to
98 the first, then a line is presumed; for a polygon they must match.
99
100 This is simply Pythagoras.
101
102 $l = sqrt((x1-x0)^2 + (y1-y0)^2) + sqrt((x2-x1)^2+(y2-y1)^2) + ...
103
104 polygon_same( \@points1, \@points2, [$tolerance] )
105 Compare two polygons, where the polygons may be rotated wrt each
106 other. This is (much) slower than polygon_equal(), but some
107 algorithms will cause un unpredictable rotation in the result.
108
109 polygon_start_minxy(@points)
110 Returns the polygon, where the point which is closest to the left-
111 bottom corner of the bounding box is made first.
112
113 polygon_string(@points)
114
116 This module is part of Math-Polygon distribution version 1.10, built on
117 January 03, 2018. Website: http://perl.overmeer.net/CPAN/
118
120 Copyrights 2004-2018 by [Mark Overmeer]. For other contributors see
121 ChangeLog.
122
123 This program is free software; you can redistribute it and/or modify it
124 under the same terms as Perl itself. See http://dev.perl.org/licenses/
125
126
127
128perl v5.34.0 2021-07-22 Math::Polygon::Calc(3)