Line segment spatial relationship detection algorithm and equipment based on tolerance value

文档序号:7572 发布日期:2021-09-17 浏览:28次 中文

1. A line segment space relation detection algorithm based on tolerance values is characterized by comprising the following steps:

1) inputting end points P1 and P2 of a segment P, end points Q1 and Q2 of a segment Q, and tolerance value tolerance which is more than 0;

2) judging whether the circumscribed rectangles of the line segment P, Q are intersected after being amplified according to the tolerance value tolerance, if so, turning to the step 3), otherwise, the output line segment P, Q is not intersected, and ending the process;

3) respectively calculating minimum distance values of four endpoints P1, P2, Q1 and Q2 of the two line segments P, Q from the corresponding other line segment;

4) when two or more minimum distance values are smaller than the tolerance value tolerance in the four minimum distance values, judging that the two line segments P, Q are in a collinear relationship, and turning to the step 5); if a minimum distance value is smaller than the tolerance value tolerance, turning to step 6); if the minimum distance value smaller than the tolerance value tolerance does not exist, turning to the step 7);

5) the output line segments P, Q are collinear and intersected, and the process is finished;

6) the output line segment P, Q is crossed at a single point, and the process ends;

7) judging whether the circumscribed rectangles of the line segment P, Q are intersected, if so, turning to the step 8), otherwise, the output line segment P, Q is not intersected, and ending the process;

8) judging whether the end points P1 and P2 are on the same side of the end point line segment Q, if so, the output line segment P, Q is not intersected, and the process is ended; otherwise, the output line segments P, Q are crossed, and the crossing point is calculated; judging whether the end points Q1 and Q2 are on the same side of the line segments P of the end points P1 and P2, if so, the output line segments P, Q are not intersected, and the process is ended; otherwise output line segments P, Q intersect and the intersection is calculated.

2. The tolerance value-based line segment spatial relationship detection algorithm of claim 1, wherein: the method for judging whether the circumscribed rectangles of the line segment P, Q are intersected after being amplified according to the tolerance in the step 2) comprises the following steps:

21) calculating the maximum and minimum horizontal coordinates of four endpoints P1(x1, y1), P2(x2, y2), Q1(x1 ', y 1'), Q2(x2 ', y 2'), and setting the maximum and minimum horizontal coordinates as minPx, maxPx, minQx and maxQx;

22) if the condition (minPx > maxQx + tolerance) or (maxPx < minQx-tolerance) is met, outputting disjointness, otherwise, turning to step 23);

23) calculating the maximum and minimum vertical coordinates of four endpoints P1(x1, y1), P2(x2, y2), Q1(x1 ', y 1'), Q2(x2 ', y 2'), and setting the maximum and minimum vertical coordinates as minPy, maxPy, minQy and maxQy;

24) if the condition (minPy > maxQy + tolerance) or (maxPy < minQy-tolerance) is satisfied, the outputs are disjoint, otherwise the outputs are crossed.

3. The tolerance value-based line segment spatial relationship detection algorithm of claim 1, wherein: the minimum distance value calculated in the step 3) adopts a geometric method, and the method for judging the minimum distance value distance from the endpoint P1(x, y) to the line segment Q comprises the following steps:

31) judging whether the end points Q1 and Q2 of the line segment Q are coincident, if not, turning to the step 23), if yes, calculating distance:

32) let r beWherein r represents the meaning: when r is 0, P1 and Q1 coincide; when r is 1, P1 and Q2 coincide; when r is<At 0, P1 is in the reverse extension direction of line segment Q; when r is>When 1, P1 is in the positive extension line direction of the line segment Q; when 0 is present<r<1, P1 is between Q1Q 2;

33) calculating the minimum distance value distance according to the r value:

when r is less than or equal to 0,

when r is greater than or equal to 1,

when r is more than 0 and less than 1,

4. the tolerance value-based line segment spatial relationship detection algorithm of claim 1, wherein: the method for judging whether the endpoints P1 and P2 are on the same side of the line segment Q in the step 8) comprises the following steps:

81) for an end point P1(x, y) and a straight line segment Q, a starting point Q1(x1, y1) of the line segment Q, an end point (x2, y2) of the Q has a vector A (x1-x, y1-y) formed by an end point P1 and the Q, a vector B (x2-x, y2-y), and a vector C, a cross-product formula is established:

C=A×B

C=(x1-x)*(y2-y)–(y1-y)*(x2-x)

82) direction of the endpoint P1 with respect to the straight line segment Q is judged: when C >0, LEFT; when C <0, it is RIGHT; when C is 0, STRAIGHT;

83) the direction of each vertex relative to the other line segment is judged by adopting the methods of the steps 81) and 82) for the endpoint P2 and the line segment Q, the endpoint Q1 and the line segment P, and the endpoint Q2 and the line segment P respectively, and a straddle experiment is carried out.

5. The tolerance value-based line segment spatial relationship detection algorithm of claim 4, wherein: the method for the transistion experiment in the step 83) comprises the following steps:

84) inputting a vertex sequence P1(x1, y1) of a segment P, P2(x2, y2), a vertex sequence Q1(x3, y3) of a segment Q, Q2(x4, y4) and a tolerance value tolerance > 0;

85) calculating the directions of vertexes P1 and P2 of the line segment P relative to the line segment Q, and setting the vertexes P1 and P2 as P1Q and P2Q;

86) if the conditions (P1Q >0 and P2Q >0) or (P1Q <0 and P2Q <0) are met, then vertices P1 and P2 are on the same side of segment Q and output line segment P, Q does not intersect; otherwise go to step 87);

87) calculating directions of vertexes Q1 and Q2 of the line segment Q with respect to the line segment P, and setting the directions as Q1P and Q2P;

88) if the conditions (Q1P >0 and Q2P >0) or (Q1P <0 and Q2P <0) are met, then vertices Q1 and Q2 are on the same side of segment P and output line segment P, Q does not intersect; otherwise go to step 89);

