Boost logo

Geometry :

Subject: [ggl] Iterating over polygon vertices.
From: Barend Gehrels (barend.gehrels)
Date: 2010-04-13 08:40:51


Hi Jack,

> I have a polygon of type 'polygon_2d' and I want to be able to loop
> over the vertices of the Polygon. I can't for the life of me figure
> out how to get at the vertices making up the polygon.
>

Welcome to the list!

You can either use boost::geometry::for_each using a strategy, but the
most convenient way is probably to use exterior_ring to get the exterior
ring, and (if wished) interior ring to access the interior rings.

So for example:
ring_2d const& ring = exterior_ring(poly);
std::copy(ring.begin(), ring.end(), ....)

And for interior rings (holes):
BOOST_FOREACH(ring_2d const& ring, interior_rings(poly))
{
  // do things with this ring
}

Regards, Barend

>


Geometry list run by mateusz at loskot.net