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