]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/doc/src/examples/algorithms/area.cpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / geometry / doc / src / examples / algorithms / area.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // QuickBook Example
3
4 // Copyright (c) 2011-2012 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
19 namespace bg = boost::geometry; /*< Convenient namespace alias >*/
20
21 int main()
22 {
23 // Calculate the area of a cartesian polygon
24 bg::model::polygon<bg::model::d2::point_xy<double> > poly;
25 bg::read_wkt("POLYGON((0 0,0 7,4 2,2 0,0 0))", poly);
26 double area = bg::area(poly);
27 std::cout << "Area: " << area << std::endl;
28
29 // Calculate the area of a spherical equatorial polygon
30 bg::model::polygon<bg::model::point<float, 2, bg::cs::spherical_equatorial<bg::degree> > > sph_poly;
31 bg::read_wkt("POLYGON((0 0,0 45,45 0,0 0))", sph_poly);
32 area = bg::area(sph_poly);
33 std::cout << "Area: " << area << std::endl;
34
35 return 0;
36 }
37
38 //]
39
40
41 //[area_output
42 /*`
43 Output:
44 [pre
45 Area: 16
46 Area: 0.339837
47 ]
48 */
49 //]