89) and calculating the intersection point of the line segments P and Q, and intersecting the output points.

6. The tolerance value-based line segment spatial relationship detection algorithm of claim 1, wherein: the calculation method of the intersection point in the step 8) comprises the steps of calculating the intersection point by using the stable cross product value of the long double-precision numerical value; calculating an intersection point using projection and interpolation; the intersection point is calculated using an exact algorithm.

7. The tolerance value-based segment spatial relationship detection algorithm of claim 6, wherein: the function of calculating the intersection point is defined as GetIntersection (point1, point2, point3, point4), where point1 and point2 are end points of the first input line segment, point3 and point4 are end points of the second input line segment, and an error allowable value klnterctioneror is set for the calculated intersection point, where klnterctioneror takes eight times the maximum error value DBL _ ERR arithmetically calculated by the double-precision value on the processor platform.

8. The tolerance value-based line segment spatial relationship detection algorithm of claim 6, wherein: the method for calculating the intersection point of the line segments P and Q by adopting a geometrical calculation method comprises the following steps:

b1=(y2-y1)*x1+(x1-x2)*y1

b2=(y4-y3)*x3+(x3-x4)*y3

D=(x2-x1)*(y4-y3)-(x4-x3)*(y2-y1)

D1=b2*(x2-x1)-b1*(x4-x3)

D2=b2*(y2-y1)-b1*(y4-y3)

x0=D1/D

y0=D2/D

in the formula, the endpoints P1(x1, y1) and P2(x2, y2) of the segment P, the endpoints Q1(x3, y3) and Q2(x4, y4) of the segment Q, and the intersection point of P and Q is I (x0, y 0).

9. An apparatus, comprising:

at least one processor; and the number of the first and second groups,

a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,

the memory stores instructions executable by the at least one processor to enable the at least one processor to perform a tolerance value-based line segment spatial relationship detection algorithm as claimed in any one of claims 1 to 8.

10. A computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the tolerance value-based line segment spatial relationship detection algorithm of any one of claims 1 to 8.

Technical Field

The geographic information data model is a hybrid data model which expresses continuous geographic entities by discrete spatial data and comprises a vector data model, a grid data model and vector grid integration. The vector data model comprises geometric objects such as points, lines and planes, and vector geographic information data generated according to the vector data model is one of important geographic information digital products in China, namely a digital line Drawing (DLG). The geometric engine for vector data processing is an algorithm library set, wherein line segment spatial relationship judgment is the bottommost algorithm, and the algorithm applied to the geometric engine for data processing has an important role in geographic information software. The spatial relationship of the two line segments is: disjoint (NO _ INTERSECTION), Point-INTERSECTION, and COLLINEAR-INTERSECTION. Where the point intersection in turn distinguishes the case where two line segments intersect crosswise (True) or where two line segments intersect at end points (fast). The existing line segment space relation judgment algorithm is to solve the line segment space relation in the storage precision range of floating point type numbers in a computer, and belongs to strict geometric relation. In the production of digital geographic information data, the storage and calculation accuracy is far lower than that of a computer, and the spatial relationship of line segments is different from the traditional strict geometric relationship due to the factor of considering tolerance values. The existing judgment algorithm for the line segment spatial relationship in the geographic information software has certain limitation in application because the line segments are aggregated according to the tolerance value and then the spatial relationship is judged by adopting a geometric calculation method.

The high-efficiency line segment space relation judgment algorithm in the calculation geometry and the computer graphics at the present stage has the following three problems in different degrees: firstly, the error factor of computer expression is not considered, the actual intersection point is not necessarily on the straight line due to the rounding reason of the computer expression according to the intersection point coordinate calculated by two straight line segments; secondly, tolerance factors are not considered, because the produced digital products have different mapping scales, the coordinate values of the geometric objects and the topological relation among the line segments have different precision requirements, and when the tolerance is not considered, the coordinate values of the geometric objects are expressed by the highest precision of a computer, and the topological relation among the line segments is also a strict geometric relation, thereby not only causing unnecessary resource waste, but also having errors that the judgment result of the spatial relation does not meet the actual requirement; and thirdly, the performance of the algorithm is unstable, the line segment relation judgment algorithm has higher execution frequency in a geographic information software system, the geometric forms needing to be calculated are various, a processor platform for supporting different calculation capabilities of various terminals is needed, and the algorithm in the current stage does not consider the calculation time complexity and the space complexity under the common influence of the factors.

Disclosure of Invention

The invention aims to overcome the defects of the prior art, provides a line segment spatial relationship detection algorithm and equipment based on tolerance values, can improve the calculation performance, and provides a geographic analysis algorithm which can be directly used for various geographic information software for geographic information vector data processing.

In order to achieve the above object, the line segment spatial relationship detection algorithm based on tolerance value designed by the present invention is characterized in that the method comprises the following steps:

1) inputting end points P1 and P2 of a segment P, end points Q1 and Q2 of a segment Q, and tolerance value tolerance which is more than 0;

2) judging whether the circumscribed rectangles of the line segment P, Q are intersected after being amplified according to the tolerance value tolerance, if so, turning to the step 3), otherwise, the output line segment P, Q is not intersected, and ending the process;

3) respectively calculating minimum distance values of four endpoints P1, P2, Q1 and Q2 of the two line segments P, Q from the corresponding other line segment;

4) when two or more minimum distance values are smaller than the tolerance value tolerance in the four minimum distance values, judging that the two line segments P, Q are in a collinear relationship, and turning to the step 5); if a minimum distance value is smaller than the tolerance value tolerance, turning to step 6); if the minimum distance value smaller than the tolerance value tolerance does not exist, turning to the step 7);

5) the output line segments P, Q are collinear and intersected, and the process is finished;

6) the output line segment P, Q is crossed at a single point, and the process ends;

7) judging whether the circumscribed rectangles of the line segment P, Q are intersected, if so, turning to the step 8), otherwise, the output line segment P, Q is not intersected, and ending the process;

