does it matter in boost geometry c++ library the order of points I add?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 11:13:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!