Voronoi graphs and Delaunay triangles and convex packages

Source: Internet
Author: User

Write a little something recently written ...

Recently in the algorithm class, the class teacher talked about the Vinoto, I think it is very interesting to study a bit, and Java wrote a simple SE program used to show Vinoto and Delaunay triangles and convex package.

First of all, the convex hull, convex hull in mathematics is very common, given some points, and then find out the smallest convex package containing these, generally do so. As for the definition of convex hull Wikipedia or Baidu, you can check a check to know that the popular talk is to extend each side, the rest of the graphics are always on the side.

(The interface is a bit ugly)

Here, give me the convex hull that my program runs out of.

Then there is the Delaunay triangle, the triangle is such that the insertion point in the convex hull, and then connect the nodes and the insertion point, then the formation of a triangle, and then insert the triangle again, and the formation of the triangle does not include the fourth point.

Voronoi figure on the basis of the above triangle to find each triangle circumscribed circle center, connecting each such center can get such a Voronoi diagram.

All right, this is my effect. Display diagram, specific code I uploaded to GitHub for everyone to learn the reference, some of the notes, but because the comparison is not written in a hurry to write very detailed, we have problems can be discussed together.

GitHub Address: https://github.com/monster5475/JAVACore/tree/master/

Next, I do some of the problems encountered in this process and some things, first of all, thank you for helping me a lot of several blogs.

Https://www.cnblogs.com/zhiyishou/p/4430017.html The main triangle of the cutting formation

50808360 This article is mainly about the convex hull formed by the method of Graphscan

48208983 This is a reference blog.

52244123 This is my main reference, according to the implementation of the blog, this blog is very good, I basically refer to this idea go.

Forget to add the Bowyer-watson algorithm, I also look at the "research based on Bowyer_watson triangle network Generation algorithm _ Zhou Xuemei" This article some pseudo-code.

Really is walnuts, descendants take Yin, thank predecessors!

Now, let's introduce the main idea.

(1) The first is the Java form design, as well as some of the button bindings, drawing, about a day to complete, the form of drawing a little forget.

(2) then is the first step randomly generated point function, this is not difficult, it is important to be careful not to generate duplicate points, and then do not exceed the boundary. (at first thought there would be a gap between drawing X Y and the real x Y, which was later found not to be considered)

(3) Get a point ArrayList, first find the y lowest point, get a pie chart similar to this

Then P0 must be a convex bag on the point, the P1 point must be a bit on the convex hull, and then the two points into the stack, start to judge the other points, this side first to understand the concept of cross-multiplication, vector a cross-vector b, the resulting vector is perpendicular to the vector A and b composition of the plane, The direction is based on the order of the right-hand rule according to the cross-multiplication of a and B, then we can determine the position of the point by the positive or negative of the result of the cross-multiplication (the p0p1 of the vector and the vector p1p2) (note that the fork multiply first to make two vectors the same starting point), According to the law of the right hand is a vertical paper outward vector, then it can be explained that the point P2 in the vector p0p1 counterclockwise side. If the P2 is on the clockwise side of the P0P1, the cross-multiplication result should be a vector of vertical paper inward. According to this, we can be a judge, such as P0P1 judge finished p2 is we want point, then into the stack, this time the stack element is (P0,P1,P2) P2 bit stack top element, when we connect p2p3, with the vector p1p2 (two points on the top of the stack) fork by P2P3, found that the result vector vertical paper inward, then the point P3 is in the clockwise direction of P1P2, then with our convex hull definition error, because we said before the convex hull all points on the side of the same side, now P3 on the clockwise side, P0 on the counter-clockwise side, so P2 is not a point on the convex bag, will p2 out of the stack, P3 into the stack, so far until the end. This is the Graham scanning method, because we initially selected is from the counter-clockwise direction, so the judgment time correlation, of course we can also choose the clockwise direction, then we are from P12 p11 over there, then we have to determine whether the point in the current stack of two points on the side of the clockwise direction.

