Boost logo

Geometry :

Subject: Re: [geometry] union gives an empty multi-polygon
From: Barend Gehrels (barend_at_[hidden])
Date: 2012-12-27 11:48:41

Hi Romain,

Welcome to the list.

On 27-12-2012 15:11, Romain Texier wrote:
> Hi,
> I want to make real time union and clipping of many polygons.
> I have tried the clipper library and I would like to try the boost
> geometry library.
> But I have a problem: The union of two triangles is an empty
> multi-polygon.
> Could you help me ?
> typedef boost::geometry::model::d2::point_xy<float> BoostPoint;
> typedef boost::geometry::model::polygon<BoostPoint,false>
> BoostPolygon; //false because my triangles are counter-clockwise.
> typedef boost::geometry::model::multi_polygon< BoostPolygon >
> BoostPolygons;

I did not (yet) test the code, because I don't have the definitions of
your triangles, but I'm pretty sure that your polygons are not closed.
You defined them counterclockwise, but you should also define them as
"open" if you want them to use this way. So the definition should be
BoostPoint, false, false>.

See also this link:

> void BoostShape::createNewPoly(Triangle2D const & NewTriangle,
> BoostPolygons& p_InOutPolygon)
> {
> model::ring<BoostPoint,false> outerRingTriangle;
> outerRingTriangle.push_back(BoostPoint(NewTriangle.m_Vertex0.X,NewTriangle.m_Vertex0.Y));
> outerRingTriangle.push_back(BoostPoint(NewTriangle.m_Vertex1.X,NewTriangle.m_Vertex1.Y));
> outerRingTriangle.push_back(BoostPoint(NewTriangle.m_Vertex2.X,NewTriangle.m_Vertex2.Y));

What also helps is calling boost::geometry::correct (which would close
them in this code).

HTH, Barend

Geometry list run by mateusz at