0

我正在尝试使用Math::Geometry::PlanarGpcClip()中的函数来查找两个多边形的交集。我通过使用构建了两个多边形,但在使用它们时出现以下错误:Math::Geometry::Planar->new();GpcClip()

在 gpc_polygon_clip 的参数 2 中键入错误。预期 _p_gpc_polygon 在 c:/strawberry/perl/site/lib/math/geometry/planar.pm 行 2028

如何将返回的对象转换Math::Geometry::Planar->new()为 GPC 多边形?

4

2 回答 2

1

根据文档,您可以使用以下convert2gpc方法:

$多边形->convert2gpc;

将多边形/轮廓转换为 gpc 结构并返回生成的 gpc 结构

例子:

use strict;
use warnings 'all';

use Math::Geometry::Planar;

my $outer = Math::Geometry::Planar->new;
my $inner = Math::Geometry::Planar->new;
$outer->points([[0, 0], [0, 3], [3, 3], [3, 0]]);
$inner->points([[1, 1], [1, 2], [2, 2], [2, 1]]);

my $diff = GpcClip('DIFFERENCE', $outer->convert2gpc, $inner->convert2gpc);
于 2016-05-12T16:31:16.987 回答
-1
use strict;
use warnings 'all';
use Data::Dumper;
use Math::Geometry::Planar;

my $outer = Math::Geometry::Planar->new;
my $inner = Math::Geometry::Planar->new;
$outer->points([[0, 0], [0, 3], [3, 3], [3, 0],[0,0]]);
$inner->points([[2, 0], [2, 2], [4, 2], [4, 0],[2,0]]);

my $diff = GpcClip('INTERSECTION', $outer->convert2gpc, $inner->convert2gpc);
#first polygon rep the outer poly, the rest of them are holes
my @pgons = Gpc2Polygons($diff);  

#since here we don't have holes, only the first one is a valid polygon 
print Dumper($pgons[0]->polygons->[0]);

#convert the points into Planar Polygon
my $result = Math::Geometry::Planar->new;
$result->points($pgons[0]->polygons->[0]);

print Dumper($result);

感谢@ThisSuitlsBlackNot 的帮助。顺便说一句,你有什么想法在多边形内找到一个随机点,这个多边形没有洞。再次感谢

于 2016-05-12T19:04:07.453 回答