Hello all together,
I have tried to understand as JTS handles with the inaccuracy from doubles. As already mentioned there still appear mistakes with my calculations, because some values differ around 0.000000000004, although they are same. To solve this problem I have carried out some tests with JTS and tried to comprehend. On this occasion, I found the following difference between two equal geometrical cases: 1. Fall: Linestring1: "LINESTRING(4 1, 4 7)"; Linestring2: "LINESTRING(1 4, 7 4)"; With the intersection „linestring1.intersection(linestring2)“ the point „POINT (4 4)“ came out as expected. The question „linestring1.intersects(linestring1.intersection(linestring2))” delivered true. 2.Fall: Linestring3: "LINESTRING(-27611.19260069567 25315.392403581718, -11080.415853237311 23468.8694690252)"; Linestring4: "LINESTRING(-21456.11615217394 29272.22726334569, -18818.226245664628 18368.948983107195)"; With the intersection „Linestring3.intersection(linestring4)“ the point „POINT (-20301.268838372802 24498.858366300974) „ came out. However the question „Linestring3.intersects(linestring3.intersection(linestring4))” returns false. In fact it should return true? Does one of you know an explanation of this? Maybe someone does know who about JTS I can contact or who knows a lot about it? Or should I announce this as a bug? With kind regards, Anke Trittenbach -- Neu: GMX FreeDSL Komplettanschluss mit DSL 6.000 Flatrate + Telefonanschluss für nur 17,95 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02 _______________________________________________ jts-devel mailing list [hidden email] http://lists.refractions.net/mailman/listinfo/jts-devel |
Anke,
As others have pointed out, the reason you are seeing the apparent inconsistency in your example 2 is due to the finite precision of the floating point representation used by JTS. JTS uses Java doubles, which follow the IEEE 754 standard and provide about 16 decimal digits of precision. When JTS computes an intersection point, this is the maximum precision it can compute. (In fact, for some kinds of inputs the actual accuracy of the computed intersection point will be even less than that, due to the cascading of round-off error in the internal computations). So the point POINT (-20301.268838372802 24498.858366300974) is only a 16-digit approximation to the true intersection point. However, for spatial *predicates* (such as intersects) JTS can compute the test *exactly* (by virtue of a clever algorithms for computing exact signs of determinants of FP numbers). So this test can detect that the computed point does not lie precisely on either of the input line segments - and hence intersects returns false. One thing to be aware of is that the spatial predicates do not incorporate the geometry precision model in any way - they always compute the *exact* relationship between the precise data specified by the floating point numbers in the vertices of the input geometry. (This was a design decision made in JTS - it's not the only possible way to do it, but at the moment there is no other strategy available). The precision model is used only for determining the precision of geometry results computed by JTS operations (such as intersection). Hope that helps to clear this up. This is a common point of confusion - so I'm going to add your case to the JTS FAQ! Anke Trittenbach wrote: > Hello all together, > > I have tried to understand as JTS handles with the inaccuracy from doubles. As already mentioned there still appear mistakes with my calculations, because some values differ around 0.000000000004, although they are same. To solve this problem I have carried out some tests with JTS and tried to comprehend. On this occasion, I found the following difference between two equal geometrical cases: > > 1. Fall: > > Linestring1: "LINESTRING(4 1, 4 7)"; > > Linestring2: "LINESTRING(1 4, 7 4)"; > > With the intersection „linestring1.intersection(linestring2)“ the point „POINT (4 4)“ came out as expected. > > The question „linestring1.intersects(linestring1.intersection(linestring2))” delivered true. > > 2.Fall: > > Linestring3: "LINESTRING(-27611.19260069567 25315.392403581718, -11080.415853237311 23468.8694690252)"; > > Linestring4: "LINESTRING(-21456.11615217394 29272.22726334569, -18818.226245664628 18368.948983107195)"; > > With the intersection „Linestring3.intersection(linestring4)“ the point „POINT (-20301.268838372802 24498.858366300974) „ came out. > > However the question „Linestring3.intersects(linestring3.intersection(linestring4))” returns false. > In fact it should return true? Does one of you know an explanation of this? Maybe someone does know who about JTS I can contact or who knows a lot about it? Or should I announce this as a bug? > > With kind regards, > > Anke Trittenbach > > -- Martin Davis Senior Technical Architect Refractions Research, Inc. (250) 383-3022 _______________________________________________ jts-devel mailing list [hidden email] http://lists.refractions.net/mailman/listinfo/jts-devel |
Free forum by Nabble | Edit this page |