# sromku/polygon-contains-point

Point in polygon - Check if the point inside the polygon
Switch branches/tags
Nothing to show
Latest commit e5717ff Sep 12, 2017
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea Jul 2, 2017
assets Apr 17, 2016
src Sep 12, 2017
.gitignore Jul 2, 2017

# 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

## 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()
.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()
.close()
.addVertex(new Point(2, 3)) // hole one
.close()
.addVertex(new Point(6, 6)) // hole two
.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.