问题
I'm a total newbie with boost and even more with boost-geometry, so my question is... Does it matter to boost-geometry the order in which I add points to a polygon?
Eg: Is this the same?
// create a polygon
polygon p;
p.outer().push_back(point(0, 0));
p.outer().push_back(point(0, 10));
p.outer().push_back(point(10, 0));
p.outer().push_back(point(10, 10));
// create a polygon the same polygon?
polygon p;
p.outer().push_back(point(0, 0));
p.outer().push_back(point(0, 10));
p.outer().push_back(point(10, 10));
p.outer().push_back(point(10, 0));
Thank you very much in advance.
回答1:
As stated here:
The point order is defined for any geometry type, but only has a real meaning for areal geometry types (ring, polygon, multi_polygon)
As for the polygon concept, there are some rules written here:
- If the polygons underlying ring_type is defined as clockwise, the exterior ring must have the clockwise orientation, and any interior ring must be reversed w.r.t. the defined orientation (so: counter clockwise for clockwise exterior rings).
- If the ring_type is defined counter clockwise, it is vice versa.
- If the polygons underlying ring_type is defined as closed, all rings must be closed: the first point must be spatially equal to the last point.
Point order is important when you use algorithms such as intersection, area, centroid, union.
To correct your geometries before using those functions, use boost::geometry::correct
(reference)
来源:https://stackoverflow.com/questions/24283344/does-it-matter-in-boost-geometry-c-library-the-order-of-points-i-add