(4) Then we got the convex hull of these points, and now we are going to do the Delaunay triangle construction, I was determined to use the Bowyer-watson algorithm to build, but in the second step of the time I have some doubts, then I think of a way to solve, do not know whether there are loopholes, But the drawing is OK, I copy the above link in a blogger hair

Delaunay is a triangulation standard, and it has many algorithms to realize it. This time using the Bowyer-watson algorithm, the basic steps of the algorithm are:
(1) construct a super-triangle that contains all the scatter points and put them into a triangular linked list.
(2) The scatter points in the point set are inserted in order, and the circumscribed circle contained in the triangle linked list is found.
The triangle of the insertion point, called the effect triangle for that point, removes the common edges that affect the triangle, joins the insertion point with all vertices of the affected triangle, and completes the insertion of a point in the Delaunay triangle list.
(3) According to the optimization criterion, the locally newly formed triangle is optimized. The resulting triangle is placed in the Delaunay triangle linked list.
(4) Loop through the 2nd step above until all the scattered points have been inserted.

Key Step 2 is as follows:

The local optimization guidelines for step 3 refer to the following:
1. The newly formed triangle is optimized to synthesize a polygon with two triangles with a common edge.
2. Check the maximum empty circle criterion to see if the fourth vertex is within the circumscribed circle of the triangle.
3. If the correction diagonal is about to be reversed, the processing of the local optimization process is completed.

The LOP (Local optimization Procedure) process is as follows:

---------------------This article from Dablelv csdn blog, full-text address please click: 52244123?utm_source=copy

I'm wondering how the second step is going to "delete the public side that affects the triangle, connect the insertion point to all vertices that affect the triangle", and later in the code, I think of a method, I'm going to explain here, first we get the convex hull, now we insert a point in the convex hull, So how do we divide the triangles? is not directly take the points of the convex hull and the insertion point can complete the division of the Triangle, get a triangles, and then we now proceed to the second point of insertion, we detect triangle circumscribed circle found this point in three triangles, we call these three triangles are affected by the triangle, We can tell that the three Samsung shapes are joined together, we remove the three triangles from the triangles, and form a polygon with the edges of the three triangles, and the insertion point is in the middle of the polygon, which is not the case when we insert the first point. All we need to do is connect the dots and the insertion point to get a new Samsung-shaped collection and join the triangles. Here is also worth noting is the local optimization correction process, at first not very understanding of the situation, and then I think about this situation should be to avoid the circumscribed circle in the right two points is the diameter of the case then the fourth point in the park, to modify the diagonal, forming a small circumscribed circle, will be one of the points fork out.

When the above work is all done, you can get a list of triangles that can be drawn.

(5) The final step is the establishment of the Vinoto, in fact, the establishment of Vinoto in the Delaunay triangle is already very convenient, as long as the triangle of the previous step to find the circumscribed Circle Center, and then have a common side of the circumscribed Circle Center link together can get the initial Vinoto we need, It is also noteworthy that there are some rays in the Cerviño diagram. I was bored by these rays in the process of drawing. Only the need to really have a drawing to know the ray is very difficult to decide. I also don't know, if I wrote the code in my processing is very complicated, although it is drawn, but there is a little bit of a problem. May sometimes fail.

Above is I write this small project process, which used some java8 stream characteristics, I think java8 is very useful. Come on, come on.

Below put a few classes of small, give also want to try some of your feelings, of course you can go to see my code. If you think I can, please give me the GitHub project little Star ~ ~ ~

This is the main algorithm class: algorithm

This is the edge class that mainly overrides equals and ToString

This is the form class

This is the artboard class

A little bit of a few pictures, specific to see the code ~ ~ ~

This is the implementation of a code, found on-line data there is, but did not see a real can run up, do an example of their own happy, the amount ~ This probably took me five days to finish. Of course it's intermittent, because I've been in class recently.

Voronoi graphs and Delaunay triangles and convex packages

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.