...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Area calculation by spherical excess / Huiller's formula.
template<typename PointOfSegment, typename CalculationType> class strategy::area::huiller { // ... };
Parameter |
Default |
Description |
---|---|---|
typename PointOfSegment |
point type of segments of rings/polygons |
|
typename CalculationType |
void |
numeric type for calculation (e.g. high precision); if void then it is extracted automatically from the coordinate type and (if necessary) promoted to floating point |
Function |
Description |
Parameters |
---|---|---|
huiller(calculation_type radius = 1.0)
|
calculation_type: radius: |
Function |
Description |
Parameters |
Returns |
---|---|---|---|
void apply(PointOfSegment const & p1, PointOfSegment const & p2, excess_sum & state)
|
PointOfSegment const &: p1: PointOfSegment const &: p2: excess_sum &: state: |
||
return_type result(excess_sum const & state)
|
excess_sum const &: state: |
#include <boost/geometry/strategies/spherical/area_huiller.hpp>
Calculate the area of a polygon
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/point_xy.hpp> #include <boost/geometry/geometries/polygon.hpp> namespace bg = boost::geometry;int main() { // Calculate the area of a cartesian polygon bg::model::polygon<bg::model::d2::point_xy<double> > poly; bg::read_wkt("POLYGON((0 0,0 7,4 2,2 0,0 0))", poly); double area = bg::area(poly); std::cout << "Area: " << area << std::endl; // Calculate the area of a spherical polygon (for latitude: 0 at equator) bg::model::polygon<bg::model::point<float, 2, bg::cs::spherical_equatorial<bg::degree> > > sph_poly; bg::read_wkt("POLYGON((0 0,0 45,45 0,0 0))", sph_poly); area = bg::area(sph_poly); std::cout << "Area: " << area << std::endl; return 0; }
Output:
Area: 16 Area: 0.339837