How to triangulate from a Voronoï diagram? - delaunay

I computed a Voronoï diagram from a set of point (with Boost.polygon).
I try to find a Delaunay triangulation, connecting each cell center for each Voronoï edge, but I miss some edges.
In the following image, the red dots are my initial points, the blue lines are the Voronoï edges (I ignored infinite edges), and the green lines are the triangulation edges (on green edge for each blue edge, connecting two cell origins).
We can see that diagonal edges are missing. What am I missing?

4 Delaunay vertices lie on a common circle, this is a degenerate situation. Shift the points a little and you will recognize the problem.

Related

How to detect whether a circle and a polygon overlap?

I am implementing a function that can detect whether a circle and a polygon are overlapping or not.
I have all the points of the polygon and I know the center points and radius of the circle.
There I check two scenarios:
polygon vertices are inside the circle
circle center is inside the polygon
But there are other scenarios in which a circle and a polygon are overlapping, as shown in the attached image. Can anyone suggest validation for finding the intersection?
Here is a possible approach.
If one of the polygon vertices is inside the circle, there is overlap.
If the the circle center is inside the polygon, they overlap. Note that this test is not trivial for non-convex shape. For example consider a polygon similar to a thin spiral.
Otherwise, for every edge (a,b) of the polygon:
Find p, the projection of the circle center to the line (a,b).
If the distance of p to the circle center is larger than the radius, there is no overlap for this edge.
Otherwise, if p is between a and b (so p_x between a_x and b_x, and also p_y between a_y and b_y, to include the case of horizontal and vertical edges), then there is overlap for this edge, otherwise not.

Get Edges between Vertices (outer polygon)

I'm using THREE.JS and I have a this mesh with different surfaces. Of each surface I got its vertices. Now I want to create edges ( connect the vertices with lines). The vertices are in an arbitrary order, so I can't simply connect v1 with v2, v2 with v3 and so on. I think I have to walk through them with a ray clockwise or counter clockwise and put them in the right order somehow and I have to somehow check their distances, so that the horizontal line between the inner vertices doesn't appear, rather it should go right along the real edges,but I don't know how... Any idea?
(the spheres are the vertices that are the real corners of the surface, the orange lines are the wrong edges that need to be corrected and the blue lines are the edges of each single face)
I need to create these 8 edges (red)
Assuming that you are able to assign a unique number to the vertices and to uniquely associate every triangle to a face, and that the triangulation is watertight, the edges of a face are those edges that are common to a triangle of that face and a triangle of another. When you have all edges of a face, it is a trivial matter to chain them in a polygon.

Calculate approximate outline from polygon points

I have a series of points that make up a polygon (the green dots below), these are connected with straight lines to make the polygon (the blue lines). I want to calculate the red lines, I've tried a few approaches around scaling the points and the lines but they always ended up with intersecting red lines which I don't want.
The green dots/blue lines polygon is drawn by the user so it could be any non-intersecting polygon.
Is it possible to calculate the red line, even approximately?
(If the red line had to go into the channel on the top of the polygon that would fine)

How to detect border vertices of an open mesh 3d model?

There are two kinds of surface mesh models, closed mesh like a sphere or a cube and the second one is the open mesh model which means the surface of the model is not in a closed loop. It is open from somewhere like a hollow pipe.
Sp what I want is I want to detect the border vertices of the open mesh model. there is no border in closed loop mesh but in open mesh we have to detect border vertices for some smoothing, subdivision, etc. operations.
Kindly, suggest me how can I select/detect border vertices ? what is the optimal way to do this ?
by comparing edges of the triangles ? Give me some idea ?
Thanks.
Assuming that you have a manifold mesh, then the border of the mesh are those edges which belong to only one polygon. Edges that are not on the border will belong to two polygons. The border vertices are the vertices that belong to the border edges.
A naive way to find the border vertices is to iterate through all your edges, count how many polygons they belong to, and if they only belong to one polygon, then collect the edge's vertices as border vertices. You will have to remove duplicates vertices from your collection, though.
A second approach is to have your mesh data structure examine each edge as they are added to the mesh, or as polygons are attached to particular edges. In this way, the mesh data structure can keep a list of up-to-date border edges for you, so that when you needed the edges you would not have to find them each time. This will greatly reduce the overhead of determining border edges, although inserting edges and polygons will be slightly more expensive. Your mesh data structure will also take up a bit more memory.
Assuming that your mesh is a 2D (or 2.5D) regular, well-constructed triangulation. You can use some of the properties listed here: http://graphics.stanford.edu/courses/cs468-10-fall/LectureSlides/02_Basics.pdf
Page 9 defines the degree (or valence) of a vertex as the number of incident edges. As shown, all boundary vertices 4 incident edges. "Internal" vertices have 5 incident edges.
Page 17 defines a boundary edge as one that is adjacent to exactly one face.
You might find the discussion on page 22 helpful (closed 2-manifold triangle meshes)

