判断点是否在圆内 和 多边形内

/***
 * 判读一个点是否在多边形内 返回boolean  true存在   false不存在
 * @param point
 * @param polygon
 * @return
 */
public boolean checkWithJdkPolygon(Point2D.Double point, List<Point2D.Double> polygon) {
    java.awt.Polygon p = new Polygon();
    final int TIMES = 1000;
    for (Point2D.Double d : polygon) {
        int x = (int) d.x * TIMES;
        int y = (int) d.y * TIMES;
        p.addPoint(x, y);

    }
    int x = (int) point.x * TIMES;
    int y = (int) point.y * TIMES;
    return p.contains(x, y);
}

/**
 *  判读一个点是否在圆内 返回boolean  true存在   false不存在
 */
private boolean isInCircle(double r,float centerX1,float centerY1,float x2,float y2)
{
    double distance=Math.sqrt((y2-centerY1)*(y2-centerY1)+(x2-centerX1)*(x2-centerX1));
    if(distance>r){
        return false;
    }
      else
    {return true;}
    }

猜你喜欢

转载自blog.csdn.net/weixin_33207551/article/details/86539002