Polygon类

1.1.0 2020-06-17 19:41 UTC

This package is auto-updated.

Last update: 2024-09-18 04:25:16 UTC


README

Build Status

一个点在多边形内算法,质心和方向计算,用PHP编写。确定(双关语)一个点是否实际上位于凸多边形或凹多边形内部。

使用方法

使用指定在GeoJSON格式中的坐标初始化Polygon对象。一个经纬度对的数组。

$coords = [
    [51.046945330263, 3.7388005491447],
    [50.884119340619, 4.7054353759129],
    [51.260385196697, 4.3696193284848],
];

$poly = new \Geometry\Polygon($coords);

$coords = $poly->getOutline();
$poly->setOutline($coords);

$centroid = $poly->centroid();
echo "the centroid of the polygon is ($centroid[0], $centroid[1]).\n";

if ($poly->isValid()) {
    echo "the polygon was succesfully created.\n";
}

if (!$poly->isClockwise()) {
    echo "the points define a counter-clockwise polygon.\n";
}

if ($poly->pip($x, $y)) {
    echo "the polygon includes ($x,$y).\n";
}

起源

于2012年Ghent Apps期间编写。

许可证

MIT