java 利用jdk的awt.geom 判断处理geo业务应用经纬度的线段相交,点在多边形区域内问题
程序员文章站
2022-04-15 18:37:57
...
//两条线段是否相交,{(0,0),(2,2)} {(2,0),(1.9,1.8)}
boolean res = Line2D.linesIntersect(0,0,2,2,2,0,1.9,1.8);
System.out.println(res);
//点是否在多边形内,{(0,0),(2,0),(2,2),(0,2),(0,0)} 测试点(1,1)
GeneralPath path = new GeneralPath();
//设定多边形起始点
path.moveTo(0,0);
path.lineTo(2,0);
path.lineTo(2,2);
path.lineTo(0,2);
//图像完成,封闭
path.lineTo(0,0);
//多边形结束
path.closePath();
System.out.println(path.contains(1,1));