PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/geometry/doc/src/examples/algorithms/area.cpp

http://hadesmem.googlecode.com/
C++ | 50 lines | 18 code | 12 blank | 20 comment | 0 complexity | abf77a01de72df3ad91c8ce9a7776571 MD5 | raw file
 1// Boost.Geometry (aka GGL, Generic Geometry Library)
 2// QuickBook Example
 3
 4// Copyright (c) 2011 Barend Gehrels, Amsterdam, the Netherlands.
 5
 6// Use, modification and distribution is subject to the Boost Software License,
 7// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
 8// http://www.boost.org/LICENSE_1_0.txt)
 9
10//[area
11//` Calculate the area of a polygon
12
13#include <iostream>
14
15#include <boost/geometry.hpp>
16#include <boost/geometry/geometries/point_xy.hpp>
17#include <boost/geometry/geometries/polygon.hpp>
18#include <boost/geometry/domains/gis/io/wkt/wkt.hpp>
19
20namespace bg = boost::geometry; /*< Convenient namespace alias >*/
21
22int main()
23{
24    // Calculate the area of a cartesian polygon
25    bg::model::polygon<bg::model::d2::point_xy<double> > poly;
26    bg::read_wkt("POLYGON((0 0,0 7,4 2,2 0,0 0))", poly);
27    double area = bg::area(poly);
28    std::cout << "Area: " << area << std::endl;
29
30    // Calculate the area of a spherical equatorial polygon
31    bg::model::polygon<bg::model::point<float, 2, bg::cs::spherical_equatorial<bg::degree> > > sph_poly;
32    bg::read_wkt("POLYGON((0 0,0 45,45 0,0 0))", sph_poly);
33    area = bg::area(sph_poly);
34    std::cout << "Area: " << area << std::endl;
35
36    return 0;
37}
38
39//]
40
41
42//[area_output
43/*`
44Output:
45[pre
46Area: 16
47Area: 0.339837
48]
49*/
50//]