einarsrud/point-in-polygon

点在多边形内

v1.0.2 2020-10-28 12:26 UTC

This package is not auto-updated.

Last update: 2024-09-26 18:58:45 UTC


README

Winding Number算法的实现。用于检查一个点是否在多边形内部。

安装

使用Composer安装

$ composer require einarsrud/point-in-polygon

用法

// Import the classes
use Raconteur\PointInPolygon\Polygon;
use Raconteur\PointInPolygon\Point;

// Create polygon points
$polygonPoints = [];
$polygonPoints[] = new Point(0, 0);
$polygonPoints[] = new Point(4, 0);
$polygonPoints[] = new Point(2, 4);
$polygonPoints[] = new Point(0, 4);

// Create a Polygon
$polygon = new Polygon($polygonPoints);

// Check if a Point is in a polygon
$pointInPolygon = $polygon->pointInPolygon(new Point(1,1));