Check if a point is inside a polygon

On 07/08/2018 at 07:02, xxxxxxxx wrote:

I have a closed polygon defined by a list of coordinates (x and y, 2D coordinates).

The last point connects to the first point.
I want to check if a point px,py is inside or outside of the polygon.
The scan line implementation that I have so far, is a bit too slow as it has to go through all the coordinates list.
Is there a faster way?
Any internal code that Cinema 4D already has for that?

On 08/08/2018 at 02:52, xxxxxxxx wrote:

Hi rui_mac, thanks for writing us.

With regard to your request, beside mentioning that, to my knowledge, there's no directly usable function available in the API, I'd consider to google for "testing point in triangle". You'll end mostly with pages pointing to  the Baricentric technique or the "Same-side" technique. Among those, I found them to be  well explained in this "Point in triangle test" page and the idea described can be extended to n-vertices polygons.

Best, Riccardo