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's about a binary decision, I was thinking I could theoretically achieve O(log(N))
by using a decision tree.
However I have no idea how to organize the data and how the algorithm would look like to really get an answer in O(log(N))
.
While researching with this idea in mind, I've found this:
How can we find these two cases more quickly? Binary search. Just search for x in the first coordinates of points in the two chains. If it is in the chain, you have found a crossing through a vertex (and you don't have to be as careful to tell what kind of crossing, either). If x is not the coordinate of a vertex in the chain, the two nearest values to it tell you which segment the ray from (x,y) might cross. So we can test whether a point is in a convex polygon in time O(log n).
It turns out that there are data structures that can test whether a point is in an arbitrary polygon (or which of several polygons it's in) in the same O(log n) time bound. But they're more complicated, so I don't have time to describe them here; I'll talk about them at some point in ICS 164.
(http://www.ics.uci.edu/~eppstein/161/960307.html)
So do you have any ideas:
- How the data structure should look like to get it down in
O(log(N))
? - How the algorithm should look like?
log(N)
for the test itself. – Michael