Test point for its position relative to the convex hull in log(n)

后端 未结 6 1308
清歌不尽
清歌不尽 2021-01-04 05:42

I have a collection of 2D points S and I need to test if an input point q is inside or outside the convex hull of S.

Since it\

6条回答
  •  离开以前
    2021-01-04 06:24

    An alternative solution using angles:

    Pick some point C inside the convex hull using some heuristic of your choice.

    Pick some line L passing through C, for instance the line parallel to the OX axis.

    For every point P on the convex hull, calculate the angle between the line CP and L and use it to sort the convex hull points.

    Now if you want to know if some given point T is inside the convex hull, calculate the angle between the lines CT and L and using binary search look for the points in the convex hull which are just after and before it (A and B respectively).

    Now you only have to check it T is at the same side of the line AB than C (inside) or not (outside).

提交回复
热议问题