Summary of the invention
This goal of the invention is to solve the tolerance problem of asking for floating-point numerical evaluation in the scan-line algorithm, particularly solve in Floating-point Computation and exist under the prerequisite of error, dynamic tolerance computational problem when handling the data of varying number level with scan-line algorithm, thereby whether correct decision event point is on line segment, guarantee the correctness of scan-line algorithm, can correctly try to achieve all intersection points, further, guarantee the correct realization of overlay analysis, made Geographic Information System that geography information more accurately can be provided.
For achieving the above object, according to an aspect of the present invention, provide a kind of dynamic tolerance setup method based on scan-line algorithm, it comprises following steps:
According to the function in the intersection point of line segments computation process, utilize formula i to calculate the absolute error of intersecting point coordinate;
According to determining the whether function in the process on line segment of point, utilize the absolute error of formula i and intersecting point coordinate to calculate tolerance;
Formula i
Wherein f represents about variable x
1, x
2... x
nFunction, δ (f (x
1, x
2... x
n)) absolute error of representative function f;
This tolerance is set to the whether tolerance on line segment of judging point.
According to a further aspect in the invention, provide a kind of method of definite intersection point of line segments, it comprises following steps:
1) receives line segment, obtain the case point structure;
2) obtain minimum case point from the incident dot structure, related line segment is handled and the update event dot structure to putting therewith;
When 3) the case point structure is empty, the set of output intersection point;
Step 2 wherein) comprises: calculate intersection point of line segments, determine that point whether on line segment, calculates tolerance according to formula i, and this tolerance is set to the whether tolerance on line segment of judging point.
Effect of the present invention is to determine the tolerance behind the floating point arithmetic, further, be that computing at the floating-point numerical value of expression point coordinate and line segment etc. exists under the prerequisite of error, whether correct decision event point is on line segment, guarantee the correctness of scan-line algorithm, can correctly try to achieve all intersection points, further, guarantee the correct realization of overlay analysis, made Geographic Information System that geography information more accurately can be provided.
Embodiment
Method about error analysis, the situation that actual science is calculated is complicated, each calculating can produce new round-off error and propagate the front and respectively go on foot existing error, and operation times is often many, often in tens million of, the accumulation of error subtracts when increasing when being, simply increases to estimate it is worthless by dullness, because the error bound that obtain like that are actual conditions head and shoulders above, even can cover useful results fully.In actual applications, offset owing to repeatedly round off in the computing, historical facts or anecdotes border error should be much smaller.
Repeatedly the propagation of error of computing is separate, and can not obtain extreme value simultaneously, should adopt a kind of mode of optimism to carry out error analysis.According to " the 3 σ principle " of normal distribution, the cumulative errors of n computing guarantees with 99.97% probability:
Wherein ε is the error bound of measuring or calculating, ε
kIt is each error of measuring.
It is irrelevant that this formula shows that error produces with transmission.
In physics or chemical experiment analysis, measuring error is the coefficient results of various small accidentalia, inevitable Normal Distribution.The following Gaussian error Transfer Formula of the normal employing of error analysis that causes by these Normal Distribution and separate measuring error participation calculating:
Usually,
Because the precision of floating number all is limited,, in computation process, can produce error inevitably so represent point coordinate and line segment with floating number in the scan-line algorithm.Floating-point Computation is through after the computing repeatedly, by initial equally distributed round-off error cause the inevitable Normal Distribution of cumulative errors (0, σ).Though initial error is distributed as even distribution,, must be similar to Normal Distribution through after the calculating in several steps.Therefore Gaussian error Transfer Formula commonly used in physico-chemical measurement or calculating is applied to Error Analysis of Floating-point Computation.
The flow process of scan-line algorithm is described in detail as follows as shown in Figure 2:
At first initialization: with all line segment end points initialization event dot structure Q and ordering; The current activation line segment of initialization bundle R is null set; Current all line segment ordered sets are S; Current output intersection point set I is null set.
Judge whether Q is empty, if null set is then calculated and finished, I is the set of the intersection point that calculates and get; Otherwise the following operation of circulation is null set until Q.
From Q, obtain minimum case point p, and it is deleted from Q.Searching among the R with p is the line segment of terminal point, deletes segment; Searching among the R through p and p according to tolerance is not the line segment of line segment end points, and then this some intersection point that is properly intersect is exported this and put I; And, the order of these line segments is inverted; From S, choose and from then on put initial line segment, from S, delete, join among the R and go.More than after three operations whenever find a line segment, calculate the line segment that finds and be adjacent the intersection point that line segment may exist, go if exist then intersection point added among the Q.
Just produce error in the time of can calculating the intersection point that may exist at algorithm analysis, the intersection point of promptly trying to achieve is not the theoretical intersection point of two line segments just, but small skew is arranged, as shown in Figure 1.And also can continue to produce error when to search among the R through p and p be not the line segment of line segment end points, and need whether judge this error result, thereby correctly whether judging point p is on line segment less than tolerance.
Judge in the scan-line algorithm whether current event spot generally realizes with following formula on line segment.
det=(point.x-head.x)*(tail.y-point.y)-(point.y-head.y)*(tail.x-point.x)
Wherein point is current point, and head and tail are respectively the two-end-points of current line segment, and x, y represent horizontal stroke, ordinate value a little respectively.When det equaled 0, some point was on line segment; Otherwise some point is not on line segment.Need consider error at this.If judge det==0 simply, because the error problem of Floating-point Computation, can not the correct line segment that must be certain point; If set a quiescent value, the error because of Floating-point Computation is relevant with the size of numerical value again, and then this quiescent value may be correct to some data, may be incorrect to other data.
The invention provides a kind of scan-line algorithm that dynamically arranges tolerance, the general scope of numerical value is determined in the outsourcing of the line segment of intersection point as requested, according to calculating the intersection point step that may exist, calculates the absolute error of the intersecting point coordinate of this process generation; Not the line segment step of line segment end points according to searching among the R again, promptly determine the whether step on line segment of some p, and the intersection point absolute error that has obtained is further calculated the error that this process produces, i.e. tolerance yet through p and p; Carry out determining the line segment of case point p according to this tolerance in the process in scan-line algorithm.
More than analyze the data of NATURAL DISTRIBUTION are all set up.The length and width that promptly comprise the minimum boundary rectangle of figure layer with outsourcing are 10
6The order of magnitude, general relative coordinate value are that the coordinate difference of point in a certain subrange is 10 on x or y coordinate direction
5The data instance of the order of magnitude specifically describes the present invention.
The intersection point that calculating may exist, and it is as follows to calculate the detailed process of the error that this process produces, wherein two line segments are respectively with head0 and tail0, and head1 and tail1 are starting point and terminal point, and institute's find intersection is inter; X and y represent horizontal stroke, ordinate respectively; Δ is represented relative error; δ represents absolute error:
The coordinate difference of difference zequin and terminal point:
double?zx=tail0.x-head0.x;
double?zy=tail0.y-head0.y;
double?ox=tail1.x-head1.x;
double?oy=tail1.y-head1.y;
double?ozx=head0.x-head1.x;
double?ozy=head0.y-head1.y;
More than in six groups of computings the coordinate figure of each parameter all be accurate, the subtraction of two accurate numerical value then, its result has only round-off error.The relative round-off error of double-precision floating points is Δ=1.11 * 10
-16Round-off error and computation process are irrelevant, are the errors that the result of calculation that obtains need round off and cause to show in computing machine.
double?denominator=zx*oy-zy*ox;
This computing has propagation of error three times, twice multiplication, a subtraction; Multiplication transmits relative error, for
Round-off error is 1.11 * 10
-16This relative error refers to that itself and round-off error are separate owing to calculate the transmission error that causes.Therefore,
According to data characteristic, zx, zy, ox, oy, ozx, ozy etc. are less than 10
5The quantitative series certificate.
δ(zx*oy)=δ(zy*ox)=2×10
-16×10
10=2×10
-6。
According to 10
XThe data of the order of magnitude, it is long-pending to be about 10 (
2X-1)The statistical law of the order of magnitude, obtaining denominator is 10
9The data of the order of magnitude.
Δ (denominator)=2.8 * 10
-6÷ 10
-9=2.8 * 10
-151.11 * 10
-16Round-off error, therefore begin no longer to consider round-off error from this step.
double?numerator0=ox*ozy-oy*ozx;
Numerator0 is identical with the error analysis of above denominator.
double?Ua=numerator0/denominator;
Transmit relative error:
Coordinate that inter orders is set for (head0.x+Ua*zx, head0.y+Ua*zy), to this coordinate figure, its absolute error is δ=3.9 * 10
-15* 10
5=3.9 * 10
-10
Searching among the R through p and p is not the line segment of line segment end points, just judges the p point whether on line segment, and whether end points by judging line segment and p are ordered the leg-of-mutton area that constituted is that 0 operation is finished, if area be 0 point on line segment.This computation process is not considered round-off error, because some p herein is the intersection point that possible exist of aforementioned calculation, its error has been far longer than the round-off error of floating point representation.The detailed process of this calculating is as follows, wherein, two end points of the corresponding line segment of head and tail, x and y represent horizontal stroke, ordinate respectively:
double?x1=p.x-head.x;
double?y1=p.y-head.y;
double?x2=tail.x-p.x;
double?y2=tail.y-p.y;
At this head, all non-intermediate result of the data of tail all is initial input data, does not have error, then according to the error of the intersection point of trying to achieve, above the absolute error of each difference be 3.9 * 10
-10
double?det=x1*y2-x2*y1;
This computing has propagation of error three times, twice multiplication, and a subtraction is only considered transmission error: Δ (x1)=Δ (y1)=Δ (x2)=Δ (y2)=3.9 * 10
-10÷ 10
5=3.9 * 10
-15
So error
Then this value is according to inventive concept, according to the dynamic tolerance of data computation.
Whether the absolute value of judging det is less than error delta=7.8 * 10
-5If, less than then put on line segment, otherwise line segment is this point only.
More than be to 10
6The error analysis of quantitative series certificate.In The whole analytical process, some hypothesis are arranged, i.e. under the order of magnitude of outsourcing, all be some natural data, promptly the order of magnitude of coordinate is less than the order of magnitude of outsourcing.To any outsourcing is (10
X) data of the order of magnitude, be brought into above-mentioned analytic process, can get its tolerance computing formula and be: 7.8 * 10
(2X-17), wherein X is the order of magnitude.This tolerance only is only applicable to use the method for stating and calculates the thinking whether intersection point and judging point cross line segment.According to inventive concept,, different error tolerance computing formula is arranged at different calculation process.
In the test of true geodata, the tolerance that calculates with this formula has guaranteed algorithm validity, and experimental data is as shown in the table:
Table 1 test is 10 with the outsourcing of above-mentioned code analysis
6Data result
Test data |
Det value sum |
The det absolute value is greater than 10
-5Quantity
|
Det minimal value (* 10
-5)
|
Det maximum value (* 10
-5)
|
Data one |
62488 |
145 |
-3.52 |
4.13 |
Data two |
30228 |
40 |
-1.38 |
4.13 |
Data three |
258288 |
24 |
-1.92 |
1.82 |
Data four |
351726 |
2 |
-5.79 |
1.88 |
The present invention calculate and tolerance be 7.8 * 10
-5, on show true geodata test specification the dynamic tolerance that calculates with the present invention with very big probability ground greater than the error that produces in the computation process, show that this method can guarantee algorithm validity.
The present invention adopts floating number to represent for numerical value and needs judge that the problem whether numerical value equates fully provides a kind of solution thinking.
Should be noted that and understand, under the situation that does not break away from the desired the spirit and scope of the present invention of accompanying Claim, can make various modifications and improvement the present invention of foregoing detailed description.Therefore, the scope of claimed technical scheme is not subjected to the restriction of given any specific exemplary teachings.