Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a Point is inside a Polygon

I've got a Polygon:

image

I want to check if the Location of an Entity is inside this Polygon.
As example x:5 and y:5, How can I make a check to see if this Coordinate is inside this Polygon (Java)?

like image 436
user1621988 Avatar asked Apr 11 '13 20:04

user1621988


People also ask

How do you check if a point is inside a polygon in Matlab?

in = inpolygon( xq , yq , xv , yv ) returns in indicating if the query points specified by xq and yq are inside or on the edge of the polygon area defined by xv and yv . [ in , on ] = inpolygon( xq , yq , xv , yv ) also returns on indicating if the query points are on the edge of the polygon area.

Is point in a polygon?

To determine the status of a point (xp,yp) consider a horizontal ray emanating from (xp,yp) and to the right. If the number of times this ray intersects the line segments making up the polygon is even then the point is outside the polygon.


1 Answers

If you create the polygon using the Polygon class that is included with java use the contains() method.

http://docs.oracle.com/javase/6/docs/api/java/awt/Polygon.html

Take a look at the method summary:

contains(int x, int y) - Determines whether the specified coordinates are inside this Polygon

like image 149
Joban Dhillon Avatar answered Sep 28 '22 11:09

Joban Dhillon