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

后端 未结 6 1311
清歌不尽
清歌不尽 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:06

    You can do it in Log(h) where h is the amount of point being the already calculated hull points. It is totally false that it is bound by Log(n) although this is what is written in Wikipedia.

    You should note that Wikipedia "Convex hull algorithms" is filtered by David Eppstein which you refer. This guy prevent useful information to be added. If that guy would accept to add useful information (new algorithm) and would understand it, he will realize that you can achieve your goal in O(Log h).Please look at the Wikipedia page for the history of the page.

    In algorithm Ouellet convex Hull AVL you can use intermediate result (avl tree by quadrant) and look inside directly. You will achieve your goal in the fastest way possible (best performance: Log(h)).

    2 important points:

    • You have to identify the quadrant first. You should check if it could be a quadrant boundary itself. After, using either only root point for disjoint quadrant, or using the cross product with first and last point of quadrant to know if its to the right (in case of cross product, if no quadrant is found it is because the point can't be a hull point - no need to identify the quadrant).
    • Points are ordered by the x coordinate.

    If I could find some time, I will add an interface to my class to check/add new point dynamically. But you can do it right now: get the convex hull intermediate result and use it directly (see the 2 important points) .

提交回复
热议问题