My question: Given a set of 2D points, enumerate all triples of points such that no other points is inside the triangle formed by those 3 points.
I'm looking for something better than this:
// The strategy is to build a couple of data structures that will enable
// us to query whether 3 points form an empty triangle in constant time.
int nCcw[N][N]; // nCcw[i][j] is the number of points p
// such that (points[i],points[j],p)
// is listed counter clockwise.
int byAngle[N][N-1]; // byAngle[i] lists all points sorted
// by their angle to point[i]
now let us answer the query
"How many points are to the left of a line draw between these two points?"
byAngle lets us answer the query "How many points are in the wedge formed by these 3 points?".
Using some inclusion/exclusion, we can answer "Is there a point within the triangle formed by these 3 points" in constant time.
Any ideas?
EDIT:
Here are is my working solution that I have so far:
Here is an outline of a O(n^3) solution.
The strategy is to build a couple of data structures that will enable us to query whether 3 points form an empty triangle in constant time.
int nCcw[N][N];// nCcw[i][j] is the number of points p such that (points[i],points[j],p) is listed counter clockwise.
int byAngle[N][N-1]// byAngle[i] lists all points sorted by their angle to point[i]
nCcw lets us answer the query "How many points are to the left of a line draw between these two points?". byAngle lets us answer the query "How many points are in the wedge formed by these 3 points?".
Using some inclusion/exclusion, we can answer "Is there a point within the triangle formed by these 3 points" in constant time.
Aucun commentaire:
Enregistrer un commentaire