Determine whether a point lies in a convex hull in O(log n) time [duplicate]

喜你入骨 提交于 2019-12-23 07:05:22

问题


I've researched several algorithms for determining whether a point lies in a convex hull, but I can't seem to find any algorithm which can do the trick in O(logn) time, nor can I come up with one myself.Let a[] be an array containing the vertices of the convex hull, can I pre-process this array in anyway, to make it possible to check if a new point lies inside the convex hull in O(logn) time.


回答1:


Looks like you can.

  1. Sort vertices in a[] by polar angle relative to one of vertices (call it A). O(N log N), like convex hull computation.
  2. Read point, determine its polar angle. O(1)
  3. Find two neighbor vertices, one of them should have polar angle less than point from step 2, and other should have angle bigger (B and C). O(log N), binary search
  4. Then simple geometry: draw the triangle between points from A, B, C and check if point from step 2 lies inside. O(1)


来源:https://stackoverflow.com/questions/28801832/determine-whether-a-point-lies-in-a-convex-hull-in-olog-n-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!