Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost Intersection not working

i have a big problem with boost intersection. i would like to intersect a triangle with a quad, but i get a clip:

i46.tinypic.com/2nvuo01.png

Can somebody help me?

I tried to changed the orientation of the geometry, nothing happened. the intersection work with other triangles, but not with this.

typedef model::polygon<model::d2::point_xy<double> > polygon
std::deque<polygon> tmp;
bool ok = intersection(quad, triangle, tmp)

The triangle:

-213.57   -2.13163e-14   0 
-350      37.5           0 
-350      -2.84217e-14   0

The box:

BoundingBox(-300, -165, 2, 170, -0.1, 0.1)

UPDATE:

Here my code. I use gcc 4.7.2 with boost 1.53.0 on Ubuntu 12.10

#include <deque>
#include <fstream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/io/wkt/wkt.hpp>
#include <boost/geometry/extensions/io/svg/svg_mapper.hpp>

using namespace boost::geometry;

int main()
{
    typedef model::polygon<model::d2::point_xy<double> > polygon;
    typedef typename model::d2::point_xy<double> point_type;

    polygon quad, triangle;

    read_wkt("POLYGON((-213.57 -2.131 , -350.0 37.5 , -350.0 -2.842 , -213.57 -2.131))", triangle);
    read_wkt("POLYGON((-300.0 2 , -300 170 , -165 170 , -165 2 , -300 2))", quad);

    std::deque<polygon> output;
    intersection(quad, triangle, output);

    std::string filename = "intersectiontest.svg";
    std::ofstream svg(filename.c_str());
    svg_mapper<point_type> mapper(svg, 600, 600);

    mapper.add(output[0]);
    mapper.map(output[0], "fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(255,0,0);stroke-width:5");

}
like image 644
shinpei Avatar asked Mar 08 '13 23:03

shinpei


1 Answers

My best guess is that this has to do with specifying the points in counterclockwise order when by default polygon expects the points to be in clockwise order. So you would need to change it as follows:

read_wkt("POLYGON((-213.57 -2.131 , -350.0 -2.842 , -350.0 37.5 , -213.57 -2.131))", triangle);

You can read more about this issue here

like image 81
Shafik Yaghmour Avatar answered Sep 19 '22 05:09

Shafik Yaghmour