It is also a classic issue of computational ry that has recently come into contact with the problem of calculation of Cartesian partitioning. According to others'  Algorithm , You have also implemented (  Source code download When the vertex set is large,  Program Computing is very slow. Later, the analysis found that the others program claimed to be O (nlogn), but I became O (N * n), and the algorithms were the same. Later I found out that it was a Data Structure Problem, it seems that the program = Algorithm + data structure makes sense. When I was idle, I sorted out some related knowledge and organized it as follows: 
 
 
 
 
1. Definition of Dirichlet triangle partitioning and KNN Graph
2. algorithm and Analysis for calculation of the Adaboost triangle
3. Example Program &Code
 
 
Big talk
Triangulation is an extremely important Preprocessing Technology for numerical analysis (such as finite element analysis) and graphics.
In particular, due to its uniqueness, many kinds of geometric maps about the point set are related to the Cartesian triangle, such as the canvas, emst tree, and Gabriel diagram. Note:
1. Maximize the smallest angle and "the closest to the regular" Triangle network.
2. uniqueness (any four points cannot be a circle ).
 
 
 
Concepts and Definitions
Triangle partitioning on two-dimensional real number field (two-dimensional plane)
 
 
 
Definition 1: Suppose V is a finite vertex set in two-dimensional real number field, edge e is a closed line segment composed of vertices in the vertex set as endpoints, and E is a set of E.
Then, a triangle partition t = (V, E) of the vertex set V is a plan G, which meets the following conditions:
1. Except the endpoint, the edges in the plan do not contain any vertices in the vertex set.
2. No intersection edge.
3. All faces in the plan are triangular surfaces, and the collection of all triangular surfaces is the convex hull of the Point Set v.
So what is the Adaboost triangle? It's just a special triangle. Start with the Dirichlet edge.
 
 
 
Dirichlet edge
Definition 2: assume that an edge e in E (two endpoints are A and B), and E is called a Dirichlet edge if it meets the following conditions:
There is a circle that passes through two points A and B. The circle does not contain any point in point v. This feature is also called the null circle feature.
 
 
 
Gridded
Definition 3: If a triangle T of a point set V contains only the Dirichlet edge, the triangle is called the Cartesian triangle.
 
 
 
Let's look at several figures:
 
 
 
 
 
 
 
 
The preceding figure introduces another definition of the Adaboost triangle:
Definition 4: Assume that T is a V triangle, then T is a V-based Dirichlet triangle, currently, only when the outer circle of each triangle in t does not contain any vertices in v.
 
 
 
KNN Diagram
 
 
 
Defines 5: v. the canvas is a set of polygon areas (some areas may not be closed). This area contains only one vertex v in the vertex set, the distance from any position in the area to V is shorter than the distance from all other points in the point-to-point concentration.
 
 
 
Based on the relationship between the KNN graph and the Adaboost triangle, we can introduce another definition:
Definition 6: A graph composed of vertices in adjacent areas (areas with common edges) of a KNN graph.
For example:
 
 
 
Here is the concept part. Let's take a look at how to calculate the Adaboost triangle.
 
 
 
Calculate the Adaboost triangle
 
 
 
Question 1: Calculate two-dimensional Cartesian partitioning
Question input: point set V in two-dimensional real number field
Problem output: dt = (V, E ).
 
 
 
Algorithm
 
 
 
Different definitions have different algorithms. Most commonly used algorithms are defined based on 3 or 4.
Currently, common algorithms are divided into several types, which are discovered by different players. What scanning line method (sweepline), random increment method (incremental), divide and conquer method (divide and conquer) and so on.
 
 
 
Random increment method (incremental)
 
 
The random increment method is relatively simple. It follows the consistent idea of the increment method, that is, to insert the points in the vertex set in a random order, during the entire process, you must maintain and update the corresponding gridded points of the current point set. Insert VI points because all vertices V1, V2,... are inserted before ,..., vi-1 consisting of DT (V1, V2 ,..., vi-1) has been a node, just consider the changes caused by inserting VI points, and make adjustments to make DT (V1, V2 ,..., vi-1) u vi becomes the new NN (V1, V2 ,..., VI ).
(Insert adjustment process: first, determine the triangle (or edge) in which the VI falls ), connect VI with three triangle vertices to form three triangles (or connect the two triangles with the same edge to form four triangles ), because the newly generated edges and the original edges may not or are no longer the Dirichlet edges, we flip the edges to adjust them to make them all into the Dirichlet edges, so that DT (V1, v2 ,..., vi ).)
 
 
 
