 # Geometry :

Subject: [ggl] Re: Help needed with Intersection operation
From: Christoph Keller (christoph)
Date: 2011-08-19 18:57:02

Hello Angus,

thanks for providing the code. However if I do that using double
precision, i get a triangle as output, that has little to do with the
intersection.

I made a mistake posting my Data. One element had a different value. I
also used correct, as you suggested, but as I expected this changes nothing.

I posted my complete code below. Note that the y-value
29.884635544079821 cannot belong to the first polygon.

So it seems we found two errors. The question for me is if I should
develop my own intersection code? I just have to calculate the
difference/intersection of a lot of triangles in 2D. The library needs
to handle these cases, they ALWAYS occur in practice.

Greetings,
Christoph

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/polygon.hpp>

BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
typedef boost::tuple<double, double> point;
typedef boost::geometry::model::polygon<point> polygon;

void boostGiveMeError() {
std::vector<polygon> outDiff, outIntersect, outInnerDiff;
polygon vecPoly, lpPoly;

lpPoly.outer().push_back(boost::make_tuple(0.24806946917841693,
26.015444246572663));
lpPoly.outer().push_back(boost::make_tuple(31.751930530821582 ,
33.984555753427337));
lpPoly.outer().push_back(boost::make_tuple(32.248069469178418
,30.015444246572663));
lpPoly.outer().push_back(boost::make_tuple(0.24806946917841693,
26.015444246572663));

vecPoly.outer().push_back(boost::make_tuple(17.763942722600319,
32.236057277399681));
vecPoly.outer().push_back(boost::make_tuple(19.192448808558737,
30.807551191441263));
vecPoly.outer().push_back(boost::make_tuple(16.000000000000000,
30.000000000000000));
vecPoly.outer().push_back(boost::make_tuple(17.763942722600319,
32.236057277399681));
boost::geometry::correct(vecPoly);
boost::geometry::correct(lpPoly);

boost::geometry::difference(vecPoly, lpPoly, outDiff);
for(unsigned i=0; i < outDiff.size(); i++)
boost::geometry::unique(outDiff[i]);

double debugMe;
for(int i=0; i < 5; i++) {
debugMe[i] = outDiff.outer()[i].get<0>();
debugMe[i] = outDiff.outer()[i].get<1>();
}
}

THE DEBUGGER OUTPUT:

- debugMe 0x0052eddc double 
-  0x0052eddc double 
 15.543935884491610 double
 29.884635544079821 double
-  0x0052edec double 
 16.000000000000000 double
 30.000000000000000 double
-  0x0052edfc double 
 17.763942722600319 double
 32.236057277399681 double
-  0x0052ee0c double 
 19.192448808558737 double
 30.807551191441263 double
-  0x0052ee1c double 
 15.543935884491610 double
 29.884635544079821 double

On 08/19/2011 11:37 PM, angusj wrote:
> wont be helpful as evidently you did 'close' the polygons (and the
> link I gave was to the wrong thread too). Anyhow, I have compiled and
> tested your polygons and can confirm that there appears to be a small
> problem with the solution to an intersection operation (which returns
> a single point well beyond any potential intersection).
> #include<boost/geometry.hpp>
> #include<boost/geometry/geometries/point_xy.hpp>
> #include<boost/geometry/geometries/polygon.hpp>
> #include<boost/geometry/multi/geometries/multi_polygon.hpp>
> #include<boost/geometry/domains/gis/io/wkt/wkt.hpp>
>
> typedef boost::geometry::model::polygon ggl_polygon;
> typedef boost::geometry::model::multi_polygon ggl_polygons;
>
> ggl_polygon blue, green;
> "POLYGON((0.24806946917841693 26.015444246572663, 31.751930530821582 33.984555753427337, "
> "32.248069469178418 30.015444246572663, 0.24806946917841693 26.015444246572663))", green);
> "POLYGON((17.763942722600319 32.236057277399681, 19.192448808558737 30.807551191441263, "
> "16.000000000000000 30.000000000000000, 17.763942722600319 32.236057277399681))", blue);
> ggl_polygons output;
> bg::intersection(green, blue, output);
> cout<< output;
>
> ------------------------------------------------------------------------
> View this message in context: Re: Help needed with Intersection
> operation

> Sent from the Boost Geometry mailing list archive
> <http://boost-geometry.203548.n3.nabble.com/> at Nabble.com.
>
>
> _______________________________________________
> ggl mailing list
> ggl_at_[hidden]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/ggl/attachments/20110820/90580a0a/attachment.html

Geometry list run by mateusz at loskot.net