8) judging whether the end points P1 and P2 are on the same side of the end point line segment Q, if so, the output line segment P, Q is not intersected, and the process is ended; otherwise, the output line segments P, Q are crossed, and the crossing point is calculated; judging whether the end points Q1 and Q2 are on the same side of the line segments P of the end points P1 and P2, if so, the output line segments P, Q are not intersected, and the process is ended; otherwise output line segments P, Q intersect and the intersection is calculated.

Preferably, the method for judging whether the circumscribed rectangles of the line segment P, Q intersect after being amplified according to the tolerance in step 2) is as follows:

21) calculating the maximum and minimum horizontal coordinates of four endpoints P1(x1, y1), P2(x2, y2), Q1(x1 ', y 1'), Q2(x2 ', y 2'), and setting the maximum and minimum horizontal coordinates as minPx, maxPx, minQx and maxQx;

22) if the condition (minPx > maxQx + tolerance) or (maxPx < minQx-tolerance) is met, outputting disjointness, otherwise, turning to step 23);

23) calculating the maximum and minimum vertical coordinates of four endpoints P1(x1, y1), P2(x2, y2), Q1(x1 ', y 1'), Q2(x2 ', y 2'), and setting the maximum and minimum vertical coordinates as minPy, maxPy, minQy and maxQy;

24) if the condition (minPy > maxQy + tolerance) or (maxPy < minQy-tolerance) is satisfied, the outputs are disjoint, otherwise the outputs are crossed.

Preferably, the minimum distance value calculated in step 3) is determined geometrically by the following method:

31) judging whether the end points Q1 and Q2 of the line segment Q are coincident, if not, turning to the step 23), if yes, calculating distance:

32) let r beWherein r represents the meaning: when r is 0, P1 and Q1 coincide; when r is 1, P1 and Q2 coincide; when r is<At 0, P1 is in the reverse extension direction of line segment Q; when r is>When 1, P1 is in the positive extension line direction of the line segment Q; when 0 is present<r<1, P1 is between Q1Q 2;

33) calculating the minimum distance value distance according to the r value:

when r is less than or equal to 0,

when r is greater than or equal to 1,

when r is more than 0 and less than 1,

preferably, the method for determining whether the endpoints P1 and P2 are on the same side of the line segment Q in the step 8) is as follows:

81) for an end point P1(x, y) and a straight line segment Q, a starting point Q1(x1, y1) of the line segment Q, an end point (x2, y2) of the Q has a vector A (x1-x, y1-y) formed by an end point P1 and the Q, a vector B (x2-x, y2-y), and a vector C, a cross-product formula is established:

C=A×B

C=(x1-x)*(y2-y)-(y1-y)*(x2-x)

82) direction of the endpoint P1 with respect to the straight line segment Q is judged: when C is more than 0, LEFT is obtained; when C is less than 0, the compound is RIGHT; when C is 0, STRAIGHT;

83) the direction of each vertex relative to the other line segment is judged by adopting the methods of the steps 81) and 82) for the endpoint P2 and the line segment Q, the endpoint Q1 and the line segment P, and the endpoint Q2 and the line segment P respectively, and a straddle experiment is carried out.

Preferably, the method for setting up the experiment in the step 83) is as follows:

84) inputting a vertex sequence P1(x1, y1) of a segment P, P2(x2, y2), a vertex sequence Q1(x3, y3) of a segment Q, Q2(x4, y4) and a tolerance value tolerance > 0;

85) calculating the directions of vertexes P1 and P2 of the line segment P relative to the line segment Q, and setting the vertexes P1 and P2 as P1Q and P2Q;

86) if the conditions (P1Q >0 and P2Q >0) or (P1Q <0 and P2Q <0) are met, then vertices P1 and P2 are on the same side of segment Q and output line segment P, Q does not intersect; otherwise go to step 87);

87) calculating directions of vertexes Q1 and Q2 of the line segment Q with respect to the line segment P, and setting the directions as Q1P and Q2P;

88) if the conditions (qlp >0 and Q2P >0) or (qlp <0 and Q2P <0) are met, then vertices Q1 and Q2 are on the same side of segment P and output line segments P, Q do not intersect; otherwise go to step 89);

89) and calculating the intersection point of the line segments P and Q, and intersecting the output points.

Preferably, the calculating method of the intersection in step 8) includes calculating the intersection with a stable cross product of the long double precision type value; calculating an intersection point using projection and interpolation; the intersection point is calculated using an exact algorithm.

Preferably, the function for calculating the intersection point is defined as getinteraction (point1, point2, point3, point4), where point1 and point2 are end points of a first input line segment, and point3 and point4 are end points of a second input line segment, and an error allowable value kinteractioneror is set for the calculated intersection point, where kinteractioneror takes eight times the maximum error value DBL _ ERR arithmetically calculated by a double-precision value on the processor platform.

Preferably, the method for calculating the intersection point of the line segments P and Q by adopting the method for calculating geometry comprises the following steps:

b1=(y2-y1)*x1+(x1-x2)*y1

b2=(y4-y3)*x3+(x3-x4)*y3

D=(x2-x1)*(y4-y3)-(x4-x3)*(y2-y1)

D1=b2*(x2-x1)-b1*(x4-x3)

D2=b2*(y2-y1)-b1*(y4-y3)

x0=D1/D

y0=D2/D

in the formula, the endpoints P1(x1, y1) and P2(x2, y2) of the segment P, the endpoints Q1(x3, y3) and Q2(x4, y4) of the segment Q, and the intersection point of P and Q is I (x0, y 0).

The invention also proposes a device comprising: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,

the memory stores instructions executable by the at least one processor, characterized in that the instructions are executable by the at least one processor to enable the at least one processor to perform a tolerance value based line segment spatial relationship detection algorithm as described above.

The invention further provides a computer-readable storage medium, which stores a computer program, and is characterized in that the computer program, when executed by a processor, implements the line segment spatial relationship detection algorithm based on the tolerance value.

