Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find if point is inside polygon in d3.js

Tags:

d3.js

I know there are manual ways of doing this (see Point in Polygon), but is there a native way of determining whether a point is inside a polygon, in d3.js?

like image 567
Gabriel Florit Avatar asked Nov 07 '12 22:11

Gabriel Florit


People also ask

How do you check if a point is within a polygon?

Draw a horizontal line to the right of each point and extend it to infinity. Count the number of times the line intersects with polygon edges. A point is inside the polygon if either count of intersections is odd or point lies on an edge of polygon.

How do you check if a point is inside a polygon in Python?

How to check if a point is inside a polygon in Python. To perform a Point in Polygon (PIP) query in Python, we can resort to the Shapely library's functions . within(), to check if a point is within a polygon, or . contains(), to check if a polygon contains a point.


1 Answers

Update: this is now part of d3-polygon.

d3.polygonContains(polygon, point)
like image 126
Gabriel Florit Avatar answered Oct 07 '22 23:10

Gabriel Florit