| Home | Libraries | People | FAQ | More

#### convex_hull

Calculates the convex hull of a geometry.

###### Description

The free function convex_hull calculates the convex hull of a geometry.

###### Synopsis

    template<typename Geometry1, typename Geometry2>
    void convex_hull(Geometry1 const & geometry, Geometry2 & hull)

###### Parameters

Type | Concept | Name | Description
--- | --- | --- | ---
Geometry1 const & | Any type fulfilling a Geometry Concept | geometry | A model of the specified concept, input geometry
Geometry2 & | Any type fulfilling a Geometry Concept | hull | A model of the specified concept which is set to the convex hull

###### Header

Either

`#include <boost/geometry/geometry.hpp>`

Or

`#include <boost/geometry/algorithms/convex_hull.hpp>`

###### Complexity

Linear

###### Example

Shows how to generate the convex_hull of a geometry

    #include <iostream>

    #include <boost/geometry.hpp>
    #include <boost/geometry/geometries/polygon.hpp>
    #include <boost/geometry/geometries/adapted/boost_tuple.hpp>

    BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)

    int main()
    {
        typedef boost::tuple<double, double> point;
        typedef boost::geometry::model::polygon<point> polygon;

        polygon poly;
        boost::geometry::read_wkt("polygon((2.0 1.3, 2.4 1.7, 2.8 1.8, 3.4 1.2, 3.7 1.6,3.4 2.0, 4.1 3.0"
            ", 5.3 2.6, 5.4 1.2, 4.9 0.8, 2.9 0.7,2.0 1.3))", poly);

        polygon hull;
        boost::geometry::convex_hull(poly, hull);

        using boost::geometry::dsv;
        std::cout
            << "polygon: " << dsv(poly) << std::endl
            << "hull: " << dsv(hull) << std::endl
            ;

        return 0;
    }

Output:

    polygon: (((2, 1.3), (2.4, 1.7), (2.8, 1.8), (3.4, 1.2), (3.7, 1.6), (3.4, 2), (4.1, 3), (5.3, 2.6), (5.4, 1.2), (4.9, 0.8), (2.9, 0.7), (2, 1.3)))
    hull: (((2, 1.3), (2.4, 1.7), (4.1, 3), (5.3, 2.6), (5.4, 1.2), (4.9, 0.8), (2.9, 0.7), (2, 1.3)))