地图判断点是否在面里面算法

直接上代码:

一个数据对类:PairValue

 /**
 * 数据对
 * 
 */
 public class PairValue<T> {
    
    private T x;
    private T y;
    
    public PairValue(){
        
    }
    
    public PairValue(T t1, T t2) {
        this.x = t1;
        this.y = t2;
    }
    
    public T getX() {
        return x;
    }
    
    public void setX(T x) {
        this.x = x;
    }
    
    public T getY() {
        return y;
    }
    
    public void setY(T y) {
        this.y = y;
    }
  }
     isPointInArea 方法

   /***
     * 判断点是否在面里
     * points 一组点集合
     * point 判断点
     */
    public static boolean isPointInArea(List<PairValue<Double>> points, PairValue<Double> point){
        if(points == null || points.size() ==0 || point == null){
            return false;
        }
        
        List<Point2D.Double> dPoints = new ArrayList<Point2D.Double>();
        for(PairValue<Double> onePoint : points){
            dPoints.add(new Point2D.Double(onePoint.getX(), onePoint.getY()));
        }
        GeneralPath path = getGeneralPath(dPoints);
        if(path == null){
            return false;
        }
        Point2D.Double dPpoint = new Point2D.Double(point.getX(), point.getY());
        return path.contains(dPpoint);
    }
    protected static GeneralPath getGeneralPath(List<Point2D.Double> points) {
        GeneralPath path = new GeneralPath();
        if (points.size() < 3) {
         return null;
        }
        path.moveTo((float) points.get(0).getX(), (float) points.get(0).getY());
        for (Iterator<Point2D.Double> it = points.iterator(); it.hasNext();) {
         Point2D.Double point = (Point2D.Double) it.next();
         path.lineTo((float) point.getX(), (float) point.getY());
        }
        path.closePath();
        return path;
     }




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值