The invention provides a line segment space relation detection algorithm and device based on tolerance values, which mainly solve the following key problems:

1. designing a calculation flow of an algorithm: the method for calculating the geometry does not fully consider the similarity and heterogeneity rules of the geospatial data, and a good algorithm flow is designed according to the calculation frequency and the calculation complexity in the application, so that the comprehensive performance of the algorithm in the application process can be effectively improved;

2. a method for judging whether the external rectangles corresponding to the two line segments are intersected in the tolerance range is realized;

3. the judgment method for realizing the collinearity of the two line segments comprises the following steps: the collinear relationship with tolerance and the collinear relationship with geometry change, and the situation is no longer applicable to the geometric equation;

4. the method for calculating the intersection point of the two line segments comprises the following steps: calculating an intersection point according to a spatial relation with tolerance, and calculating the intersection point according to a geometric method;

5. the robustness problem of the algorithm under extreme conditions is solved. Due to the rounding mechanism of the floating point number of the computer, particularly under the condition that two line segments intersect at a very small angle, the intersection point is difficult to accurately calculate, and the phenomenon that the calculated intersection point of the two line segments is not on the input two line segments occurs with a certain probability.

The invention has the beneficial effects that:

1. tolerance parameters are introduced into a line segment spatial relationship judgment algorithm, the calculation process is improved, and the calculation performance is improved;

2. the invention provides an efficient algorithm for geographic information vector data processing, can be used for improving a data processing geometric engine algorithm, and can also be directly used for geographic analysis algorithms of various geographic information software;

3. the method is based on open source geographic information software, relevant program source codes are modified based on the technical scheme, meanwhile, a solution for judging the geographic unit topological relation based on tolerance is formed, and a basic algorithm library is generated;

4. the invention applies the basic algorithm library to geostationary earth space planning software with independent intellectual property rights, and realizes various technical links from a line segment space relation judgment node to a geographic unit space relation judgment node and finally to a production application node and the like which run through the upper and lower streams of a geographic information software technical chain in a geographic information data production management technical route.

Drawings

FIG. 1 is a flowchart of a line segment spatial relationship detection algorithm based on tolerance values according to the present invention.

Fig. 2 is a conceptual diagram of tolerance values.

FIG. 3 is a diagram illustrating the intersection of bounding rectangles with tolerance values.

FIG. 4 is a schematic diagram of two line segments when the bounding rectangles do not intersect and the line segments intersect.

FIG. 5 is a schematic diagram of two intersecting line segments without intersecting line segments.

FIG. 6 is a diagram illustrating the intersection of the line segments P and Q when there is no tolerance.

FIG. 7 is a schematic diagram of the intersection of the line segments P and Q when there is no tolerance.

FIG. 8 is a diagram illustrating the intersection of the line segments P and Q when there is no tolerance.

Fig. 9 is a schematic diagram of the intersection of the line segments P and Q when there is no tolerance.

Fig. 10 is a schematic diagram of a single-point intersection of two line segments without tolerance values.

FIG. 11 is a schematic diagram of line segment non-intersection without tolerance.

Fig. 12 is a schematic diagram of two line segments intersecting at a single point and hasprop ═ True.

Fig. 13 is a database interface created in the geostationary earth space planning application software.

Fig. 14 is an interface for detecting validity of vector data in geostationary space planning application software.

FIG. 15 is a schematic illustration of an invalid pattern.

FIG. 16 is a schematic view of vector surface graph topology.

Detailed Description

The present invention will be described in further detail below with reference to the accompanying drawings and geostationary space planning and library building software as examples, but the embodiment should not be construed as limiting the present invention.

The line segment spatial relationship detection algorithm based on the tolerance value, disclosed by the invention, as shown in figure 1, comprises the following steps:

1) inputting end points P1 and P2 of a segment P, end points Q1 and Q2 of a segment Q and tolerance value tolerance, wherein tolerance is more than 0;

2) judging whether the circumscribed rectangles of the line segment P, Q are intersected after being amplified according to the tolerance value tolerance, if so, turning to the step 3), otherwise, the output line segment P, Q is not intersected, and ending the process;

3) respectively calculating minimum distance values of four endpoints P1, P2, Q1 and Q2 of the two line segments P, Q from the corresponding other line segment;

4) when two or more minimum distance values are smaller than the tolerance value tolerance in the four minimum distance values, judging that the two line segments P, Q are in a collinear relationship, and turning to the step 5); if a minimum distance value is smaller than the tolerance value tolerance, turning to step 6); if the minimum distance value smaller than the tolerance value tolerance does not exist, turning to the step 7);

5) the output line segments P, Q are collinear and intersected, and the process is finished;

6) the output line segment P, Q is crossed at a single point, and the process ends;

7) judging whether the circumscribed rectangles of the line segment P, Q are intersected, if so, turning to the step 8), otherwise, the output line segment P, Q is not intersected, and ending the process;

8) judging whether the end points P1 and P2 are on the same side of the line segment Q, if so, the output line segment P, Q is not intersected, and the process is ended; otherwise, the output line segments P, Q are crossed, and the crossing point is calculated; judging whether the end points Q1 and Q2 are on the same side of the line segment P, if so, the output line segment P, Q is not intersected, and the process is ended; otherwise output line segments P, Q intersect and the intersection is calculated.

The overall flow of the algorithm provided by the invention is shown in fig. 1, and according to the principles of low complexity and high calculation frequency priority, whether the external rectangles intersect within the tolerance range is judged firstly, then the collinear intersection condition is judged, the single-point intersection condition is judged, and finally, a cross-over experiment is carried out to judge whether the rectangles intersect. The process reduces the judgment times according to the actual application experience, preferentially adopts comparison operation, saves reusable calculated values and has higher calculation performance. The tolerance value is used for measuring the proximity between two points to determine whether the two points are the same, and as shown in fig. 2, the unit of the quantity of the tolerance value tolerance is consistent with the unit of the geographic coordinate system where the line segment is located. When the distance between two points is less than the tolerance, the two points are considered to be coincident.

