Skip to content
Advertisement

How to know if a point is inside an arbitrary contour in Javascript?

I have some SVG arbitrary closed shapes composed of lines and curve paths. I want to check if some points are inside the shape. I have found Point in Polygon algorithm that seems to work well, but I will have to decompose my path into a multitude of lines. Is there a more direct solution to this problem? If not, what good algorithm I can use to decompose my paths?

Advertisement

Answer

Let me demonstrate how to use isPointInFill by this live code.

JavaScript
JavaScript

If isPointInStroke is used instead, the third point will be the one that turns to red.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement