polygon-contains-point

Point in polygon - Check if the point inside the polygon

  • 所有者: sromku/polygon-contains-point
  • 平台:
  • 许可证: Other
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

polygon-contains-point

The point-in-polygon (PIP) problem asks whether a given point in the plane lies inside, outside, or on the boundary of a polygon.
Wiki reference: Point in polygon

Latest Release

:inbox_tray: Download - polygon-1.0.2.jar

:bookmark_tabs: Changelog - https://github.com/sromku/polygon-contains-point/releases/latest

Algorith

The number of intersections for a ray passing from the exterior of the polygon to any point; if odd, it shows that the point lies inside the polygon. If it is even, the point lies outside the polygon.

Usage

Build Polygon

This is the simple version of the polygon. You can build both types of polygons: concave and non-convex

Polygon polygon = Polygon.Builder()
        .addVertex(new Point(1, 3))
        .addVertex(new Point(2, 8))
        .addVertex(new Point(5, 4))
        .addVertex(new Point(5, 9))
        .addVertex(new Point(7, 5))
        .addVertex(new Point(6, 1))
        .addVertex(new Point(3, 1))
        .build();

Build Polygon with Holes

First build all the border sides of the polygon. Close the borders and then you can start adding holes into the polygon.
You can add multiple number of holes, just remember to close() after each added hole.

Polygon polygon = Polygon.Builder()
        .addVertex(new Point(1, 2)) // polygon
        .addVertex(new Point(1, 6))
        .addVertex(new Point(8, 7))
        .addVertex(new Point(8, 1))
        .close() 
        .addVertex(new Point(2, 3)) // hole one
        .addVertex(new Point(5, 5))
        .addVertex(new Point(6, 2))
        .close() 
        .addVertex(new Point(6, 6)) // hole two
        .addVertex(new Point(7, 6))
        .addVertex(new Point(7, 5))
        .build();

Check if the point inside

Point point = new Point(4.5f, 7);
boolean contains = polygon.contains(point);

Tests

Two main tests are attached (not in junit format). Both tests cover polygons with holes and without.

License

Apache 2.0. See LICENSE

Follow us

Twitter URL
Twitter Follow

主要指标

概览
名称与所有者sromku/polygon-contains-point
主编程语言Java
编程语言Java (语言数: 1)
平台
许可证Other
所有者活动
创建于2013-03-01 21:39:56
推送于2019-03-25 17:10:36
最后一次提交2017-09-12 09:29:28
发布数1
最新版本名称1.0.2 (发布于 )
第一版名称1.0.2 (发布于 )
用户参与
星数296
关注者数17
派生数101
提交数19
已启用问题?
问题数12
打开的问题数6
拉请求数2
打开的拉请求数2
关闭的拉请求数4
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?