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

后端 未结 3 1138
悲&欢浪女
悲&欢浪女 2021-01-18 07:42

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?

相关标签:
3条回答
  • 2021-01-18 08:22

    Update: this is now part of d3-polygon.

    d3.polygonContains(polygon, point)
    
    0 讨论(0)
  • 2021-01-18 08:29

    No, there is no function for this. The only very special case when there is support for this would be checking whether the point is the centroid of the polygon (using the polygon.centroid function), but in general you'll have to provide your own function.

    0 讨论(0)
  • 2021-01-18 08:45

    Here's an implementation, in case you'd rather not roll your own. Demo here.

    0 讨论(0)
提交回复
热议问题