CN111915665B - A method for determining points in polygons using simplified intersection calculation on computer - Google Patents
A method for determining points in polygons using simplified intersection calculation on computer Download PDFInfo
- Publication number
- CN111915665B CN111915665B CN202010703960.XA CN202010703960A CN111915665B CN 111915665 B CN111915665 B CN 111915665B CN 202010703960 A CN202010703960 A CN 202010703960A CN 111915665 B CN111915665 B CN 111915665B
- Authority
- CN
- China
- Prior art keywords
- polygon
- ray
- intersection
- grid
- outside
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/60—Analysis of geometric attributes
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F17/00—Digital computing or data processing equipment or methods, specially adapted for specific functions
- G06F17/10—Complex mathematical operations
Landscapes
- Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Theoretical Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Mathematical Physics (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Algebra (AREA)
- Computational Mathematics (AREA)
- Geometry (AREA)
- Mathematical Analysis (AREA)
- Mathematical Optimization (AREA)
- Pure & Applied Mathematics (AREA)
- Databases & Information Systems (AREA)
- Software Systems (AREA)
- General Engineering & Computer Science (AREA)
- Image Generation (AREA)
Abstract
Description
技术领域technical field
本发明属于计算机算法、计算机图形学、计算几何、地理信息系统处理领域,具体说是一种涉及点在多边形内判定计算的方法,即:对于一个点的空间位置,判断该位置是否位于一个多边形所限定的空间区域内的方法。The invention belongs to the processing fields of computer algorithms, computer graphics, computational geometry, and geographic information systems, and specifically relates to a method for determining and calculating points within a polygon, that is, for the spatial position of a point, it is determined whether the position is located in a polygon. methods within a defined spatial area.
背景技术Background technique
点在多边形内的判定计算,是计算机图形学、计算几何、地理信息系统处理中的一种基础计算技术,就是对于一个多边形而言,任一个测试点,要判断该点是否位于该多边形内。这方面的工作很多,其中使用比较广泛的有射线法和基于均匀网格划分的方法。射线法,就是从测试点发出一条射线,统计它与多边形的边的相交次数。如果相交次数为偶数,则测试点在多边形外;否则,在内。射线法要与多边形的每条边进行求交测试,其计算复杂度为O(N),这里N为多边形的边的数目。为降低计算复杂度,提出了多种方法,先对多边形进行一定的预处理,如将多边形划分成梯形或凸多边形,然后可快速定位测试点所位于的局部区域,再根据局部区域的情况进行判断计算。这类方法可减少需要检测的多边形的边数,计算复杂度可降至O(logN)。但这类方法的预处理比较麻烦。为此,均匀网格方法提出,对多边形的包围盒进行与坐标轴对齐的矩形网格划分,由此可进行简单的预处理,也可将测试点的检测限定于所在网格单元邻近的局部区域进行。经过对多种方法进行对比后,均匀网格方法是适于实际应用的高效的点在多边形内判定计算方法。进一步,提出了将射线法与均匀网格法相结合的方法,先计算各个网格交点位于多边形内/外的属性,然后将测试点与其所在网格单元的网格交点进行连线,就可局部化地使用射线法进行点在多边形内的判定计算。由于一个网格交点与多个网格单元相关,这几个网格单元中的多边形的边都要进行检测。为此,一些方法提出,先计算每个网格单元中心点位于多边形内/外的属性,然后将测试点与其所在网格单元的中心点进行连线处理,并改进了网格中心点位于多边形内/外属性的判定计算方法和网格分辨率的优化处理,以及对一些歧义情况进行鲁棒处理的方法,它们可将均匀网格方法的预处理的计算复杂度降至O(N),将测试计算的复杂度的期望值降至O(1)。The determination calculation of a point within a polygon is a basic computing technology in computer graphics, computational geometry, and geographic information system processing. For a polygon, for any test point, it is necessary to determine whether the point is located within the polygon. There are many works in this area, among which the ray method and the method based on uniform meshing are widely used. The ray method is to emit a ray from the test point and count the number of times it intersects with the edges of the polygon. If the number of intersections is even, the test point is outside the polygon; otherwise, it is inside. The ray method requires an intersection test with each side of the polygon, and its computational complexity is O(N), where N is the number of sides of the polygon. In order to reduce the computational complexity, a variety of methods are proposed. First, a certain preprocessing is performed on the polygon, such as dividing the polygon into a trapezoid or a convex polygon, and then the local area where the test point is located can be quickly located, and then according to the situation of the local area. Judgmental calculation. This type of method can reduce the number of polygon edges that need to be detected, and the computational complexity can be reduced to O(logN). However, the preprocessing of such methods is more troublesome. To this end, the uniform grid method proposes to divide the bounding box of the polygon into a rectangular grid aligned with the coordinate axis, so that simple preprocessing can be performed, and the detection of test points can also be limited to the local area adjacent to the grid cell where it is located. area carried out. After comparing various methods, the uniform grid method is an efficient calculation method for point-in-polygon determination suitable for practical applications. Further, a method combining the ray method and the uniform grid method is proposed. First, the attributes of each grid intersection point inside/outside the polygon are calculated. The ray method is used to determine the calculation of points within the polygon. Since a mesh intersection is related to multiple mesh cells, the polygon edges in these mesh cells are all checked. To this end, some methods propose to first calculate the attribute that the center point of each grid unit is located inside/outside the polygon, then connect the test point to the center point of the grid unit where it is located, and improve the grid center point located in the polygon. The determination calculation method of inner/outer properties and the optimization of grid resolution, as well as the method of robust processing for some ambiguity cases, can reduce the computational complexity of preprocessing of the uniform grid method to O(N), Reduces the expected value of the complexity of the test computation to O(1).
虽然射线法与均匀网格法的结合将计算复杂度降至最低了,但其基本的测试射线与多边形的边的求交运算依然有较多的乘法、加法等计算,对于计算机处理器而言,计算代价还是比较高。Although the combination of the ray method and the uniform grid method minimizes the computational complexity, the basic intersection operation between the test ray and the polygon edge still requires a lot of multiplication, addition and other calculations. For computer processors , the computational cost is still relatively high.
发明内容SUMMARY OF THE INVENTION
为了解决上述技术问题,本发明提出一种计算机上使用简化求交计算的点在多边形内判定方法,以简化求交计算,并便于高效使用计算机的并行处理能力,由此提高点在多边形内的判断计算效率。本发明对射线法与网格法的结合进行进一步的改进。首先,将测试点发出的射线固定为平行于一个坐标轴的方向,这样就可预先知道交点的一个坐标,降低射线与多边形的边的求交计算复杂性。同时,对网格单元内的多边形的边的片段进行条状结构的管理,使得每个条状结构中的边均可能与位于该条状结构中的射线相交,这样,网格单元中大量与射线无相交的边将无需与射线进行求交计算,并且,这样也有利于使用GPU进行并行计算以更好地提高效率,因为无需进行费时的分叉处理以判断射线是否与边可能相交。In order to solve the above-mentioned technical problems, the present invention proposes a point-in-polygon determination method on a computer that simplifies the calculation of intersection, so as to simplify the calculation of intersection and facilitate the efficient use of the parallel processing capability of the computer, thereby improving the accuracy of points within the polygon. Judge the computational efficiency. The invention further improves the combination of the ray method and the grid method. First, the ray emitted by the test point is fixed in a direction parallel to a coordinate axis, so that a coordinate of the intersection point can be known in advance, and the computational complexity of the intersection between the ray and the polygon edge is reduced. At the same time, the strip-like structure is managed for the edge segments of the polygons in the mesh unit, so that the edges in each strip-like structure may intersect the rays located in the strip-like structure. Edges that the ray does not intersect will not need to intersect the ray, and it is also beneficial to use the GPU for parallel computing for better efficiency, because there is no need for time-consuming fork processing to determine whether a ray and an edge may intersect.
本发明的技术方案,为一种简化求交计算的点在多边形内判定方法,包括以下步骤:The technical solution of the present invention is a method for judging points within a polygon that simplifies the calculation of intersection, comprising the following steps:
步骤(1)将多边形的顶点坐标读入计算机内存,以生成多边形的包围盒,使得包围盒的边界均位于多边形外;对多边形的包围盒进行与坐标轴对齐的均匀网格划分,依据多边形的边与X轴或Y轴平行的网格线的交点将这些网格线划分成许多片段,并判断并记录各个网格线片段位于多边形内/外的属性;Step (1) read the vertex coordinates of the polygon into the computer memory to generate the bounding box of the polygon, so that the boundaries of the bounding box are all located outside the polygon; the bounding box of the polygon is divided into a uniform mesh aligned with the coordinate axis, according to the polygon's bounding box. The intersection of grid lines whose sides are parallel to the X-axis or Y-axis divide these grid lines into many segments, and determine and record the attributes of each grid line segment inside/outside the polygon;
步骤(2)在每个网格单元中生成条状结构,以管理网格单元中所含的多边形的边片段,在此,一个条状结构是由平行于Y轴或X轴的边作为边界构成,使得其中的多边形的边片段与该条状结构的两端边界均相交;Step (2) Generate a strip structure in each grid cell to manage the edge segments of the polygons contained in the mesh cell. Here, a strip structure is bounded by edges parallel to the Y axis or the X axis constituted so that the edge segments of the polygons intersect with both ends of the strip structure;
步骤(3)输入测试点进行检测时,利用单独处理器或并行的多个处理器,对于每一个测试点,从其发出一条平行于Y轴或X轴射线,由近至远逐步计算其与X轴或Y轴平行网格线的交点,直至该交点位于多边形内/外的属性能够由其所在的网格线的片段位于多边形内/外的属性获知,此时,终止射线的前行;Step (3) When inputting test points for detection, use a single processor or multiple processors in parallel, for each test point, emit a ray parallel to the Y-axis or X-axis from it, and gradually calculate its and X-axis from near to far. The intersection of the X-axis or Y-axis parallel grid lines, until the attribute that the intersection is located inside/outside the polygon can be known from the attribute that the segment of the grid line where it is located is located inside/outside the polygon, at this time, the forward line of the ray is terminated;
步骤(4)将要用到的相关条状结构调入,在单独处理器或并行处理器中,进行点在多边形内的判断计算;此时,对于从一个测试点发出的射线,计算其与所经过的条状结构中的多边形的边的相交情况,统计该射线与多边形的边的相交次数;In step (4), the relevant strip structures to be used are called in, and in a separate processor or a parallel processor, the judgment calculation of the point in the polygon is carried out; The intersection of the edges of the polygons in the strip-like structure passing through, and the number of intersections of the ray and the edges of the polygons is counted;
步骤(5)根据步骤(3)和(4)的结果,得知测试点位于多边形内/外的属性。Step (5) According to the results of steps (3) and (4), the attribute that the test point is located inside/outside the polygon is known.
进一步的,所述步骤(1)对网格线被其与多边形的边的交点所划分的片段位于多边形内/外属性的判断,其步骤是如下:Further, the step (1) determines that the segment divided by the intersection point of the grid line and the polygon edge is located in the polygon inside/outside attribute, and the steps are as follows:
(1.a)将一条网格线可看作是从其最外端的一个点发出的一条射线,并与多边形的边进行求交而得到这条网格线与多边形的边相交情况;(1.a) A grid line can be regarded as a ray emitted from a point at its outermost end, and the intersection of the grid line and the side of the polygon is obtained by intersecting it with the edge of the polygon;
(1.b)网格线的最外端的点是位于多边形外的。同时,根据点在多边形内判断计算的射线法,可知相邻的网格线片段位于多边形内/外的属性是交替变化的,由此,可知网格线上各个片段位于多边形内/外的属性。(1.b) The outermost points of the grid lines are located outside the polygon. At the same time, according to the ray method of judging and calculating the points within the polygon, it can be seen that the attributes of adjacent grid line segments inside/outside the polygon change alternately. .
进一步的,所述步骤(2)对于每个网格单元中的多边形的边片段,建立条状结构进行管理,其步骤如下:Further, in the step (2), for the edge segments of the polygons in each grid unit, a strip-like structure is established for management, and the steps are as follows:
(2.a)对于一个网格单元中的边片段,根据它们位于该网格单元中的端点的X或Y坐标值,生成许多平行于Y或X坐标轴的平行线,由这些平行线作为边界将该网格单元剖分成许多条状结构;(2.a) For the edge segments in a grid unit, according to the X or Y coordinate values of their endpoints located in the grid unit, generate many parallel lines parallel to the Y or X coordinate axis, and use these parallel lines as The boundary divides the grid cell into many strips;
(2.b)每个条状结构记录其所包含的边,无需记录该边片段的端点的坐标。(2.b) Each strip structure records the edges it contains, without recording the coordinates of the endpoints of the edge segments.
进一步的,所述步骤(3)对一个测试点进行测试时发出的射线是与条状结构的边界边平行的。Further, the ray emitted when a test point is tested in the step (3) is parallel to the boundary edge of the strip structure.
进一步的,所述步骤(3)对从测试点发出的射线与网格线进行由近至远的求交时,判断该交点位于多边形内/外的属性是否可由其所位于的网格线片段位于多边形内/外的属性来获知,并由此决定射线是否停止前进;如果可获知,则该射线停止前进;否则,该射线要继续往前与后续网格线进行求交处理。Further, in the step (3), when the ray emitted from the test point and the grid line are intersected from near to far, it is judged whether the attribute that the intersection is located in/outside the polygon can be determined by the grid line segment where it is located. The attributes located inside/outside the polygon are used to know whether the ray stops moving forward; if it can be known, the ray stops moving forward; otherwise, the ray needs to continue moving forward for intersection processing with subsequent grid lines.
进一步的,所述步骤(4)对一条测试用的射线与其经过的每个条状结构中的多边形的边进行求交测试时,无需在求交点前进行该边是否与射线相交的检测,因此便于使用计算机的并行能力,如减少使用GPU时的费时的分叉处理。计算射线与一条边的交点时,该交点的一个坐标值是已知的,就是该射线所垂直的坐标轴的坐标值;通过判断交点的另一个坐标值与测试点的另一个坐标值的大小,即可知射线与该边是否真的相交。Further, in the step (4), when a test ray and the edge of the polygon in each strip structure that it passes through are subjected to the intersection test, it is not necessary to detect whether the edge intersects the ray before the intersection point is obtained. Therefore, Facilitates the use of computer parallelism, such as reducing time-consuming fork processing when using GPUs. When calculating the intersection of a ray and an edge, a coordinate value of the intersection is known, which is the coordinate value of the coordinate axis perpendicular to the ray; by judging the size of another coordinate value of the intersection and another coordinate value of the test point , that is, to know whether the ray really intersects the edge.
进一步的,所述步骤(5)中综合步骤(3)和(4)的结果,得到测试点位于多边形内/外的属性,其处理如下:Further, in the step (5), the results of steps (3) and (4) are integrated to obtain the attribute that the test point is located inside/outside the polygon, and the processing is as follows:
(5.a)如果射线终止前行时与网格线的交点位于多边形内,则射线与多边形的边相交次数为偶数时,测试点位于多边形内;否则,在外;(5.a) If the intersection of the ray and the grid line is located within the polygon when the ray terminates and moves forward, the test point is located within the polygon when the number of intersections between the ray and the polygon's edge is an even number; otherwise, it is outside;
(5.b)如果射线终止前行时与网格线的交点位于多边形外,则射线与多边形的边相交次数为偶数时,测试点位于多边形外;否则,在内。(5.b) If the intersection of the ray and the grid line is located outside the polygon when the ray terminates and moves forward, the test point is located outside the polygon when the number of intersections between the ray and the edge of the polygon is an even number; otherwise, it is inside.
有益效果:Beneficial effects:
本发明能极大的节省求交计算中的乘法、加法等运算,并能高效使用计算机的并行处理能力如GPU等,可大幅提高点在多边形内的判定计算效率。The invention can greatly save operations such as multiplication and addition in the calculation of intersection, and can efficiently use the parallel processing capability of the computer such as GPU, etc., and can greatly improve the calculation efficiency of the point in the polygon.
附图说明Description of drawings
图1为多边形的边与网格线进行求交计算,然后根据交点情况,对水平网格线的片段进行其位于多边形内/外属性的判定。同时,对各个网格单元进行条状结构的组织,以有效管理各个网格单元中的边片段;Figure 1 shows the calculation of the intersection between the edge of the polygon and the grid line, and then according to the situation of the intersection, the segment of the horizontal grid line is determined to be located inside/outside the polygon. At the same time, each grid unit is organized in a strip structure to effectively manage the edge segments in each grid unit;
图2为测试点发出射线与水平网格线求交、并计算射线与所经过的条状结构中的边相交的情况,由此,可判定测试点是否位于多边形内;Fig. 2 is the intersection of the ray and the horizontal grid line of the test point, and the calculation of the intersection of the ray and the edge in the strip structure that passes through, thus, it can be determined whether the test point is located in the polygon;
图3为射线与多边形的边共线、或射线经过多边形的顶点时,射线与多边形的边相交统计处理方法;3 is a statistical processing method for the intersection of the ray and the edge of the polygon when the ray and the edge of the polygon are collinear, or when the ray passes through the vertex of the polygon;
图4为用于测试的4个多边形,(a)边数很少的多边形;(b)边数不多且分布较均衡的多边形;(c)边数很多但分布不均衡的多边形;(d)边数很多且分布较均衡的多边形。Figure 4 shows the 4 polygons used for testing, (a) a polygon with a small number of sides; (b) a polygon with a small number of sides and a relatively balanced distribution; (c) a polygon with a large number of sides but an uneven distribution; (d) ) is a polygon with many sides and a well-balanced distribution.
图5为本发明方法的流程图。Figure 5 is a flow chart of the method of the present invention.
具体实施方式Detailed ways
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整的描述。显然,所描述的实施例仅为本发明的一部分实施例,而不是全部的实施例,基于本发明中的实施例,本领域的普通技术人员在不付出创造性劳动的前提下所获得的所有其他实施例,都属于本发明的保护范围。The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, but not all of the embodiments. Based on the embodiments of the present invention, those of ordinary skill in the art can obtain all other The embodiments all belong to the protection scope of the present invention.
本发明是一种使用计算机简化求交计算的点在多边形内判定方法,能够用于工程中诸多场景,比如说,在地理信息系统中,对于一个区域的道路、楼房、公园等以多边形方式进行区域限定;当要对某些目标进行定位时,如某辆汽车是否位某条道路上、或位于某个公园内等,则可使用本发明进行快速检索。或者,当洪水浸漫一个城市时,洪水覆盖的区域可用多边形表达,则使用本发明可快速知道哪些位置还没有被洪水覆盖、是安全的。The present invention is a point-in-polygon determination method using a computer to simplify the calculation of intersection, which can be used in many scenarios in engineering, for example, in a geographic information system, for roads, buildings, parks, etc. Area limitation; when certain objects need to be located, such as whether a certain car is on a certain road or in a certain park, the present invention can be used for quick retrieval. Or, when flood floods a city, the area covered by flood can be represented by polygon, then using the present invention, it can quickly know which positions are not covered by flood and are safe.
根据本发明的一个实施例,不失一般性,本发明将条状结构和测试用的射线均按照平行Y轴的方向生成,且射线是从测试点向上射出(其Y坐标逐步增大的方向),如图1所示。According to an embodiment of the present invention, without loss of generality, the present invention generates both the strip structure and the ray for testing in a direction parallel to the Y axis, and the ray is emitted upward from the test point (the direction in which the Y coordinate gradually increases). ),As shown in Figure 1.
根据本发明的一个实施例,本发明上述方法分二个阶段:According to an embodiment of the present invention, the above-mentioned method of the present invention is divided into two stages:
第一阶段对多边形进行预处理;The first stage preprocesses the polygons;
第二阶段:根据预处理结果,判定一个测试点是否位于多边形内。The second stage: According to the preprocessing results, determine whether a test point is located within the polygon.
第一段的工作步骤如下:The working steps of the first paragraph are as follows:
1)检测多边形所有顶点的X坐标和Y坐标,得到最小的X坐标、最小的Y坐标、最大的X坐标和最大的Y坐标。然后将最小X坐标和最小的Y坐标均各自降低预定数值,将最大的X坐标和最大的Y坐标均各自增大预定数值,由此得到该多边形的包围盒,且包围盒的边界均位于多边形外。1) Detect the X and Y coordinates of all vertices of the polygon, and obtain the smallest X coordinate, the smallest Y coordinate, the largest X coordinate and the largest Y coordinate. Then, decrease the minimum X coordinate and the minimum Y coordinate by a predetermined value, respectively increase the maximum X coordinate and the maximum Y coordinate by a predetermined value, thereby obtaining the bounding box of the polygon, and the boundaries of the bounding box are located in the polygon. outside.
2)对包围盒进行网格分辨率优化的均匀网格剖分。根据“Jing Li and WenchengWang.2014.Point-In-Polygon Tests by Applying the Ray Crossing Method LocallyVia Grid Center Points.International Journal of Electrical Engineering 21,3(2014),85–92.”中的方法计算每个网格单元沿X、Y轴方向的长度Mx和My分别为:2) Uniform meshing with optimized mesh resolution for bounding boxes. Each grid was calculated according to the method in "Jing Li and Wencheng Wang. 2014. Point-In-Polygon Tests by Applying the Ray Crossing Method LocallyVia Grid Center Points. International Journal of Electrical Engineering 21, 3(2014), 85–92." The lengths Mx and My of the cell along the X and Y axes are:
Mx=k*sqrt(M*W/H),Mx=k*sqrt(M*W/H),
My=k*sqrt(M*H/W)My=k*sqrt(M*H/W)
这里,k为一个经验系数,一般设k=1;W和H分别为包围盒的宽度和高度;M为根据“Borutand Ivana Kolingerova.2001.A cell-based point-in-polygonalgorithm suitable for large sets of points.Computers&Geosciences 27,10(2001),1135–1145.”得到的网格单元总数,一般约为N,这里N为多边形的边数。Here, k is an empirical coefficient, generally set k = 1; W and H are the width and height of the bounding box, respectively; M is based on "Borut and Ivana Kolingerova.2001.A cell-based point-in-polygonalgorithm suitable for large sets of points.Computers&Geosciences 27,10(2001),1135–1145.” The total number of grid cells obtained is generally about N, where N is The number of sides of the polygon.
3)对每一条多边形的边,计算其与平行X轴的网格线的交点的X坐标,在此可根据相邻平行X轴的网格线之间的间距相等的特点,运用迭代加法,逐步地求得各个交点的X坐标。如图1中所示,边AB与平行X轴的网格线的交点的坐标x1与x2的间隔、x2与x3的间隔是相等的。3) For the edge of each polygon, calculate the X coordinate of its intersection with the grid lines parallel to the X axis. Here, iterative addition can be used according to the feature that the distance between adjacent grid lines parallel to the X axis is equal. Step by step to find the X coordinate of each intersection point. As shown in FIG. 1 , the interval between the coordinates x1 and x2 and the interval between x2 and x3 of the intersection of the side AB and the grid line parallel to the X axis are equal.
4)根据多边形的边与平行X轴的网格线的交点,每条平行X轴的网格线被划分成许多片段;这些片段位于多边形内/外的属性,可依据射线法得到,并记录。此时,对于多边形的边与平行X轴的网格线共线的情况,其在网格线上独自为一个片段,其位于多边形内/外属性标记为“歧义”。4) According to the intersection of the sides of the polygon and the grid lines parallel to the X axis, each grid line parallel to the X axis is divided into many segments; the attributes of these segments inside/outside the polygon can be obtained according to the ray method, and recorded . At this time, for the case where the edge of the polygon is collinear with the grid line parallel to the X axis, it is a segment by itself on the grid line, and its inside/outside polygon attribute is marked as "ambiguous".
5)根据多边形的边与网格线的交点,可知各个网格单元有哪些多边形的边的片段;这些边的片段的端点的X坐标,要么是边与平行X轴的网格线交点的X坐标,要么就是平行Y轴的网格线的X坐标。根据这些端点的X坐标,生成平行Y轴的垂直线作为条状结构的分界边线,以得到该网格单元的条状结构划分结果,并在各个条状结构中记录所包含的边(无需记录这些边片段的端点坐标)。一个条状结构的上端边界位于多边形内/外的属性,就是其位于所在平行X轴的网格线上的片段位于多边形内/外的属性,因为其上端边界一定是位于该网格线的一个片段内。如图1中包含C点的网格单元,被划分成3个条状结构。5) According to the intersection of the edge of the polygon and the grid line, you can know which polygonal edge fragments each grid unit has; the X coordinates of the endpoints of these edge fragments, or the X coordinate of the intersection of the edge and the grid line parallel to the X axis coordinate, or the X coordinate of the grid lines parallel to the Y axis. According to the X coordinates of these endpoints, a vertical line parallel to the Y axis is generated as the boundary line of the strip structure, so as to obtain the strip structure division result of the grid unit, and the included edges are recorded in each strip structure (no need to record the endpoint coordinates of these edge fragments). The attribute that the upper boundary of a strip structure is located inside/outside the polygon is the attribute that its segment on the grid line parallel to the X axis is located inside/outside the polygon, because its upper boundary must be one of the grid lines. within the fragment. As shown in Figure 1, the grid cell containing point C is divided into 3 strip structures.
在第二阶段的工作步骤如下:The working steps in the second stage are as follows:
(1)根据测试点的X坐标,生成一条平行Y轴的向上的射线。(1) According to the X coordinate of the test point, an upward ray parallel to the Y axis is generated.
(2)由近及远地计算射线与平行X轴的网格线的交点,直至该交点位于多边形的内/外属性可知为止。(2) Calculate the intersection of the ray and the grid line parallel to the X axis from the near and far, until the intersection is located at the inner/outer property of the polygon.
(3)对射线经过的每个条状结构,检测射线与其中的边的相交情况。此时,交点的X坐标是已知的,只需计算交点的Y坐标,由边的线方程与射线的X坐标即可求取。如果所得Y坐标比测试点的Y坐标小,则该边位于测试点下方,不会与射线相交;否则,就是一个真实的交点。如果是真实相交的,则统计相交次数增加1次;否则,不是真实相交情况,则不予统计。对于射线经过多边形的顶点或与多边形的边共线的情况,其相交情况统计按照图3中所示的方式进行:(3) For each strip-like structure that the ray passes through, the intersection of the ray and the edge therein is detected. At this time, the X coordinate of the intersection point is known, and it is only necessary to calculate the Y coordinate of the intersection point, which can be obtained from the line equation of the edge and the X coordinate of the ray. If the resulting Y coordinate is smaller than the Y coordinate of the test point, the edge is below the test point and will not intersect the ray; otherwise, it is a true intersection. If it is a real intersection, the number of statistical intersections will increase by 1; otherwise, if it is not a real intersection, it will not be counted. For the case where the ray passes through the vertex of the polygon or is collinear with the edge of the polygon, the intersection statistics are performed as shown in Figure 3:
3.1)如果射线所经过的多边形的一个顶点,其关联的2条边位于射线的同一侧,则该顶点相关的2条边均不进行统计处理;否则,该顶点相关的2条边,统计为射线与多边形的边相交1次。3.1) If a vertex of the polygon passed by the ray has two associated edges on the same side of the ray, the two edges related to the vertex are not statistically processed; otherwise, the two edges related to the vertex are counted as The ray intersects the edge of the
3.2)如果射线与多边形的一条边共线,则该边关联的2条边位于射线的同一侧,则该边及其关联的2条边均不进行统计处理;否则,该边及关联的2条边,统计为射线与多边形的边相交1次。3.2) If the ray is collinear with an edge of the polygon, and the 2 edges associated with the edge are on the same side of the ray, then the edge and its associated 2 edges are not subject to statistical processing; otherwise, the edge and the associated 2 The number of edges is counted as one intersection of the ray and the edge of the polygon.
(4)根据射线与平行X轴的网格线的交点位于多边形内/外的属性、以及射线与多边形的边的相交次数的统计,可知测试点是否位于多边形内。如果相交次数为偶数,测试点与交点具有相同的位于多边形内/外属性;否则,它们位于多边形内/外的属性相反。如图2中所示,相交的次数为奇数,测试点q位于多边形内,因为此时射线与水平网格线的交点位于多边形外。(4) According to the attribute that the intersection of the ray and the grid line parallel to the X-axis is located inside/outside the polygon, and the statistics of the number of intersections of the ray and the sides of the polygon, it can be known whether the test point is located in the polygon. If the number of intersections is even, the test points have the same inside/outside polygon properties as the intersection points; otherwise, their inside/outside polygon properties are opposite. As shown in Figure 2, the number of intersections is odd, and the test point q is inside the polygon because the intersection of the ray and the horizontal grid line is outside the polygon at this time.
本发明运可用计算机的GPU进行并行计算以提高检测速度。此时,先将所有条状结构装入GPU的全局存储器中;然后,依据GPU的并行处理能力,将要处理的一众测试点分组,使得各组由GPU中的一个处理器进行处理;最后,将各处理器要用到的相关条状结构调入,即可在GPU的各个处理器中并行地进行点在多边形内的判断计算。In the present invention, the GPU of the computer can be used for parallel computing to improve the detection speed. At this time, all strip structures are first loaded into the global memory of the GPU; then, according to the parallel processing capability of the GPU, a group of test points to be processed is grouped, so that each group is processed by one processor in the GPU; finally, By calling in the relevant strip structures to be used by each processor, the judgment calculation of points within the polygon can be performed in parallel in each processor of the GPU.
本发明在一台计算机上进行了测试,对比方法是目前所知最高效的网格方法GCP(Jing Li and Wencheng Wang.2014.Point-In-Polygon Tests by Applying the RayCrossing Method Locally Via Grid Center Points.International Journal ofElectrical Engineering 21,3(2014),85–92.)。根据多边形的边数多少、多边形的边的分布是否均匀,测试时选用了4个多边形进行测试,它们来自(Borutand IvanaKolingerova.2001.A cell-based point-in-polygon algorithm suitable for largesets of points.Computers&Geosciences 27,10(2001),1135–1145)的推荐。这4个多边形在图4中展示,(a)Pol 10,(b)Pol100,(c)Pol1249,(d)Pol28000,分别有10条边、100条边、1249条边和28000条边。测试时在多边形的包围盒中随机均匀地采样了1000 000个点作为测试点。相关测试所有的计算机配置有一个Intel(R)Core(TM)i7-8700 CPU,16GB内存,一个NVIDIA GeForce GTX 1080Ti GPU(有16GB的存储空间)。The present invention is tested on a computer, and the comparison method is the most efficient grid method GCP (Jing Li and Wencheng Wang. 2014. Point-In-Polygon Tests by Applying the RayCrossing Method Locally Via Grid Center Points. International Journal of Electrical Engineering 21, 3 (2014), 85–92.). According to the number of sides of the polygon and whether the distribution of the sides of the polygon is uniform, 4 polygons were selected for the test. They come from (Borut and Ivana Kolingerova. 2001. A cell-based point-in-polygon algorithm suitable for largesets of points. Computers & Geosciences 27, 10 (2001), 1135–1145). The 4 polygons are shown in Figure 4, (a) Pol 10, (b) Pol100, (c) Pol1249, (d) Pol28000, with 10 edges, 100 edges, 1249 edges and 28000 edges, respectively. During testing, 1000,000 points are randomly and uniformly sampled in the polygon's bounding box as test points. Related tests All computers were configured with an Intel(R) Core(TM) i7-8700 CPU, 16GB of RAM, and an NVIDIA GeForce GTX 1080Ti GPU (with 16GB of storage).
有关这2个方法对比的实验结果如下:The experimental results for the comparison of these two methods are as follows:
*加速比计算:(t1-t2)/t2,t1、t2分别为GCP和本发明所花的时间。*Calculation of speedup ratio: (t1-t2)/t2, t1 and t2 are the time spent by GCP and the present invention respectively.
完成这些测试所用各类计算量统计情况:Statistics of various computations used to complete these tests:
*re1、re2、re3分别为本发明所需乘法、加法和比较运算相较于GCP方法的相关运算量的节省情况,其计算为:本发明所需运算数量/GCP所需对应运算的数量。*re1, re2, and re3 are respectively the saving of the related computation amount of the multiplication, addition and comparison operations required by the present invention compared to the GCP method, and the calculation is: the required number of operations of the present invention/the number of corresponding operations required by GCP.
从以上实验结果可知,虽然本方法在预处理阶段需要较多的计算和较多的空间存储预处理结果,但增加的幅度不是很大。而在检测计算时,本发明可极大地节省所需乘法、加法、比较运算的数量,由此大幅提高检测速度;并且,由于高效利用计算机的并行处理能力,本发明在GPU上可获得比在CPU上更高的运算效率。It can be seen from the above experimental results that although this method requires more computation and more space to store the preprocessing results in the preprocessing stage, the increase is not very large. During detection and calculation, the present invention can greatly save the number of required multiplication, addition, and comparison operations, thereby greatly improving the detection speed; and, due to the efficient use of the parallel processing capability of the computer, the present invention can obtain more Higher computing efficiency on the CPU.
本发明未详细阐述部分属于本领域公知技术。The parts of the present invention that are not described in detail belong to the well-known technology in the art.
以上所述,仅为本发明部分具体实施方式,但本发明的保护范围并不局限于此。任何熟悉本领域的人员在本发明揭露的技术范围内,可轻易想到的变化或替换,都应涵盖在本发明的保护范围之内。The above description is only a part of the specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily conceived by any person skilled in the art within the technical scope disclosed by the present invention shall be included within the protection scope of the present invention.
Claims (6)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010703960.XA CN111915665B (en) | 2020-07-21 | 2020-07-21 | A method for determining points in polygons using simplified intersection calculation on computer |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010703960.XA CN111915665B (en) | 2020-07-21 | 2020-07-21 | A method for determining points in polygons using simplified intersection calculation on computer |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111915665A CN111915665A (en) | 2020-11-10 |
CN111915665B true CN111915665B (en) | 2022-05-31 |
Family
ID=73281319
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010703960.XA Active CN111915665B (en) | 2020-07-21 | 2020-07-21 | A method for determining points in polygons using simplified intersection calculation on computer |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111915665B (en) |
Families Citing this family (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112926123B (en) * | 2021-03-17 | 2022-09-02 | 杭州品茗安控信息技术股份有限公司 | Method, device, equipment and storage medium for determining position relation of building member |
CN113034515A (en) * | 2021-03-22 | 2021-06-25 | 易视腾科技股份有限公司 | Bounding box tree-based polygon clipping method, electronic device and storage medium |
CN115222806B (en) * | 2022-09-20 | 2022-12-09 | 腾讯科技(深圳)有限公司 | Polygon processing method, device, equipment and computer readable storage medium |
CN118068442A (en) * | 2024-04-17 | 2024-05-24 | 四川吉埃智能科技有限公司 | A method and system for realizing vehicle-mounted tunnel intrusion inspection based on laser scanning |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101114379A (en) * | 2007-09-07 | 2008-01-30 | 中国科学院软件研究所 | A method to determine whether a point is inside a polygon |
CN102629375A (en) * | 2012-01-06 | 2012-08-08 | 中国科学院软件研究所 | Method for determining whether point is located in polygon |
CN105184837A (en) * | 2015-08-31 | 2015-12-23 | 武汉云空间地理信息技术有限公司 | Vector polygon rasterization algorithm and system |
WO2016116070A2 (en) * | 2015-01-23 | 2016-07-28 | 中兴通讯股份有限公司 | Method and device for determining locational relationship |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20120082373A1 (en) * | 2010-09-30 | 2012-04-05 | Konica Minolta Systems Laboratory, Inc. | Method and system for determining whether a point is inside a polyhedron |
-
2020
- 2020-07-21 CN CN202010703960.XA patent/CN111915665B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101114379A (en) * | 2007-09-07 | 2008-01-30 | 中国科学院软件研究所 | A method to determine whether a point is inside a polygon |
CN102629375A (en) * | 2012-01-06 | 2012-08-08 | 中国科学院软件研究所 | Method for determining whether point is located in polygon |
WO2016116070A2 (en) * | 2015-01-23 | 2016-07-28 | 中兴通讯股份有限公司 | Method and device for determining locational relationship |
CN105184837A (en) * | 2015-08-31 | 2015-12-23 | 武汉云空间地理信息技术有限公司 | Vector polygon rasterization algorithm and system |
Non-Patent Citations (4)
Title |
---|
Point-in-Polygon Tests by Determining Grid Center Points in Advance;Jing Li 等;《IEEE》;20161006;1-7 * |
加强局部简便计算的点在多边形内的高效判定;王盛春等;《图学学报》;20190415(第02期);267-273 * |
基于凸片段分解和格网的点在多边形中的可见边检测;高天豪等;《计算机辅助设计与图形学学报》;20130815(第08期);1114-1120 * |
基于网格中心点的点在多边形内的高效判定;李静等;《软件学报》;20120915(第09期);2481-2488 * |
Also Published As
Publication number | Publication date |
---|---|
CN111915665A (en) | 2020-11-10 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111915665B (en) | A method for determining points in polygons using simplified intersection calculation on computer | |
Cignoni et al. | Optimal isosurface extraction from irregular volume data | |
TWI303039B (en) | Methods, computing apparatus and computing system for ray tracing , and machine-accessible medium for application in ray tracing | |
Rong et al. | GPU-assisted computation of centroidal Voronoi tessellation | |
CN114861500B (en) | Method and system for automatically generating finite element model of tunnel structure based on three-dimensional point cloud | |
US11551412B2 (en) | Systems and methods for traversing implied subdivision hierarchical level of detail content | |
KR101705072B1 (en) | Image processing apparatus and method | |
CN105005072B (en) | The PML border dimensionally seismic wave propagating mode utilizing CUDA intends method | |
CN102629375A (en) | Method for determining whether point is located in polygon | |
Liu et al. | Change detection of mobile LIDAR data using cloud computing | |
US10559125B2 (en) | System and method of constructing bounding volume hierarchy tree | |
CN105787998B (en) | The two-grid of more ball particles searches for contact detecting method in a kind of emulation of discrete element | |
KR101089638B1 (en) | Ray tracing device and method for cross inspection acceleration and rendering device and method using same | |
CN108615262A (en) | A kind of magnanimity model method for detecting parallel collision based on GPU | |
US11417073B2 (en) | System and method for generating hierarchical level-of-detail measurements for runtime calculation and visualization | |
CN115935673A (en) | A ray-tracing-based FDTD meshing method and system | |
Qin et al. | Fast and Memory‐Efficient Voronoi Diagram Construction on Triangle Meshes | |
Horvat et al. | Ray-casting point-in-polyhedron test | |
CN115346005B (en) | Data structure construction method for object plane grid based on nested bounding box concept | |
Li et al. | Fast and robust point-in-spherical-polygon tests using multilevel spherical grids | |
Lehericey et al. | Ray-traced collision detection: Interpenetration control and multi-gpu performance | |
Popescu et al. | Efficient and Robust From-Point Visibility | |
EP4459559A2 (en) | Ray tracing | |
CN119227466B (en) | Finite difference time domain modeling method and system for undulating terrain and irregular abnormal body | |
Lai et al. | A cell subdivision strategy for r‐nearest neighbors computation |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |