4
votes

This code snippet works fine in 2D version, but doesn't compile in 3D version:

namespace bg = boost::geometry;

typedef bg::model::point<double, 3, bg::cs::cartesian> Point3D;
typedef bg::model::polygon<Point3D>                    Poly3D;

Poly3D         p0, p1;
vector<Poly3D> result;

bg::read_wkt("POLYGON((0 0 0, 0 1 1, 1 0 0, 0 0 0))", p0);
bg::read_wkt("POLYGON((0 0 0.5, 0 11 0.5, 11 0 0.5, 0 0 0.5))", p1);

bg::intersection(p0, p1, result);

with this template error:

1>C:\boost_1_54_0\boost/geometry/core/coordinate_dimension.hpp(89): error C2338: ( boost::mpl::equal_to < geometry::dimension<Geometry>, boost::mpl::int_<Dimensions> >::type::value )
...

Can anyone tell me what is wrong with intersection call? My application is to find intersection of planar polygons. I can see that in general case Poly3D doesn't have to be planar, so it can be the source of this error. Is there a way to define a planar 3D polygon type?

1

1 Answers

3
votes

Erm. The compiler is telling you that the algorithm invoked is invalid for 3 dimensions... The programmers made this explicitely clear (area.hpp):

    BOOST_CONCEPT_ASSERT( (geometry::concept::AreaStrategy<Strategy>) );
    assert_dimension<Ring, 2>();

So. Yeah. Can't use intersection to cross two planar polygons. I'm pretty sure with a bit of maths you can do two projections which would lead to two intersections that together give you the information you're after.