How to know if a point is inside a polygon

Here’s a quick code snippet to know if given a point, the point is inside an array of polygon vertices. Based on the crossing number algorithm.

 

This can also be extended to 3D space if necessary, but that’s for the reader.

2 Responses to “How to know if a point is inside a polygon”

  1. Juan Sebastian says:

    No because its the end of the array, hence a <= ends on an out of index error

  2. kolenda says:

    Thank you for your code, but shouldn’t you iterate like “i <= nPoints" in the for loop? The 'i%nPoints' in array indexing seems like this was the intent.