Let A and B be two sets of points, each consisting of n points, all lying in unit square S.
I am trying to find a efficient algorithm for finding the largest disk D such that:
(i) The center of D lie in S.
(ii) The interior of D is empty.
(iii) The boundary of D touches atleast one point from A and one point from B.
Im having a real problem with this question. Any hints will be usefull.
To complete Yves Daoust's partial solution, compute the Voronoi diagram (which is dual to the Delaunay triangulation) bounded by S. We can find an optimal circle center at some Voronoi vertex (i.e., a point in the interior of S where the nearest three points in A ∪ B are equidistant, or a point on the boundary of S where the nearest two points in A ∪ B are equidistant) where one of the nearest points is in A and another is in B.
Such a vertex is clearly feasible as a center. If we try to take any other center, then we can apply stark's observation. This center must be equidistant from a point in A and a point in B, so assuming that A ∩ B is empty (I really don't want to think about the degenerate cases; we can always perturb our way out), we can slide the center along the perpendicular bisector of AB until we hit either a third point or the boundary.
Related
Let P be a simple, but not necessarily convex, polygon and q an arbitrary
point not necessarily in P.
Design an efficient algorithm to find a line segment originating from q that intersects the minimum number of edges of P.
If q is your point in the space of 2D, we can write q(x,y). We know that a polyhedron have the edges(E), vertices(V) and faces(F) which all of this terms are related with the formula V - E + F = 2 from the Euler's theorem but the problem turns out to be easier since it is for a polygon.
So the plain is to find an edge and calcule the direction vector of the point q(x,y) to the center of the edge, doing this (and if the polygon is convex) we are sure that this line segment will only goes through one edge of P.
The calculation will need a little of linear algebra, but it is not that difficult, for example:
1 - Find the distance from a line to a point (so we can find the closest edge to use in this problem):
2 - Also, a good idea would be to find the point on this line which is closest to (x0,y0) has coordinates:
Where the equation of the line is ax + by + c = 0 and the (x0,y0) is an arbitrary point not necessarily in P.
So, now we can find the point k(x,y) on the line that is closest to the initial point q(x0,y0), doing |q-k| = d. Where d is the distance that we just calculate. After that you already have everything that you need to find a line segment originating from q that intersects the minimum number of edges of P.
Some places where you can study and find more about this topic:
Wiki
mathwords
Think of doing this on a map, so you can think of directions like North, South, East, West, and bearings.
If you have a ray going in a particular direction from q out to infinity, whether it intersects a line between points A and B depends only on the bearing of the ray, and the bearings from q to A and B: if the bearing of the ray is within the range spanned by the bearing from q to A and the bearing from q to B, taking this in the direction of the line, then the ray will intersect the line.
So you can reduce this to a simpler problem. Imagine that all the points are in a circle around q, and the lines are arcs of this circle. Now you need to find a point on this circle which is overlapped by the minimum number of arcs. You will also make life very much easier if you divide each arc that spans 0 degrees into two at 0, cutting e.g. an arc from 320 degrees round to 40 degrees into one from 320 degrees to 360=0 degrees, and one from 0 degrees to 40 degrees.
Good candidate points for this are points just clockwise of each point in the circle. Now order each arc so that it is from a low angle to a high angle, sort the arcs by low angle, and work through them in order, incrementing a counter when you see the start of an arc, and decrementing it when you see the end of an arc (you don't need to worry about arcs that wrap across 0=360 degrees because you have just made sure that there aren't any). The point you want to find is the one associated with the smallest value of the counter.
Taking q as the origin of the coordinates, compute the polar arguments of the vertices. This is done in linear time.
Then every edge spans an interval of angles. To handle the wraparound, you can split the intervals that cross the 360° border.
You turned the problem in an instance of 1D intervals overlap. This is readily solved in O(N Log(N)) time.
Let's examine this picture a bit.
Basically we follow the well-known steps: we sort the points, we separate the array of points in half and we recursively compute the smallest distance from the right side and from the left side.
And we consider δ as being the minimum of the two computed distances.
Let's consider a point p, from the left side. Now we have these assumptions:
"All points from the right side, within δ distance of p reside in a δ x 2δ rectangle, R. If each pair is at least δ apart, then there are at most 6 points inside R".
These assumptions are a bit ambiguous.
1. Where exactly should we place the rectangle? Should A be the projection of p on the border?
2. The 6 points "inside" R are actually the vertices and 2 of the midpoints of the rectangle?
3. Why are the 3 points inside the red circle candidates? The distance from A to the ones that are vertices is δ√2 > δ. And if we consider the distance between p and A being x, then the distance between p and the other point (the midpoint) would be x + δ > δ.
Source: https://www.cs.ucsb.edu/~suri/cs235/ClosestPair.pdf
The rectangle shall be placed in region P2, and yes, A shall be a projection of p on the border. The left side of the rectangle shall coincide with the median line.
The 6 points are the maximum number of points that can be found in the region R because the minimum distance between any two pairs of points is delta. If there are 6 points then yes the location of those points shall be as you described.
There can be a case where p coincides with A. Hence we know that except the two right-most vertex points, all the other 4 points can be valid candidates. Now the points on the vertex cannot by themselves be candidates but they act as the boundaries for points that we should consider as candidates.
I want to determine whether a given triangle intersects a tetrahedron. I do not want to compute the solution polygon(if it exists) itself. Is there any library/package/published practical algorithm which can be used to solve this problem directly(unlike my attempt below)?
I think as a last resort I will have to use standard polygon-polygon intersection algorithm implementations to solve this problem indirectly.
My attempt on this problem:
I thought of breaking it into the problem of polygon-polygon intersection. So for each triangular face(say T1) of the tetrahedron and the given triangle T2, I thought of doing the following:
Compute intersection(a line) between planes corresponding to each triangle, say L1.
For each triangle:
For each edge of the triangle say L2, compute point of intersection P between L1 and L2.
Test(maybe using parametric form) of L2, if the point lies on the edge L2.
If for both triangles T1 and T2, there exists at least one edge on which the intersection point P lies, then it implies that the triangles(and hence the given tetrahedron and the triangle T2) do intersect.
Create an orthonormal frame based on the triangle (origin at some vertex, axis X using the direction of some side, axis Y and Z using the direction of another side and Gram-Schmidt formulas).
Transform the coordinates of the 3 + 4 vertices to the new frame.
If all Z of the 4 tetrahedron vertices are of the same sign, there is no intersection. Otherwise, find the 3 or 4 intersection point of the edges into XY, by linear interpolation on Z.
Now you need to check for intersections between a triangle and a triangle or (convex) quadrilateral, in 2D. You can solve that by means of a standard clipping algorithm, made simple by convexity of the polygons.
As an easy optimization, note that it is useless to compute the Z of the triangle vertices (=0), and the XY of the tetrahedron vertices before you know that there is a possible intersection.
You can also speedup the polygon intersection process by first using a bounding box test.
I just found a function in CGAL library CGAL::do_intersect(Type1< Kernel > obj1,Type2< Kernel > obj2 ) for computing intersection between two geometric objects. It permits Type1 and Type2 to be Triangle_3<Kernel> and Tetrahedron_3<Kernel> respectively.
In
http://en.wikipedia.org/wiki/Closest_pair_of_points_problem
we can see that it mentions that is at most 6 points that is closest to the point on the other half, which can be represented as the graph below:
My question is for point P1 and Point P2, the distance to the red point will exceed sqrt(2)*d, why it is part of the solution? Why it is not at most 4 points that is closest to P rather than at most 6 points? Thanks.
P1 and P2 are not part of the solution, but they have to be examined on the way to the solution, because the algorithm examines all points in the box, and P1 and P2 are in the box.
Note that no such point as your Q can exist, because by hypothesis the minimum distance between points in the right-hand half of the diagram is d.
Edited to add: you seem to think that the Wikipedia article is making a claim like this:
There may be up to 6 points on the right side of the line that are within a distance d of P.
This claim would be false. But the article does not make such a claim. Instead, it makes two separate claims, both of which are true:
All the points on the right side of the line that are within a distance d of P are inside the box.
There may be up to 6 points in the box.
We are only counting the maximum number of points that can lie in the right d x 2d rectangle. Since any two points are constrained to have a minimum distance of d, we can place at most 6 points in the rectangle while satisfying this constraint, as shown in the figure.
Note that the points on the right side that are within d distance from P should all lie within a circular segment of a circle centered at P and whose radius is d. There can be at most 4 points in this segment. However, finding the number of points within a segment is more complicated than finding the number of points within a rectangle. So we use the rectangle instead and incur an extra cost of having to search for at most 2 additional points.
The bound is only important for complexity estimation. Code-wise, you may simply scan up and down within the distance dRmin. The bound here suggest that you'll at most see 6 points in each such scan, making this O(1).
Given a list of N points in the plane in general position (no three are collinear), find a new point p that is not collinear with any pair of the N original points.
We obviously cannot search for every point in the plane, I started with finding the coincidence point of all the lines that can be formed with the given points, or making a circle with them something.. I dont have any clue how to check all the points.
Question found in http://introcs.cs.princeton.edu/java/42sort/
I found this question in a renowned algorithm book that means it is answerable, but I cannot think of an optimal solution, thats why I am posting it here so that if some one knows it he/she can answer it
The best I can come up with is an N^2 algorithm. Here goes:
Choose a tolerance e to control how close you're willing to come to a line formed from the points in the set.
Compute the convex hull of your set of points.
Choose a line L parallel to one of the sides of the convex hull, at a distance 3e outside the hull.
Choose a point P on L, so that P is outside the projection of the convex hull on L. The projection of the convex hull on L is an interval of L. P must be placed outside this interval.
Test each pair of points in the set. For a particular line M formed by the 2 test points intersects a disc of radius 2e around P, move P out further along L until M no longer intersects the disc. By the construction of L, there can be no line intersecting the disk parallel to L, so this can always be done.
If M crosses L beyond P, move P beyond that intersection, again far enough that M doesn't pass through the disc.
After all this is done, choose your point at distance e, on the perpendicular to L at P. It can be colinear with no line of the set.
I'll leave the details of how to choose the next position of P along L in step 5 to you,
There are some obvious trivial rejection tests you can do so that you do more expensive checks only with the test line M is "parallel enough" to L.
Finally, I should mention that it is probably possible to push P far enough out that numerical problems occur. In that case the best I can suggest is to try another line outside of the convex hull by a distance of at least 3e.
You can actually solved it using a simple O(nlogn) algorithm, which we will then improve to O(n). Name A the bottom most point (in case of tie choose the one that is has smaller x coordinate). You can now sort in clockwise order the rest of the points using the CCW. Now as you process each point from the sorted order you can see that between any two successive points having different angle with point A and the bottom axis (let these be U, V) there is no point having angle c, with U <= c <= V. So we can add any point in this section and it is guaranteed that it won’t be collinear with any other points from the set.
So, all you need is to find one pair of adjacent points and you are done. So, find the minimum and the second minimum angle with A (these should be different) in O(n) time and select any point in between them.