How can a convex polygon be broken down into right triangles aligned on the X- and Y- axes?

Given a convex polygon represented by a set of vertices (we can assume they're in counter-clockwise order), how can this polygon be broken down into a set of right triangles whose legs are aligned with the X- and Y-axes?
Since I probably lack some math terminology, "legs" are what I'm calling those two lines that are not the hypotenuse (apologies in advance if I've stabbed math jargon in the face--brief corrections are extra credit).
I'm not sure about writing an algorithm to do this but it seems entirely possible to do this for any convex polygon on a piece of paper. For each vertex project a line vertically or horizontally from that vertex until it meets another of these vertical or horizontal lines. For vertices with small changes in angle, where adjacent sides are both travelling in the same direction in terms of x and y, you will need to add two lines from the vertex, one horizontal and one vetical.
Once you have done this, you should be left with a polygon in the centre of the origonal polygon but with sides that are either vertical or horizontal because the sides have been formed by the lines drawn from the vertices of the original polygon. Because these sides are either vertical or horizontal, this shape can easily be sub-divided into a number of triangles with one horizontal side, one vertical side and one hypotenuse.
I'm assuming you've already ordered the vertices as you describe above, and that they indeed define a convex polygon.
Each vertex defines a horizontal line. For V vertices, then, you will have a set of V lines. Discard any line that meets one of the following criteria:
The vertex or vertices defining that line has/have the highest or lowest Y component (if one vertex, that line intersects the polygon only at that point; if two, that line coincides with a polygon edge)
If two vertices have equal Y coordinates otherwise, keep only one of those lines (it's duplicated).
The result will resemble a "banding" of the polygon.
Each horizontal line intersects the polygon at two points. One is its defining vertex. The other is either another vertex, or a point on a segment defined by two vertices. You can determine which is the case easily enough - just simple comparison of Y coords. The coordinates of the intersection with a segment is also easy math, which I leave to you.
Each intersection defines a vertical segment. The segment is contained within the polygon (if it coincides with an edge, you can discard it), and the other end meets either another horizontal line, or the edge of the polygon if that edge is itself horizontal. Determining the case is again a matter of mere comparison of coords. Finally, there may be 0-2 additional vertical segments, defined by the vertices with the highest and/or lowest Y coords, if there is only one of either.
The resulting diagram now shows each band with a right triangle trimmed off each end if possible. Each triangle should meet your criteria. The leftover regions are rectangles; draw an arbitrary diagonal to split each into two more right triangles meeting your criteria.
You're done.
I'm not sure if this is possible. Think about a square that's already aligned with the sides on the X and Y axes. How do you draw triangles using the vertices that are also aligned to the X,Y axes?
Or are the actual sides of the polygon allowed to be along the x,y axis. Which means you could just draw a line down the diagonal of the square. If so, it might be difficult to do with a more complex polygon where some sides are aligned to the axes, while others are not.
I'm not convinced there is a general solution to the question as posed. The problem is the aligned with the X- and Y-axes bit. That means that each vertex needs to be projected to the opposite side of the polygon in both the X and Y directions, and new vertices created at those intersection points. But that process must continue on for each new vertex added that way. You might get lucky and have this process terminate (because there's already a vertex appropriately placed on the opposite side), but in the general case it's just going to go on and on.
If you throw out that restriction, then Neil N's suggestion seems good to me.
Neil N is right, I think. Unfortunate that he didn't provide any specific links.
If you have a trapezoid whose top and bottom are parallel to the X axis, you can easily render that with 4 right triangles. Call that shape a horizontal trapezoid.
If you have a triangle with one side parallel to the X axis, you can render that with 2 right triangles -- or you can consider a degenerate case of the trapezoid with the top of bottom having length zero.
Start at either the top or bottom of your convex hull (i.e. search for coordinate with min or max y) and split it into horizontal trapezoids.
It's not to hard to write the code so that it works just as well with non-convex polygons.
I think this is not possible in the general case.
Consider the polygon {(0, 1), (1, 0), (2, 0)}
.
..
This triangle can not be split into a finite number of triangles as you describe.

Resources