There is great library for geometry in Boost. It allows also to draw SVG images. I want to use it in some project of mine but it works really strange for me (see image below).>
I think there are several problems with the code:
1 1
1 0
That is:
three two one -
So the expected result is different from pic2.
You are missing the closing point and the third polygon is not directed clockwise. Take a look at the correct method. On this example, you should call it for every polygon you define.
You should use a temporary variable:
boost::geometry::union_(one, two, outputTmp);
boost::geometry::union_( outputTmp, three, output);
After executing the corrected code, the result is:
This may be a valid simplifcation of your polygon. See the Ramer–Douglas–Peucker algorithm.
After performing those modifications, below is the resulting main()
int main()
{
// create points (each point == square poligon)
boost::geometry::model::polygon > one, two, three;
boost::geometry::read_wkt( "POLYGON((1 1, 1 0, 0 0, 0 1))", one);
boost::geometry::read_wkt( "POLYGON((2 2, 2 1, 1 1, 1 2))", two);
boost::geometry::read_wkt( "POLYGON((1 1, 1 2, 0 2, 0 1))", three);
boost::geometry::correct(one);
boost::geometry::correct(two);
boost::geometry::correct(three);
// create a container for joined points structure
boost::geometry::model::multi_polygon< boost::geometry::model::polygon > > outputTmp, output, simpl;
// join points one by one (because one day we would have many=))
boost::geometry::union_(one, two, outputTmp);
boost::geometry::union_( outputTmp, three, output);
// simplify joined structure
boost::geometry::simplify(output, simpl, 0.5);
// create an svg image
create_svg("make_envelope.svg", simpl, output );
}