1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // QuickBook Example
3
4 // Copyright (c) 2020 Digvijay Janartha, Hamirpur, India.
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 //[perimeter
11 //` Calculate the perimeter 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
main()21 int main()
22 {
23 // Calculate the perimeter of a cartesian polygon
24 bg::model::polygon<bg::model::d2::point_xy<double> > poly;
25 bg::read_wkt("POLYGON((0 0,3 4,5 -5,-2 -4, 0 0))", poly);
26 double perimeter = bg::perimeter(poly);
27 std::cout << "Perimeter: " << perimeter << std::endl;
28
29 return 0;
30 }
31
32 //]
33
34
35 //[perimeter_output
36 /*`
37 Output:
38 [pre
39 Perimeter: 25.7627
40 ]
41 */
42 //]
43