I'm coding a function giving the diameter of a previously defined polygon using the boost::geometry library.
This diameter is defined as the maximal distance between two of its points. Thus, I'm coding a double loop computing every distance of every pair of points but I don't know how to have access to the point coordinates inside the polygon, or even the point objects and then using the distance function between two points brought by the library (by the way, which one should be faster?).
After looking at Boost docs on polygon I tried my_polygon.PointList without success...
My solution at the end was to use a modified version of Barend's proposal:
for(auto it1 = boost::begin(boost::geometry::exterior_ring(poly));
it1 != boost::end(boost::geometry::exterior_ring(poly));
++it1)
{
for(auto it2 = it1+1;
it2 != boost::end(boost::geometry::exterior_ring(poly));
++it2)
{
double distance = boost::geometry::distance(*it1, *it2);
if(my_diameter < distance){my_diameter = distance;}
}
}
I just suppressed the redundancy of calculating twice the same distance;