The method for judging whether the circumscribed rectangles of the line segment P, Q intersect after being amplified according to the tolerance in the step 2) comprises the following steps:

21) calculating the maximum and minimum horizontal coordinates of four endpoints P1(x1, y1), P2(x2, y2), Q1(x1 ', y 1'), Q2(x2 ', y 2'), and setting the maximum and minimum horizontal coordinates as minPx, maxPx, minQx and maxQx;

22) if the condition (minPx > maxQx + tolerance) or (maxPx < minQx-tolerance) is met, outputting disjointness, otherwise, turning to step 23);

23) calculating the maximum and minimum vertical coordinates of four endpoints P1(x1, y1), P2(x2, y2), Q1(x1 ', y 1'), Q2(x2 ', y 2'), and setting the maximum and minimum vertical coordinates as minPy, maxPy, minQy and maxQy;

24) if the condition (minPy > maxQy + tolerance) or (maxPy < minQy-tolerance) is satisfied, the outputs are disjoint, otherwise the outputs are crossed.

The pseudo code for judging whether the external rectangles corresponding to the two line segments respectively intersect within the tolerance range is as follows:

the vertex sequence P1(x1, y1) of the segment P, P2(x2, y2), the vertex sequence Q1(x1 ', y 1') of the segment Q, Q2(x2 ', y 2') and the tolerance value tolerance >0 are input.

The outputs are either intersecting or disjoint.

Step 1, the maximum and minimum horizontal coordinates of P1, P2, Q1 and Q2 are calculated and are set as minPx, maxPx, minQx and maxQx.

Step 2 if minPx > maxQx + tolerance V.V.

then output disjoint

And 3, calculating the maximum and minimum vertical coordinates of P1, P2, Q1 and Q2, and setting the maximum and minimum vertical coordinates as minPy, maxPy, minQy and maxQy.

Step 4 if minPy > maxQy + tolerance, maxPy < minQy-tolerance

then output disjoint

else output crossing

The intersection relation of the rectangles can be judged by comparing the maximum and minimum vertical and horizontal coordinates, the complexity of comparison operation is less than four times of operation, the algorithm carries out O (12) times of comparison operation and O (4) times of four times of operation at most, and carries out O (3) times of comparison operation and O (1) times of four times of operation at minimum.

The method for calculating the minimum distance value in the step 3) adopts a geometric method, and the method for judging the minimum distance value distance from the endpoint P1(x, y) to the line segment Q comprises the following steps:

31) judging whether the end points Q1 and Q2 of the line segment Q are coincident, if not, turning to the step 23), if yes, calculating distance:

32) let r beWherein r represents the meaning: when r is 0, P1 and Q1 coincide; when r is 1, P1 and Q2 coincide; when r is less than 0, P1 is in the reverse extension direction of the line segment Q; when r is greater than 1, P1 is in the positive extension direction of line segment Q; p1 is between Q1Q2 when 0 < r < 1;

33) calculating the minimum distance value distance according to the r value:

when r is less than or equal to 0,

when r is greater than or equal to 1,

when r is more than 0 and less than 1,

the minimum distance value from the vertex to the straight line segment is calculated by adopting a geometrical method, and the pseudo code of the method is as follows:

the vertices P (x, y), the vertex sequence Q1(x1, y1) of the line segment Q, Q2(x2, y2) are input.

And outputting the minimum distance value distance from P to Q.

Step 1 if vertex Q1 and vertex Q2 coincide

And outputting the distance.

Step 2 is providedWherein r represents the meaning: when r is 0, P and Q1 coincide; when r is 1, P and Q2 coincide; when r is less than 0, P is in the reverse extension direction of Q1Q 2; when r is larger than 1, P is in the positive extension line direction of Q1Q 2; when 0 < r < 1, P is between Q1Q 2.

if r<=0

And outputting the distance.

else if r>=1

then

And outputting the distance.

else

And outputting the distance.

The method for judging the collineation comprises the following steps:

the vertex sequence P1(x1, y1) of the segment P, P2(x2, y2), the vertex sequence Q1(x1 ', y 1') of the segment Q, Q2(x2 ', y 2') and the tolerance value tolerance >0 are input.

Output disjoint (NO _ interrupt), or POINT (POINT _ interrupt) and hasprep ═ false and INTERSECTION intPt [0], or POINT-intersect (POINT _ interrupt) and hasprep ═ true and INTERSECTION intPt [0], or COLLINEAR-intersect (collinar _ interrupt) and INTERSECTIONs intPt [0], intPt [1 ].

Step 1 calculates the minimum distance from each vertex of two segments to another segment, set as disP1Q 2, disP2Q1Q2, disP 1P2, and disP 2P1P2, respectively.

Step 2 if disP1Q 2 ^ distance disc 2Q1Q2 ^ distance

the n output COLLINEAR _ INTERSECTION,

intPt[0]=P1,intPt[1]=P2。

step 3 if distQ 1P1P2 ^ distQ 2P1P2 ^ tolerance

the n output COLLINEAR _ INTERSECTION,

intPt[0]=Q1,intPt[1]=Q2。

step 4 if disP1Q 2 < ═ tolerance Λ disP 1P2 < ═ tolerance

if the distance value from P1 to Q1 is < ═ tolerance

the then P1 and Q1 are coincided

Output POINT _ interrupt, intPt [0] ═ P1.

else

the n output COLLINEAR _ INTERSECTION,

intPt[0]=P1,intPt[1]=Q1。

step 5 if disP1Q 2 ^ distance ^ disP 2P1P2 ^ distance

if the distance value from P1 to Q2 is < ═ tolerance

the then P1 and Q2 are coincided

Output POINT _ interrupt, intPt [0] ═ P1.

else

the n output COLLINEAR _ INTERSECTION,

intPt[0]=P1,intPt[1]=Q2。

step 6 if disP2Q1Q2 ^ distance ^ disP 1P1P2 ^ distance

