您好,欢迎来到华佗小知识。
搜索
您的当前位置:首页Java判断点在多边形内算法

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; }}

  

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo0.cn 版权所有 湘ICP备2023017654号-2

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务