A practical method for quickly calculating the area of polygon intersection and union
By discretizing the polygon envelope rectangle into small square areas and traversing the center point for judgment, the problem of low efficiency in polygon intersection and union area calculation in the existing technology is solved, and efficient and accurate area calculation is achieved.
Patent Information
- Application Number
- CN202210315937.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-28
- Publication Date
- 2025-09-26
- Estimated Expiration
- 2042-03-28
AI Technical Summary
The existing methods for calculating the area of polygon intersection and union have application limitations, especially when solving convex and concave polygons, the algorithms are complex and all intersection points need to be calculated, resulting in low computational efficiency.
Using the discretization idea, the internal area of the polygon envelope rectangle is evenly discretized into multiple small square areas. The intersection and union are determined by traversing the center points, and the angle method and ray method are used to determine whether the point is inside the polygon, and the area is approximately calculated.
The method improves computational efficiency and ensures high-precision polygon intersection and union area calculation while controlling the discretization step size.
Smart Images

Figure CN114782515B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of polygon intersection judgment, and in particular relates to a practical method for quickly calculating the area of polygon intersections and unions. Background Art
[0002] Determining the area of polygon intersections and unions is a common problem in engineering applications such as image processing, graphics, and geography. Numerous computational methods exist for this problem, but most have varying degrees of application limitations. For example, some algorithms are only applicable to convex or concave polygons, while others are applicable to both. However, these algorithms require calculating all intersection points and performing the analysis in a categorized manner, making them complex and unsuitable for fast computation.
[0003] Therefore, at this stage, it is necessary to design a practical method for quickly calculating the area of polygon intersection and union to solve the above problems. Summary of the Invention
[0004] The purpose of the present invention is to provide a practical method for quickly calculating the area of polygon intersections and unions, which is used to solve the technical problems existing in the above-mentioned prior art. The problem of solving the area of polygon intersections and unions is often encountered in engineering applications such as image processing, graphics, and geography. Currently, there are many calculation methods for this problem, but most of them have more or less application limitations. For example, some algorithms are only applicable to solving convex polygons or concave polygons; some algorithms are applicable to solving both convex polygons and concave polygons, but all intersection points need to be calculated and solved in a classified manner, which makes the algorithm complex and not conducive to fast calculation.
[0005] To achieve the above object, the technical solution of the present invention is:
[0006] A practical method for quickly calculating the area of polygon intersection and union includes the following steps:
[0007] S1: Based on the discretization idea, the inner areas of the two polygonal enveloping rectangles are evenly discretized into multiple square areas;
[0008] S2: The coordinates of the center point of each square area are calculated based on the discrete step length, and the set of square areas with all center points inside the corresponding polygon is obtained by traversal;
[0009] S3: Based on step S2, it is determined whether the center point of the square area inside one of the polygons is inside the other polygon. If so, the square area is defined as the intersection of the square areas.
[0010] S4: The area of the intersection and union of polygons is approximately calculated by solving the intersection and union of square areas.
[0011] Furthermore, step S1 is specifically as follows:
[0012] In the oxy plane coordinate system, polygon P and polygon D intersect;
[0013] The coordinate values of the vertices of polygon P and polygon D in the oxy plane coordinate system are known; by comparing the coordinate values of each vertex of polygon P in the oxy plane coordinate system, the minimum coordinate value p of polygon P on the x-axis is obtained respectively. xmin and the maximum coordinate value p xmax , the minimum coordinate value p on the y-axis ymin and the maximum coordinate value p ymax ; Similarly, get the minimum coordinate value d of polygon D on the x-axis xmin and the maximum coordinate value d xmax , the minimum coordinate value d on the y-axis ymin and the maximum coordinate value d ymax ;
[0014] Point (p xmin , p ymin ) and point (p xmax , p ymax ) is the boundary, forming the envelope rectangle R of polygon P P , the envelope rectangle R P Uniform discretization into N P A small enough square area, Represents a set of square areas. Similarly, point (d xmin , d ymin ) and point (d xmax , d ymax ) is the boundary, forming the envelope rectangle R of polygon D D , the envelope rectangle R D Uniform discretization into N D A small enough square area, Represents a collection of square regions.
[0015] Furthermore, step S2 is specifically as follows:
[0016] According to the envelope rectangle R P The vertex coordinates and the side length of the discretized square area are calculated. The coordinates of the center point of each square area in the polygon P are traversed to determine whether the center point of each square area is inside the polygon P. The angle method and ray method can be used to determine whether the center point of each square area is inside the polygon P. The square area whose center point is inside the polygon P in the set is represented by the set In other words, The square area whose center point is inside polygon D in the set is represented by the set express.
[0017] Furthermore, step S3 is specifically as follows:
[0018] By traversing Whether the center point of each square area in the set is inside polygon D can be judged by using angle method and ray method; The square area whose center point is inside polygon D in the set is represented by the set express; The sum of the areas of the square regions is approximately equal to the area of the intersection of polygon P and polygon D. The sum of the areas of the square regions is approximately equal to the area of the union of polygons P and D.
[0019] Furthermore, when the accuracy of the calculated intersection and union areas is less than expected, the discretized square area is gradually reduced until the accuracy of the calculated intersection and union areas meets expectations.
[0020] Furthermore, the square area is a square area.
[0021] An electronic device, comprising:
[0022] processor;
[0023] a memory for storing processor-executable instructions;
[0024] The processor runs the executable instructions to implement the practical method for quickly calculating the area of polygon intersection and union as described above.
[0025] A computer storage medium is characterized in that a computer program is stored on the storage medium, and when the computer program is run, it executes the above-mentioned practical method for quickly calculating the area of polygon intersection and union.
[0026] Compared with the prior art, the present invention has the following beneficial effects:
[0027] One of the beneficial effects of this solution is that the present invention proposes a practical method for quickly calculating the intersection and union areas of polygons, introduces the idea of discretization, and calculates the intersection and union areas of polygons by judging whether the points are inside the polygons. By controlling the discretization step size, it can ensure high calculation efficiency while having high calculation accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 This is a schematic diagram of intersecting polygons according to an embodiment of the present application.
[0029] Figure 2 Schematic diagram of the discretization of the envelope rectangle according to an embodiment of the present application.
[0030] Figure 3 This is a schematic diagram of the angle method of an embodiment of the present application.
[0031] Figure 4 This is a flowchart of the method steps of an embodiment of the present application. DETAILED DESCRIPTION
[0032] Below with reference to the appended claims of the present invention Figure 1 -Attached Figure 4 The technical solutions in the embodiments of the present invention are clearly and completely described. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. All other embodiments derived by persons of ordinary skill in the art based on the embodiments of the present invention without inventive effort are within the scope of protection of the present invention.
[0033] Determining the area of polygon intersections and unions is a common problem in engineering applications such as image processing, graphics, and geography. Numerous computational methods exist for this problem, but most have varying limitations. For example, some algorithms are only applicable to convex or concave polygons, while others are applicable to both. However, these algorithms require calculating all intersection points and performing the analysis in a categorized manner, making them complex and inefficient for fast computation.
[0034] Example:
[0035] like Figure 4 As shown, a practical method for quickly calculating the area of the intersection and union of two polygons is proposed. Based on the discretization concept, the interior area of the two polygonal enveloping rectangles is uniformly discretized into multiple sufficiently small square areas. The center point coordinates of each square area are calculated using discrete step lengths, and a set of square areas whose center points are within the corresponding polygons is obtained through traversal. Based on this, the method determines whether any square area within one polygon has its center point within the other polygon. If so, such a square area is defined as a square area intersection. The area of the polygon intersection and union is approximated by solving the square area intersection and union. By controlling the discretization step size, high computational efficiency and accuracy can be simultaneously ensured.
[0036] 1) Figure 1 The following describes a specific implementation method for the sake of example. In the oxy plane coordinate system, polygon P and polygon D intersect. The vertices of polygon P are p1p2p3p4p5p6p7, and the vertices of polygon D are d1d2d3d4d5. The intersection of the two polygons is s1s2, the intersection is d1s2p3p4s1d5, and the union is p1p2s2d2d3d4s1p5p6p7.
[0037] 2) The coordinates of the vertices of polygon P and polygon D in the oxy plane coordinate system are known. Assume that the coordinates of the 7 vertices of polygon P are: (p 1x , p 1y )、(p 2x , p 2y )、(p 3x , p 3y )、(p 4x , p 4y )、(p 5x , p 5y )、(p 6x , p 6y )、(p 7x , p 7y ), assuming that the coordinates of the five vertices of polygon D are: (d 1x , d 1y )、(d 2x , d 2y )、(d 3x , d 3y )、(d 4x , d 4y )、(d 5x , d 5y ). By comparing the coordinate values of each vertex of polygon P in the oxy plane coordinate system, the minimum coordinate value p of polygon P on the x-axis is obtained respectively. xmin and the maximum coordinate value p xmax , the minimum coordinate value p on the y-axis ymin and the maximum coordinate value p ymax , as shown in formula (1). Similarly, get the minimum coordinate value d of polygon D on the x-axis xmin and the maximum coordinate value d xmax , the minimum coordinate value d on the y-axis ymin and the maximum coordinate value d ymax , as shown in formula (2);
[0038]
[0039]
[0040] 3) Point (p xmin , p ymin ) and point (p xmax , p ymax ) is the boundary, forming the envelope rectangle R of polygon P P ,like Figure 2 As shown, the envelope rectangle R P Uniform discretization into N P A sufficiently small square area. P The x-axis direction is evenly divided into nP Divide the envelope rectangle R P The y-axis direction is evenly divided into m P Equal parts, with N P =n P m P , the length of each square area is l xP and width yP It can be calculated using formula (3). Represents a set of square areas. Similarly, point (d xmin , d ymin ) and point (d xmax , d ymax ) is the boundary, forming the envelope rectangle R of polygon D D , the envelope rectangle R D Uniform discretization into N D A sufficiently small square area will enclose the rectangle R D The x-axis and y-axis directions are evenly divided into n D and m D Equal parts, use Represents a set of square areas, the length of each square area is l xD and width yD It can be calculated using formula (4);
[0041]
[0042]
[0043] 4) According to the envelope rectangle R P The vertex coordinates and the side length of the discretized square area are calculated. The coordinates of the center point of each square area in The calculation formula is shown in formula (5). By traversing, we can judge whether the center point of each square area is inside the polygon P. Here, we use the angle method to judge, such as Figure 3 As shown, add the angles between the point and the lines connecting the polygon vertices. If the sum of the angles is not equal to 360°, the point is outside the polygon; if the sum of the angles is equal to 360°, the point is inside the polygon. The square area whose center point is inside the polygon P in the set is represented by the set In the same way, The square area whose center point is inside polygon D in the set is represented by the set express;
[0044]
[0045] 5) Judge by traversal The angle method is used to determine whether the center point of each square area in the set is inside polygon D. The square area whose center point is inside polygon D in the set is represented by the set express. The sum of the areas of the squares is approximately equal to the area S of the intersection of polygons P and D. ∩ , the calculation formula is shown in formula (6). The sum of the areas of the squares is approximately equal to the area S of the union of polygons P and D. ∪ , the calculation formula is shown in formula (7). When the discretized square area is small enough, the accuracy of the intersection and union areas calculated by this method is high enough.
[0046]
[0047]
[0048] The technical solution of the present invention is not limited to the above-mentioned specific embodiments. Any technical variations made according to the technical solution of the present invention fall within the protection scope of the present invention.
[0049] The above are preferred embodiments of the present invention. Any changes made according to the technical solution of the present invention, as long as the resulting functions and effects do not exceed the scope of the technical solution of the present invention, shall fall within the scope of protection of the present invention.
Claims
1. A practical method for quickly calculating the area of polygon intersection and union, characterized in that: The following steps are involved: S1: Based on the discretization idea, the inner areas of the two polygonal enveloping rectangles are evenly discretized into multiple square areas; S2: The coordinates of the center point of each square area are calculated based on the discrete step length, and the set of square areas with all center points inside the corresponding polygon is obtained by traversal; S3: Based on step S2, it is determined whether the center point of the square area inside one of the polygons is inside the other polygon. If so, the square area is defined as the intersection of the square areas. S4: Approximately calculate the area of polygon intersection and union by solving the intersection and union of square areas; Step S1 is specifically as follows: In the oxy plane coordinate system, polygon P and polygon D intersect; The coordinate values of the vertices of polygon P and polygon D in the oxy plane coordinate system are known; by comparing the coordinate values of each vertex of polygon P in the oxy plane coordinate system, the minimum coordinate value p of polygon P on the x-axis is obtained respectively. xmin and the maximum coordinate value p xmax , the minimum coordinate value p on the y-axis ymin and the maximum coordinate value p ymax ; Similarly, get the minimum coordinate value d of polygon D on the x-axis xmin and the maximum coordinate value d xmax , the minimum coordinate value d on the y-axis ymin and the maximum coordinate value d ymax ; Point (p xmin , p ymin ) and point (p xmax , p ymax ) is the boundary, forming the envelope rectangle R of polygon P P , the envelope rectangle R P Uniform discretization into N P A square area of preset size, with Represents a set of square areas. Similarly, point (d xmin , d ymin ) and point (d xmax , d ymax ) is the boundary, forming the envelope rectangle R of polygon D D , the envelope rectangle R D Uniform discretization into N D A square area of preset size, with Represents a set of square areas; Step S2 is specifically as follows: According to the envelope rectangle R P The vertex coordinates and the side length of the discretized square area are calculated. The coordinates of the center point of each square area in the polygon P are traversed to determine whether the center point of each square area is inside the polygon P. The angle method and ray method can be used to determine whether the center point of each square area is inside the polygon P. The square area whose center point is inside the polygon P in the set is represented by the set In other words, The square area whose center point is inside polygon D in the set is represented by the set express; Step S3 is as follows: By traversing Whether the center point of each square area in the set is inside polygon D can be judged by using angle method and ray method; The square area whose center point is inside polygon D in the set is represented by the set express; The sum of the areas of the squares is approximately equal to the enveloping rectangle R P and the envelope rectangle R D The area of the intersection, The sum of the areas of the squares is approximately equal to the enveloping rectangle R P and the envelope rectangle R D the area of the union; When the accuracy of the calculated intersection and union areas is lower than expected, the discretized square area is gradually reduced until the accuracy of the calculated intersection and union areas meets expectations.
2. A practical method for quickly calculating the area of polygon intersection and union according to claim 1, characterized in that: The square area is a square area.
3. An electronic device, characterized in that: include: processor; a memory for storing processor-executable instructions; The processor executes the executable instructions to implement a practical method for quickly calculating the area of polygon intersections and unions as described in any one of claims 1-2.
4. A computer storage medium, characterized in that The storage medium stores a computer program, which, when executed, executes a practical method for quickly calculating the area of polygon intersections and unions as described in any one of claims 1 to 2.
Citation Information
Patent Citations
Vector polygon rasterization parallel superposition processing device and method
CN106952324A
Rapid runway truncation analysis method
CN111652071A