if the distance value from P2 to Q1 is < ═ tolerance

the then P2 and Q1 are coincided

Output POINT _ interrupt, intPt [0] ═ P2.

else

the n output COLLINEAR _ INTERSECTION,

intPt[0]=P2,intPt[1]=Q1。

step 7 if disP2Q1Q2 ^ distance ^ disP 2P1P2 ^ distance

if the distance value from P2 to Q2 is < ═ tolerance

the then P2 and Q2 are coincided

Output POINT _ interrupt, intPt [0] ═ P2.

else

the n output COLLINEAR _ INTERSECTION,

intPt[0]=P2,intPt[1]=Q2。

step 8 if disP1Q1Q2 < ═ tolerance

the n output POINT _ INTERSECTION, intPt [0] ═ P1.

Step 9 if disP2Q1Q2 < ═ tolerance

the n output POINT _ INTERSECTION, intPt [0] ═ P2.

Step 10 if disQ1P 2 < ═ tolerance

the n output POINT _ INTERSECTION, intPt [0] ═ Q1.

Step 11 if disQ2P1P2 < ═ tolerance

the n output POINT _ INTERSECTION, intPt [0] ═ Q2.

The method for determining whether the end points P1 and P2 are on the same side of the line segment Q in the step 8) includes:

81) for an end point P1(x, y) and a straight line segment Q, a starting point Q1(x1, y1) of the line segment Q, an end point (x2, y2) of the Q has a vector A (x1-x, y1-y) formed by an end point P1 and the Q, a vector B (x2-x, y2-y), and a vector C, a cross-product formula is established:

C=A×B

C=(x1-x)*(y2-y)-(y1-y)*(x2-x)

82) direction of the endpoint P1 with respect to the straight line segment Q is judged: when C is more than 0, LEFT is obtained; when C is less than 0, the compound is RIGHT; when C is 0, STRAIGHT;

83) judging the direction of each vertex relative to the other line segment by adopting the methods of the steps 81) and 82) for the endpoint P2 and the line segment Q, the endpoint Q1 and the line segment P and the endpoint Q2 and the line segment P respectively, and carrying out a straddle experiment;

84) inputting a vertex sequence P1(x1, y1) of a segment P, P2(x2, y2), a vertex sequence Q1(x3, y3) of a segment Q, Q2(x4, y4) and a tolerance value tolerance > 0;

85) calculating the directions of vertexes P1 and P2 of the line segment P relative to the line segment Q, and setting the vertexes P1 and P2 as P1Q and P2Q;

86) if the conditions (P1Q >0 and P2Q >0) or (P1Q <0 and P2Q <0) are met, then vertices P1 and P2 are on the same side of segment Q and output line segment P, Q does not intersect; otherwise go to step 87);

87) calculating directions of vertexes Q1 and Q2 of the line segment Q with respect to the line segment P, and setting the directions as Q1P and Q2P;

88) if the conditions (Q1P >0 and Q2P >0) or (Q1P <0 and Q2P <0) are met, then vertices Q1 and Q2 are on the same side of segment P and output line segment P, Q does not intersect; otherwise go to step 89);

89) and calculating the intersection point of the line segments P and Q, and intersecting the output points.

If the spatial relationship of two line segments is not in 3) and the circumscribed rectangles intersect, the spatial relationship needs to be computed geometrically.

The directions of the vertexes of the two line segments relative to the other line segment are firstly calculated, and three directions of LEFT (LEFT), RIGHT (RIGHT) and STRAIGHT (STRAIGHT) are defined. The basic principle of calculating the vertex with respect to the direction of the straight line segment is cross multiplication of two-dimensional vectors, and for an arbitrary vector U (x1, y1), a vector V (x2, y2), a vector C, the cross multiplication formula is shown in equation (1) (2) (3):

C=U×V (1)

U×V=x1*y2-y1*x2 (2)

U×V=|U|*|V|*Sin(θ) (3)

the angle θ has a positive and negative component, which indicates that the vector C has two opposite directions, and the direction of the vector C is perpendicular to the plane of the vector U, V, and is determined according to the "right-hand rule".

For any vertex P (x, y) and the starting point Q1(x1, y1) and the ending point (x2, y2) of the straight line segment Q, there are vector A (x1-x, y1-y) and vector B (x2-x, y2-y) formed by P and Q. According to equations (1) and (2), there are equations (4) and (5):

C=A×B (4)

C=(x1-x)*(y2-y)-(y1-y)*(x2-x) (5)

wherein, the direction of the vertex P relative to the straight line segment Q: when C is more than 0, LEFT is obtained; when C is less than 0, the compound is RIGHT; when C is 0, STRAIGHT.

And then, performing a straddle experiment according to the direction of each vertex relative to the other line segment, wherein when the two line segments have a straddle relation, an intersection point is bound to exist, and conversely, the two line segments are bound not to intersect.

Its pseudo code is as follows:

the vertex sequence P1(x1, y1) of the input segment P, P2(x2, y2), the vertex sequence Q1(x3, y3) of the segment Q, Q2(x4, y4), and the tolerance value tolerance > 0.

Outputs disjoint (NO _ interrupt) or POINT-intersect (POINT _ interrupt) and INTERSECTIONs intPt [0] and hasProper ═ true.

Step 1 calculates the directions of the vertices P1 and P2 of the line segment P with respect to the line segment Q, and sets them as P1Q and P2Q, respectively.

Step 2 if (p1q is more than 0A p2q is more than 0), V-shaped (p1q is more than 0A p2q is more than 0)

the ten vertices P1 and P2 are on the same side of line segment Q

Output disjoint (NO _ interrupt).

Step 3 calculates the directions of the vertices Q1, Q2 of the line segment Q with respect to the line segment P, and sets Q1P and Q2P, respectively.

Step 4 if (q1p is more than 0A q2p is more than 0), V-shaped (q1p is less than 0A q2p is less than 0)

the ten vertices Q1 and Q2 are on the same side of line segment P

