zoukankan      html  css  js  c++  java
  • Java判断点在多边形内算法

    package algs.boundary;
    
    /**
     * Author: areful
     * Date: 2018/8/9
     */
    public class Boundary {
        private final BoundaryPoint[] points;
    
        Boundary(BoundaryPoint[] points) {
            this.points = points;
        }
    
        boolean contains(BoundaryPoint test) {
            boolean result = false;
            int i = 0;
    
            for (int j = this.points.length - 1; i < this.points.length; j = i++) {
                if (this.points[i].y > test.y != this.points[j].y > test.y
                        && test.x < (this.points[j].x - this.points[i].x) * (test.y - this.points[i].y) / (this.points[j].y - this.points[i].y) + this.points[i].x) {
                    result = !result;
                }
            }
    
            return result;
        }
    }
    

      

    package algs.boundary;
    
    /**
     * Author: areful
     * Date: 2018/8/9
     */
    public class BoundaryPoint {
        public final double x;
        public final double y;
    
        public BoundaryPoint(double x, double y) {
            this.x = x;
            this.y = y;
        }
    }
    

      

  • 相关阅读:
    .net core
    asp.net core之abp框架
    C#
    c#
    C#
    C#
    C#
    技术术语
    mysql
    006.内测.情景之迷你财务记账
  • 原文地址:https://www.cnblogs.com/areful/p/10381537.html
Copyright © 2011-2022 走看看