Its pseudo code is as follows:
 
 
Algorithm incrementalnn (V)
Input: a two-dimensional point set consisting of n points V
Output: dt
1. add a appropriate triangle boudingbox to contain V (such as: We can use Triangle ABC, A = (0, 3 m), B = (-3 m,-3 m ), C = (3 M, 0), M = max ({| X1 |, | X2 |, | X3 | ,...} U {| Y1 |, | Y2 |, | Y3 | ,...}))
2. initialize DT (A, B, C) as Triangle ABC
3. For I <-1 to n
Do (insert (DT (a, B, c, V1, V2,..., vi-1), VI ))
4. remove the boundingbox and relative triangle which cotains any vertex of Triangle ABC From DT (a, B, c, V1, V2 ,..., VN) and return DT (V1, V2 ,..., VN ).
 
 
Algorithm insert (DT (a, B, c, V1, V2,..., vi-1), VI)
1. Find the triangle vavbvc which contains VI // findtriangle ()
2. If (VI located at the interior of vavbvc)
3. Then add triangle vavbvi, vbvcvi and vcvavi into DT // updatedt ()
Fliptest (DT, VA, VB, VI)
Fliptest (DT, VB, Vc, VI)
Fliptest (DT, Vc, VA, VI)
4. Else if (VI located at one edge (e. g. Edge vavb) of vavbvc)
5. Then add triangle vavivc, vivbvc, vavdvi and vivdvb into DT (here, D is the third vertex of triangle which contains edge vavb) // updatedt ()
Fliptest (DT, VA, Vd, VI)
Fliptest (DT, Vc, VA, VI)
Fliptest (DT, Vd, VB, VI)
Fliptest (DT, VB, Vc, VI)
6. Return DT (a, B, c, V1, V2,..., VI)
Algorithm fliptest (DT (a, B, c, V1, V2,..., vi), VA, VB, VI)
1. Find the third vertex (VD) of triangle which contains edge vavb // findthirdvertex ()
2. If (VI is in circumcircle of Abd) // incircle ()
3. Then remove edge vavb, add new edge vivd into DT // updatedt ()
Fliptest (DT, VA, Vd, VI)
Fliptest (DT, Vd, VB, VI)
 
 
Algorithm incircle (va, VB, Vd, VC)
If |A ^ B ^,C ^ B ^,D ^ B ^|> 0, VD is not in the circumcircle of ABC //A ^ coordinates are (ax, ay, ax * AX + Ay * Ay ),A ^ B ^ is a vector.
If |A ^ B ^,C ^ B ^,D ^ B ^| = 0, VD is on the circumcircle of ABC
If |A ^ B^,C ^ B ^,D ^ B ^| <0, VD is in the circumcircle of ABC
 
 
 
Note: Details of incircle ():
For example:
 
 
Parabolic P (Z = x * x + y * Y), which has three points on the x-y plane: A, B, and C. Now we need to test whether the test point D is in A, B, in the outer circle of C, four lift points A, B, C, and D are formed, and P intersect at a ^, B ^, C ^, d ^. The following are displayed:
Case 1: If D is in the outer circleUpper, Then d ^ must be in the plane H consisting of a ^, B ^, C ^Upper. Current moment vectorA ^ B ^,C ^ B ^,D ^ B ^The determining factor of the matrixDet = 0
Case 2: If D is in the outer circleInternal, That is, d ', then d' ^ must be in the plane H consisting of a ^, B ^, C ^Below. VectorA ^ B ^,C ^ B ^,D ^ B ^The determining factor of the matrixDet <0
Case 3: If D is in the outer circleExternal, That is, d '', then D'' ^ must be in the plane H consisting of a ^, B ^, C ^Above. VectorA ^ B^,C ^ B ^,D ^ B ^The determining factor of the matrixDet> 0
 
 
 
Complexity Analysis
 
 
 
The scale of the problem is the total number of points in the point set N (no overlapped points). The basic operations in the cycle are as follows:
1. Find the triangle where the insertion point is located (findtriangle ())
2. Whether the test point is in the incircle ())
3. updatedt ())
4. Find the third vertex of the tested edge (findthirdvertex ())
 
 
 
