Determine translations of a polygon whose self-intersections are complicated - computational-geometry

This is a question in 2-dimensional computational geometry.
Suppose I have a compact set X in the plane which has no holes (i.e. it is simply connected). Let w be a vector, and consider the intersection of X with X+w (i.e. the translate of X by w). I say that this intersection is complicated if the following is true:
X intersects X+w
If we let Y be the simply-connected region obtained from (X union X+w) by filling in the bounded holes, then as we walk around the boundary of Y we can find 4 points in cyclic order a,b,c,d on the boundary so that a and c are in X but not in X+w, while b and d are in X+w but not in X.
Just for the sake of brevity, let's refer to the set of w for which the intersection of X with X+w is complicated as the concave hull of X (note: this has nothing to do with alpha sets; it's just a name).
I would like to know a fast, practical algorithm to compute the concave hull of X where X is (say) a polygonal disk. Beyond this, I would be interested in an elegant characterization of the concave hull perhaps in different terms. Finally, I would be very grateful for pointers to any literature discussing this problem.
Here are some remarks:
The concave hull of X is empty if and only if X is convex (hence the name); this is because if X is convex, and X intersects X+w, then the boundary of Y falls into exactly two components, one of which is in X, and the other in X+w (the converse follows from point 3 below).
The concave hull of a polygon should be an open polygon (i.e. with the boundary removed), so the answer could be given (for example) as a finite union of (open) triangles.
If X is nonconvex, we can find part of the concave hull as follows: let L be a supporting line for X which intersects X in two sets P and Q with a gap I between them. If J is the segment of the boundary of X between P and Q, then the union of I and J bounds an open disk D in the complement of X, and if p+ is the extreme point of P closest to Q, then D-p+ is in the concave hull. Call the union of such regions over all supporting lines the inner concave hull; it seems relatively easy to compute, but I think it should be smaller than the concave hull in general.

Related

Maximum enclosing disk

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.

Testing tetrahedron-triangle intersection

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.

Algorithm to Calculate the Number of Lattice Points in a Polygon

I'm trying to find the number of lattice points that strictly lie inside the boundary. I know Pick's theorem is
A = i + b/2 - 1
where A = the area of the polygon, i is the number of lattice points that lie inside the polygon, and b is the number of lattice points on the perimeter of the polygon.
I can easily find the area using the Shoelace formula, but I'm not sure how to get the points on the boundary.
I'm not really sure where to look for resource on this, so I'd appreciate links too.
What a pretty question...
Since you are talking about Pick's Theorem, I will assume all of the vertices have integer coordinates.
Your question reduces to determining how many lattice points lie on the line segment from (x1, y1) to (x2, y2). Since the answer stays the same under translation by an integer, this reduces to determining how many lattice points lie on the line segment from (0, 0) to (x, y) for arbitrary x and y.
If x=0 or y=0, the answer is 1D and trivial (i.e. x+1 or y+1).
Otherwise, the answer is gcd(x,y) + 1. You prove this by showing (a) that any lattice point between (0,0) and (x,y) must be a multiple of the "least" lattice point; and (b) that any lattice point must have coordinates that are factors of (x,y).
Finally, be careful not to double-count the vertices as you walk around the polygon.

Robust polygon normal calculation

is there a good robust algorithm to calculate normal vector of a convex polygon (in 3D, of course)? For triangles, it is easy: one takes two of the triangle's edges and calculates the cross product:
vec3 u = point[0] - point[1], v = point[0] - point[2];
vec3 n = normalize(cross(u, v));
But this approach does not really extend to polygons very well. Some edges of the polygon can be nearly or "exactly" collinear (this will happen often in meshes where T-Junction removal took place), therefore it is necessary to choose a pair of edges, giving a "strong" normal (both edges are "long enough" and they hold "almost perpendicular" angle).
This approach will still not work for all polygons, though. Imagine a polygon in the shape of a disc. If it is very finely subdivided, all the edges will be very short and all of the consecutive edges will be almost collinear, regardless of the radius of the disc. At the same time, the normal is very well defined.
One solution could be to find the largest inscribed triangle and to calculate the normal of that. However, finding it will have complexity of O(n^2), which seems prohibitive.
A better solution could be to use SVD or Eigenvalue decomposition to calculate the normal, given all the polygon points, not just three or four.
Is there a standard algorithm for this? Anyone has a good way of doing it?
If you factorize the formula for a triangle, you'll get the following:
n ~ (p1 - p0) x (p2 - p0)
= p0 x p1 + p1 x p2 + p2 x p0
You can generalize this formula for arbitrary polygons:
n ~ p0 x p1 + p1 x p2 + ... + pn x p0
So sum the cross product of consecutive edges. This is a robust algorithm and works for non-planar polygons.
If you can be sure that the polygon is planar, I would do the following (to save computation time):
Repeat k times
Pick 3 random polygon vertices
Calculate the normal of the according triangle
Choose the longest normal as the polygon's normal.
You might discard any normal that has a length <= epsilon.
start from an arbitrary vertex(lets call it vertex A), and move to the next vertex in the list(call it vertex B). calculate the perpendicular vector(call it vector P) to the AB vector. Then continue iterating in the vertex list to find the vertex that is perpendicularly the most distant from vector AB. So at each iteration take the dot product of the current element(take vertex B as the origin) with the vector P and take the one that has the greatest result in magnitude(take absolute value) and call it C. calculate the cross product of A B C vectors.
if the poly is convex you can stop iterating untill the perpendicular distances starts to
get smaller in magnitude.
I came up with this idea, i do not know how efficient this method would be since I do not know any other algorithm to compare with.
You can calculate the covariance matrix for all the points of the polygon (which will be a 3x3 matrix for 3D space). The normal to the polygon will be the Eigen vector corresponding to the smallest Eigen value.

Prove that the farthest point among a set of points(in 2-d plane) should lie on the convex hull

The question speaks for itself. It is required to prove that given a set of 2-d points, the pair of points farthest from each other must lie on the convex hull.
A point A is on the convex hull if there exists a line through it for which all points in your set of points are on the same side of this line. For the two points farthest away from each other in a set, A and B, you can prove that this holds for the lines perpendicular to A and B, through A and B.
Adding few more details to the answer above.
Claim 1: The point(P) with minimum y-coordinate will always lie on the convex hull of a set of N points.
Proof: Let's assume that the point(P) with minimum y-coordinate lies strictly inside the convex hull. Then there would exist a point(Q) on the convex hull such that Qy < Py, thereby contradicting the assumption that that point P has the minimum y-coordinate.
Claim 2: A point A is on the convex hull if and only if there exists a line through it for which all points in the set of points are on the same side of the line.
Proof: (Only if condition) Consider the point P with minimum y coordinate. From Claim 1, point P lies on the convex hull and the line passing through P parallel to x-axis satisfies the criteria that all other points of set S lies above it. Now for any other point(P') on the convex hull, we can rotate the coordinate axis such that P' has the minimum y-coordinate.
(If condition) Let the point P be such that there exists a line(L) for which all points in the set are on one side. Rotate the coordinate axis in way that slope of L becomes zero, thereby making P a point with minimum y-coordinate. Now use Claim 1 to show that it is indeed a point on the convex hull.
The Claim 2 can now be utilized as to prove that the farthest pair would indeed lie on the convex hull as mentioned in the previous answer.

Resources