Output disjoint (NO _ interrupt).

Step 5, calculating the intersection point of the line segments P and Q, and setting the intersection point as I

Output POINT INTERSECTION (POINT _ INTERSECTION), hasprep ═ true, intPt [0] ═ I.

For a line segment P and end points P1 and P2 thereof, a line segment Q and end points Q1 and Q2 thereof, the intersection point of P and Q is set as I, and a function of calculating the intersection point is defined as getinteraction (point1, point2, point3, point4), wherein point1 and point2 are end points of an input line segment 1, point3 and point4 are end points of an input line segment 2, and a return value is the calculated intersection point I. There is the following law, as shown in equations (13), (14), (15):

GetIntersection(P2,P1,Q1,Q2)=GetIntersection(P1,P2,Q2,Q1) (13)

GetIntersection(P2,P1,Q1,Q2)=GetIntersection(P1,P2,Q1,Q2) (14)

GetIntersection(Q1,Q2,P1,P2)=GetIntersection(P1,P2,Q1,Q2) (15)

the invention improves the robustness of the calculation intersection point algorithm, utilizes the intersection rule of two line segments, sets an error allowable value (kInternectionError) for the calculated intersection point, and ensures that the calculated intersection point is closest to a theoretical intersection point, wherein the kInternectionError value is eight times of the maximum error value (DBL _ ERR) arithmetically calculated by a double-precision numerical value on a processor platform, and more complex technical schemes such as extended precision and the like need to be adopted. The algorithm mainly realizes three technical schemes: the first method is to calculate the intersection point by the stable cross product value of the long double precision numerical value; the second is to calculate the intersection point using projection and interpolation, while taking care to minimize the cancellation error, which is applicable to double-precision and long double-precision versions; the third is to calculate the intersection point using an exact algorithm.

The two line segments in the step 5 are intersected, and the intersection point of the two line segments is calculated by adopting a geometric calculation method according to the equations (6) to (12). For the endpoints P1(x1, y1) and P2(x2, y2) of the above two segments P, the endpoints Q1(x3, y3) and Q2(x4, y4) of the segment Q, and the intersection point of P and Q is I (x0, y0), there are:

b1=(y2-y1)*x1+(x1-x2)*y1

b2=(y4-y3)*x3+(x3-x4)*y3

D=(x2-x1)*(y4-y3)-(x4-x3)*(y2-y1)

D1=b2*(x2-x1)-b1*(x4-x3)

D2=b2*(y2-y1)-b1*(y4-y3)

x0=D1/D

y0=D2/D

in the embodiment, the circumscribed rectangles corresponding to two line segments do not intersect in the tolerance range

FIG. 3 is a schematic diagram of the algorithm for determining the non-intersection of the circumscribed rectangles corresponding to two line segments within the tolerance range. In the figure, the dotted line part is a rectangle obtained by amplifying a rectangle circumscribed to the line segment Q according to the tolerance value tolerance, and the rectangle does not intersect with the circumscribed rectangle of the line segment P in the tolerance range, so that the outgoing line segment P and the line segment Q are determined to be necessary to be not intersected, and the algorithm return value is NO _ INTERSECTION.

In the embodiment, the corresponding circumscribed rectangles of the two line segments intersect within the tolerance range

Fig. 4 is a schematic diagram of a situation that the external rectangles corresponding to two line segments respectively intersect within the tolerance range according to the algorithm, and a distance value from an end point Q1 of the line segment Q to the line segment P is smaller than the tolerance value tolerance. The distance value may be the minimum point-to-straight line segment distance or the difference between the horizontal and vertical components of the point at the intersection of the point-to-straight line segment minimum distance and the point. Different defined distance values can be selected according to the application requirements of the algorithm.

In the embodiment, the circumscribed rectangles corresponding to the three or two line segments intersect within the tolerance range

Fig. 5 shows a geometric relationship in which the circumscribed rectangles intersect and the line segments do not intersect, the line segment Q crosses both sides of the line segment P, and the corresponding circumscribed rectangles intersect, and the distance from the end point P2 of the line segment P to the line segment Q is greater than the tolerance value, so that the two line segments do not intersect.

In the above three embodiments, fig. 3, fig. 4, and fig. 5 respectively show different types of geometric relationships between two line segments: fig. 3 shows a geometric relationship in which two line segments are necessarily not intersected when the circumscribed rectangles of the two line segments are not intersected in the tolerance range, fig. 4 shows a geometric relationship in which the circumscribed rectangles are not intersected when the two line segments are not tolerant, the circumscribed rectangles are intersected when there is a tolerance range, and fig. 5 shows a geometric relationship in which the circumscribed rectangles are intersected and the line segments are not intersected, wherein the line segment Q crosses two sides of the line segment P, the corresponding circumscribed rectangles are intersected, and the distance from the end point P2 of the line segment P to the line segment Q is greater than the tolerance value, so that the two line segments are not intersected. In practical application, whether the external rectangle of another line segment has an intersection relation in the tolerance range is judged according to the external rectangle of any line segment of the tolerance value, and if the external rectangle does not intersect in the tolerance range, the two line segments must not intersect. According to the first law of geography: everything is related and the related things are more closely related (but near things are related to each other). Since the number of non-adjacencies between real geographic units is often much larger than the number of adjacencies, this approach reduces the amount of computation in the geographic computation to a large extent.

The collinearity judgment method in geometry is not suitable for the situation with tolerance value, and the following lists that the spatial relationship can be judged as the collinearity intersection situation when some tolerance value exists, and the collinearity judgment method in geometry does not belong to the collinearity relationship situation.

Example four collinearity determination with no tolerance and with tolerance discrimination

FIG. 6 is a diagram illustrating the case where the segments P and Q do not intersect without tolerance. When the tolerance exists, the minimum distances from the four end points to the line segments are all smaller than the tolerance value, the two line segments are considered to be completely overlapped and accord with the collinear relationship, and the collinear part is P1Q 2.

