Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

algorithm to define a geofence and see if a point is inside/outside it

I am looking for an algorithm through I can create a geofence and check if a device is entering/leaving the fence. I have looked at point in polygon algorithms (ray casting and winding number) but are there any algorithms which can be applied to circle and any irregular shapes as well? The important constraint is time efficiency.

Thank you.

like image 920
Nilgiri Avatar asked Jun 01 '12 18:06

Nilgiri


2 Answers

Here is the c code algorithm that is simple to understand:

http://alienryderflex.com/polygon/

like image 75
Josh C Avatar answered Sep 19 '22 19:09

Josh C


Well circles are pretty easy (at least if you are assuming a locally flat surface) - just absolute distance from a point.

The normal way if you need speed is a cascade where you check a circle first, or a square around the point, then a convex polygon, then a more detailed polygon if necessary.

How are you defining the irregular shape - if it's not a polygon?

ps see How to test if a point is inside of a convex polygon in 2D integer coordinates?

like image 26
Martin Beckett Avatar answered Sep 18 '22 19:09

Martin Beckett