Ray casting algorithm

Page 1

Ray Casting Algorithm - Vinsol If you’ve been struggling with the problem of determining whether a point lies inside or outside a polygon, perhaps in google maps, read on. This post is specific to Android and Node.js but the algorithm can easily be implemented in any other language/platform as the algorithm itself is a piece of cake once understood. To further elaborate the problem, take a look at the diagram below:

Here we have an irregular polygon (yellow region) and points a, b, c and d. We have to programmatically determine whether these points lie inside the polygon or outside. At first glance this might sound trivial, and yes it is, but the solution provided in Google Maps api is not good enough for most of the cases. Solution provided in Google Maps api Google Maps api considers a super-rectangle that contains all the bounding points of the given polygon and then determines if the point lies inside this rectangle or not. This would work great if the polygon is close to a rectangle or square in shape but not for anything else (definitely not for our Yellow polygon above). Although their method is not as simple as it sounds. It considers the


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.