FIG. 7 is a diagram illustrating the intersection of the line P and the line Q when there is no tolerance. When the tolerance exists, the minimum distance from three end points to the line segment is smaller than the tolerance, the P2 and the Q2 are considered to be coincident, the Q1 is on the line segment P1P2 and accords with a collinear relationship, and the collinear part is Q1Q2 or Q1P 2.

FIG. 8 is a diagram illustrating the case where the segments P and Q do not intersect without tolerance. When the tolerance exists, the distances from three end points to the line segment are smaller than the tolerance value, P2 is considered to be coincident with Q2, Q1 is on the line segment Q and accords with a collinear relationship, and the collinear part is P1Q2 or P1P 2.

FIG. 9 shows that line segment P intersects Q without tolerance. When there is a tolerance, the distances from the three end points to the line segment are smaller than the tolerance value, and the P2 is considered to be coincident with the Q2, and the P1 is on the line segment Q, and the collinear part is P1Q2 or P1P 2.

From the generalizations for the various collinearity cases: respectively calculating the minimum distance values from the four end points of the two line segments to the other line segment corresponding to the four end points respectively, and calculating four minimum distance values in total, wherein if three or more minimum distance values are smaller than the tolerance value, the two line segments are in a collinear relationship certainly; if there are two minimum distance values less than the tolerance value, then there is a collinear intersection or a single point intersection; if there is one or less minimum distance value less than the tolerance, then there must not be a co-linear relationship.

Example five two line segments with no tolerance value intersect at a single point

Fig. 10 is a schematic diagram of the intersection of single points of two line segments judged to have no tolerance value by the algorithm, the distance from the point Q1 to the line segment P is 0, the intersection point is Q1, and hasprop is false.

Example six two line segments without tolerance value are disjoint

Fig. 11 is a schematic diagram of the two line segments determined to be disjoint without a tolerance value by the algorithm. When there is tolerance, point Q1 is considered to be on line segment P, the intersection point is taken as Q1, and hasprop is false.

Example seven two line segments intersect at a single point

Fig. 12 is a schematic diagram of two line segments intersecting at a single point and hasprop ═ True.

In geostationary earth space planning software, vector data are stored in a postgres database, and the software provides functions of data processing, space analysis and the like for postgis vector data. The software is used for vector data processing and spatial analysis on the premise that geometric elements involved in calculation conform to simple element rules (SFS). Therefore, as shown in the layer topology checking interface shown in fig. 14, the software platform provides a geometric validity check rule for the vector layer. Fig. 14 is an interface for detecting validity of vector data in the geostationary space planning application software, and dark color portions are invalid patterns detected when there is a tolerance. And for the geometric surface elements, the graphic effectiveness requires that non-adjacent line segments cannot intersect, otherwise, the graphic effectiveness is judged to be an invalid graphic. As shown in fig. 13, tolerance values are set in the database library interface, and in default, the graph validity detection is performed according to the values set here, and the elements marked in dark colors in the graph are detected invalid graphs. Fig. 15 lists a schematic diagram of one of the invalid patterns belonging to the tolerance range. Take fig. 15 as an example to explain: if the tolerance value is not set, the line segment AB and the line segment CD are not adjacent and are not intersected, and the graph is judged to be an effective graph; if the tolerance value is set on the library building interface of FIG. 13 and the distance from point D to segment AB is less than the tolerance value, segment AB and segment CD will be judged to be crossed, the graph will be judged to be invalid, and the graph will be covered with false marks.

FIG. 16 illustrates the application of line segment spatial relationship detection in determining the topological relationship between two surface elements. FIG. 16 is a schematic diagram showing the topological relation between two vector surface graphs, a schematic diagram showing the details of the intersection relation after the graph is amplified according to a certain scale, and a schematic diagram after the graph is amplified in a rectangular frame. When there is no tolerance, because node P of graph I is inside graph II, according to the calculation rule of the nine-intersection model, P is inside graph II, the value of the nine-intersection matrix is as shown in table 1, and the topological relationship between graph I and graph II is determined to be overlapping (overlaps). When there is a tolerance, since the minimum distance value from the node P of the graph I to the boundary of the graph II is smaller than the tolerance value, P is determined to be on the boundary of the graph II, so there is no intersection in the interior of the graph I and the graph II, i.e., the matrix has a value of-1 at [0, 0], and the boundary intersection of the graph I and the graph II is a line, i.e., the matrix has a value of 1 at [1, 1], and the boundary of the graph I and the interior of the graph II is a line, i.e., the matrix has a value of 1 at [1, 0], and the topological relation between the graph I and the graph II is determined to be adjacent (touches), as shown in table 2. Note: -2 represents intersection non-null, -1 represents intersection null, 0 represents intersection point set, 1 represents intersection line set, 2 represents intersection plane set, Interior represents inner region of geometry, Boundary represents Boundary of geometry, and exteror represents outer region of geometry.

TABLE 1 nine-way matrix values without tolerance

TABLE 2 nine-way matrix values with tolerance

The technical scheme is implemented in geographic information software, and is related to modification of a plurality of basic libraries. The current geographic information software can be divided into open-source software and closed-source business software, and only the open-source software can be selected to implement the technical scheme. The method is based on open source geographic information software, modifies related program source codes based on the technical scheme, forms a solution for judging the geographic unit topological relation based on tolerance, and generates a basic algorithm library. The basic algorithm library is applied to geostationary earth space planning software with independent intellectual property rights, and various technical links from a line segment space relation judgment node to a geographic unit space relation judgment node and finally to a production application node and the like which run through the upper stream and the lower stream of a geographic information software technical chain in a geographic information data production management technical route are realized.

Finally, it should be noted that the above detailed description is only for illustrating the technical solution of the patent and not for limiting, although the patent is described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that the technical solution of the patent can be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the patent, which should be covered by the claims of the patent.

完整详细技术资料下载
上一篇:石墨接头机器人自动装卡簧、装栓机
下一篇:一种基于称重原理的计数方法

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!