Consider the worst case:
 
 
Time Complexity T = T (addboudingbox () + sum (T (insert (I), I = 1, 2,..., n) + T (removeboundingbox)
Because addboudingbox () and removeboundingbox do not change with N, they are constants. T (addboudingbox () = O (1), T (removeboundingbox () = O (1 ).
 
 
 
T = sum (T (insert (I), I = 1, 2,..., n) + O (1) + O (1 ).
 
Consider the time when the I point is inserted:
T (insert (I) = T (findtriangle (I) + T (updatedt (I) + K * t (fliptest (I) (K is a constant)
 
 
 
So T = sum (T (findtriangle (I), I = 1, 2 ,.., n) + sum (T (updatetd (I), I = 1, 2 ,.., n) + K * sum (T (fliptest (I), I = 1, 2 ,.., n)
 
 
 
Considerations:
Findtriangle (I) is to find the triangle that contains the I point. It is known by the Euler's formula that the number of planes F is O (n), and N is the number of vertices, therefore, the total number of triangles is O (I. Therefore, the problem is equivalent to finding the target record in the O (I) record. If you do not use the special data structure, you need the O (I) time to search in the general order.
T (findtriangle (I) = O (I), so: sum (T (findtriangle (I), I = 1, 2 ,.., n) = O (N * n)
 
 
 
Updatetd (I) is a constant operation to update the data structure of a triangle. inserting and deleting a triangle to the current triangle is a constant operation because you already know the location of the insertion and deletion.
T (updatedt (I) = O (1), so: sum (T (updatetd (I), I = 1, 2,..., n) = O (N)
 
 
Fliptest (I) is a more complex recursive process. Subdivided into: T (fliptest (I) = T (findthirdvertex (I) + T (incircle (I) + T (updatedt (I )) + 2 * t (fliptest (j )). (J is used to distinguish different depths)
Because incircle (I) is a constant operation to determine whether the test point is in an external circle and does not change with the number of points. So T (incircle (I) = O (1), and T (updatedt (I) = O (1) (see the above)
Findthirdvertex (I) is the search target point. It searches for the target records in the O (I) records. If no special data structure is used, it searches for the time that requires O (I) in the general order. T (findthirdvertex (I) = O (I ).
The rest is the process of recursively calling fliptest, but fortunately, because the recursive depth of fliptest is only constant (set to K ). Is proportional to the degree (degree) in the point in the tin ). Therefore, the maximum number of fliptest (I) calls is 2*2 *,..., 2 = K', or a constant.
Therefore, T (fliptest (I) = O (I) + O (1) + O (1) + K' * (O (I) + O (1) + O (1) = O (I) + O (1) + O (1 ).
Sum (T (fliptest (I), I = 1, 2,..., n) = O (N * n) + O (N)
 
 
 
In summary, in the worst case, the total algorithm complexity T = O (N * n) + O (n) + K * (O (N * n) + O (N) + O (n) + O (1) + O (1) = O (N * n)
Among them, the key operations are findtriangle () and findthirdvertex (), which are all N * n times.
 
 
According to many materials on the Internet, the random increment method is O (nlogn), but it is O (n * n. Later, we can see other people's implementations. They used other data structures to store the tin, reducing the complexity of findtriangle () and findthirdvertex. So that the third vertex of a triangle and a common edge triangle can be found at O (logn) rather than O (n. In this way, the total search time is O (log1) + O (log2) +,... + O (logn) = O (nlogn ). Program = Algorithm + data structure, it seems correct.
For example, the complexity of O (nlogn) can be achieved by using Dag and quad-edge.
 
 
 
Divide and conquer)
 
 
 
It is said that the current performance is the best.
 
 
 
Scan Line Method (sweepline)
 
 
 
Let's take a look at its algorithm ideas.
 
 
 
Example Program & code
 
 
 
There are a lot of code libraries on the Internet, such as triangle and qhull, that are annoying. I wrote a library myself, which is very simple. It is basically a literal translation of pseudo code by random increment method, no time for optimization.
 
 
 
If you have time, sort out the knowledge related to the constraint-specific AdaBoost triangle.
 
 
 
To be continued...