determine if a point sits inside an arbitrary shape?

前端 未结 3 1444
囚心锁ツ
囚心锁ツ 2020-12-06 00:14

Given a point\'s coordinates, how can I determine if it is within an arbitrary shape?

The shape is defined by an array of points, I do not know where the shape is \'

3条回答
  •  感动是毒
    2020-12-06 00:59

    If you want to determine whether or not a point P is in an arbitrary shape, I would simply run a flood fill starting at P. If your flood fill leaves a pre-determined bounding box, you are outside the shape. Otherwise if your flood fill terminates, then you're within the shape :)

    I believe this algorithm is O(N^2) where N is the number of points, since the maximum area is proportional to N^2.

    Wikipedia: Flood Fill

提交回复
热议问题