栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在多边形PHP中查找点

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在多边形PHP中查找点

这是我从另一种语言转换为PHP的功能:

$vertices_x = array(37.628134, 37.629867, 37.62324, 37.622424);    // x-coordinates of the vertices of the polygon$vertices_y = array(-77.458334,-77.449021,-77.445416,-77.457819); // y-coordinates of the vertices of the polygon$points_polygon = count($vertices_x) - 1;  // number vertices - zero-based array$longitude_x = $_GET["longitude"];  // x-coordinate of the point to test$latitude_y = $_GET["latitude"];    // y-coordinate of the point to testif (is_in_polygon($points_polygon, $vertices_x, $vertices_y, $longitude_x, $latitude_y)){  echo "Is in polygon!";}else echo "Is not in polygon";function is_in_polygon($points_polygon, $vertices_x, $vertices_y, $longitude_x, $latitude_y){  $i = $j = $c = 0;  for ($i = 0, $j = $points_polygon ; $i < $points_polygon; $j = $i++) {    if ( (($vertices_y[$i]  >  $latitude_y != ($vertices_y[$j] > $latitude_y)) &&     ($longitude_x < ($vertices_x[$j] - $vertices_x[$i]) * ($latitude_y - $vertices_y[$i]) / ($vertices_y[$j] - $vertices_y[$i]) + $vertices_x[$i]) ) )       $c = !$c;  }  return $c;}

附加:
有关更多功能,我建议您使用此处提供的polygon.php类。使用顶点创建类,并

isInside
以测试点作为输入调用该函数,以使另一个函数解决您的问题。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/442597.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号