Created
February 5, 2020 08:54
-
-
Save suncn/506e242edf85eea8db37608c4efaff44 to your computer and use it in GitHub Desktop.
判断点是否在地理围栏中
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @param point 判断点 | |
* @param points 多边形的顶点集合 | |
* @return | |
*/ | |
public boolean pointInPoly(Point point ,Point[] points){ | |
boolean isContains=false; | |
int end=points.length-1; | |
for (int i=0;i<points.length;i++){ | |
//通过判断点的y坐标和每条边的两个端点的y坐标比较,判断点是否在这条边的中间 | |
if (point.getY()>points[i].getY()&&point.getY()<=points[end].getY()||point.getY()<=points[i].getY()&&point.getY()>=points[end].getY()){ | |
//计算交点的x坐标值,如果小于x则记为一次(只需要判断射线一侧的点个数即可) | |
if((point.getY()-points[i].getY())/(points[end].getY()-points[i].getY())*(points[end].getX()-points[i].getX())+points[i].getX()<point.getX()){ | |
isContains=!isContains; | |
} | |
} | |
//移动顶点位置 | |
end=i; | |
} | |
return isContains; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment