Debian Codegraph @

lib/Math/Polygon/Transform.pod

raw
1 =encoding utf8
2
3 =head1 NAME
4
5 Math::Polygon::Transform - Polygon transformation
6
7 =head1 INHERITANCE
8
9 Math::Polygon::Transform
10 is an Exporter
11
12 =head1 SYNOPSIS
13
14 my @poly = ( [1,2], [2,4], [5,7], [1, 2] );
15
16 my $area = polygon_transform resize => 3.14, @poly;
17
18 # requires [2.00]
19 my $area = polygon_transform +{resize => 3.14}, @poly;
20
21 =head1 DESCRIPTION
22
23 This package contains polygon transformation algorithms.
24
25 =head1 FUNCTIONS
26
27 =over 4
28
29 =item B<polygon_grid>(%options|\%options, @points)
30
31 Snap the polygon points to grid points, where artifacts are removed.
32
33 -Option--Default
34 raster 1.0
35
36 =over 2
37
38 =item raster => FLOAT
39
40 The raster size, which determines the points to round to. The origin
41 C<[0,0]> is always on a grid-point. When the raster value is zero,
42 no transformation will take place.
43
44 =back
45
46 =item B<polygon_mirror>(%options|\%options, @points)
47
48 Mirror the polygon in a line. Only one of the options can be provided.
49 Some programs call this "flip" or "flop".
50
51 -Option--Default
52 b 0
53 line <C<undef>>
54 rc undef
55 x undef
56 y undef
57
58 =over 2
59
60 =item b => FLOAT
61
62 Only used in combination with option C<rc> to describe a line.
63
64 =item line => [POINT, POINT]
65
66 Alternative way to specify the mirror line. The C<rc> and C<b> are
67 computed from the two points of the line.
68
69 =item rc => FLOAT
70
71 Description of the line which is used to mirror in. The line is
72 C<y= rc*x+b>. The C<rc> equals C<-dy/dx>, the firing angle. If
73 C<undef> is explicitly specified then C<b> is used as constant x: it's
74 a vertical mirror.
75
76 =item x => FLOAT
77
78 Mirror in the line C<x=value>, which means that C<y> stays unchanged.
79
80 =item y => FLOAT
81
82 Mirror in the line C<y=value>, which means that C<x> stays unchanged.
83
84 =back
85
86 =item B<polygon_move>(%options|\%options, @points)
87
88 Returns a list of points which are moved over the indicated distance.
89
90 -Option--Default
91 dx 0
92 dy 0
93
94 =over 2
95
96 =item dx => FLOAT
97
98 Displacement in the horizontal direction.
99
100 =item dy => FLOAT
101
102 Displacement in the vertical direction.
103
104 =back
105
106 example:
107
108 my @moved = polygon_move dx => -5.12, @points;
109 my @moved = polygon_move +{dx => -5.12}, @points; # since [2.00]
110
111 =item B<polygon_resize>(%options|\%options, @points)
112
113 Make the polygon smaller or larger, with respect to a center.
114
115 -Option--Default
116 center [0,0]
117 scale 1.0
118 xscale <scale>
119 yscale <scale>
120
121 =over 2
122
123 =item center => POINT
124
125 =item scale => FLOAT
126
127 Resize the polygon with the indicated factor. When the factor is larger
128 than 1, the resulting polygon with grow, when small it will be reduced in
129 size. The scale will be respective from the center.
130
131 =item xscale => FLOAT
132
133 Specific scaling factor in the horizontal direction.
134
135 =item yscale => FLOAT
136
137 Specific scaling factor in the vertical direction.
138
139 =back
140
141 =item B<polygon_rotate>(%options|\%options, @points)
142
143 Rotate a polygon around a center.
144
145 -Option --Default
146 center [0,0]
147 degrees 0
148 radians 0
149
150 =over 2
151
152 =item center => POINT
153
154 =item degrees => FLOAT
155
156 specify rotation angle in degrees (between -180 and 360).
157
158 =item radians => FLOAT
159
160 specify rotation angle in rads (between -pi and 2*pi)
161
162 =back
163
164 =item B<polygon_simplify>(%options|\%options, @points)
165
166 Z<>
167
168 -Option --Default
169 max_points undef
170 same 0.0001
171 slope undef
172
173 =over 2
174
175 =item max_points => INTEGER
176
177 First, C<same> and C<slope> reduce the number of points. Then, if there
178 are still more than the specified number of points left, the points with
179 the widest angles will be removed until the specified maximum number is
180 reached.
181
182 =item same => FLOAT
183
184 The distance between two points to be considered "the same" point. The value
185 is used as radius of the circle.
186
187 =item slope => FLOAT
188
189 With three points X(n),X(n+1),X(n+2), the point X(n+1) will be removed if
190 the length of the path over all three points is less than C<slope> longer
191 than the direct path between X(n) and X(n+2).
192
193 The slope will not be removed around the starting point of the polygon.
194 Removing points will change the area of the polygon.
195
196 =back
197
198 =back
199
200 =head1 DIAGNOSTICS
201
202 =over 4
203
204 =item Error: you need to specify 'x', 'y', 'rc', or 'line'
205
206 Cast by polygon_mirror()
207
208 =back
209
210 =head1 SEE ALSO
211
212 This module is part of Math-Polygon version 2.00,
213 built on September 04, 2025. Website: F<http://perl.overmeer.net/CPAN/>
214
215 =head1 LICENSE
216
217 For contributors see file ChangeLog.
218
219 This software is copyright (c) 2004-2025 by Mark Overmeer.
220
221 This is free software; you can redistribute it and/or modify it under
222 the same terms as the Perl 5 programming language system itself.
223