convex_hull - 3D possible?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

convex_hull - 3D possible?

Oliver Weinheimer
I am trying to use boost::geometry::convex_hull in 3D.
The convex hull of a cuboid should be the cuboid itself.
But i get just 5 instead of 8 points for the convex hull in my example code.
What is wrong with the code?

Code:

        typedef boost::geometry::model::point<double, 3, boost::geometry::cs::cartesian> point3D;
        typedef boost::geometry::model::multi_point<point3d> points3d;

        points3d all_points;
        boost::geometry::append(all_points,point3d(0,0,0));
        boost::geometry::append(all_points,point3d(1,0,0));
        boost::geometry::append(all_points,point3d(1,1,0));
        boost::geometry::append(all_points,point3d(0,1,0));
        boost::geometry::append(all_points,point3d(0,1,1));
        boost::geometry::append(all_points,point3d(1,1,1));
        boost::geometry::append(all_points,point3d(1,0,1));
        boost::geometry::append(all_points,point3d(0,0,1));

        points3d hull3d;
        boost::geometry::convex_hull(all_points, hull3d);

        using boost::geometry::dsv;
        std::cout
                << "all_points: " << dsv(all_points) << std::endl
                << "hull: " << dsv(hull3d) << std::endl;

        std::cout << "size of all points: " << all_points.size() << std::endl;
        std::cout << "size of hull3d: " << hull3d.size() << std::endl;

Output:

        all_points: ((0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0), (0, 1, 1), (1, 1, 1), (1, 0, 1), (0, 0, 1))
        hull: ((0, 0, 0), (0, 1, 1), (1, 1, 1), (1, 0, 1), (0, 0, 0))
Reply | Threaded
Open this post in threaded view
|

Re: convex_hull - 3D possible?

Menelaos Karavelas
Hi Oliver.

On 05/06/2014 12:18 μμ, Oliver Weinheimer wrote:
> I am trying to use boost::geometry::convex_hull in 3D.
> The convex hull of a cuboid should be the cuboid itself.
> But i get just 5 instead of 8 points for the convex hull in my example code.
> What is wrong with the code?

I think that convex hull is implemented only for 2D geometries.


> Code:
>
> typedef boost::geometry::model::point<double, 3,
> boost::geometry::cs::cartesian> point3D;
> typedef boost::geometry::model::multi_point<point3d> points3d;
>
> points3d all_points;
> boost::geometry::append(all_points,point3d(0,0,0));
> boost::geometry::append(all_points,point3d(1,0,0));
> boost::geometry::append(all_points,point3d(1,1,0));
> boost::geometry::append(all_points,point3d(0,1,0));
> boost::geometry::append(all_points,point3d(0,1,1));
> boost::geometry::append(all_points,point3d(1,1,1));
> boost::geometry::append(all_points,point3d(1,0,1));
> boost::geometry::append(all_points,point3d(0,0,1));
>
> points3d hull3d;
> boost::geometry::convex_hull(all_points, hull3d);
>
> using boost::geometry::dsv;
> std::cout
> << "all_points: " << dsv(all_points) << std::endl
> << "hull: " << dsv(hull3d) << std::endl;
>
> std::cout << "size of all points: " << all_points.size() << std::endl;
> std::cout << "size of hull3d: " << hull3d.size() << std::endl;
>
> Output:
>
> all_points: ((0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0), (0, 1, 1), (1, 1,
> 1), (1, 0, 1), (0, 0, 1))
> hull: ((0, 0, 0), (0, 1, 1), (1, 1, 1), (1, 0, 1), (0, 0, 0))

The 3rd coordinate is basically thrown away. What you get is the convex
hull of the projections of the points on the xy-plane, represented
though with your original 3D points.

- m.

>
>
> --
> View this message in context: http://boost-geometry.203548.n3.nabble.com/convex-hull-3D-possible-tp4026100.html
> Sent from the Boost Geometry mailing list archive at Nabble.com.
> _______________________________________________
> Geometry mailing list
> [hidden email]
> http://lists.boost.org/mailman/listinfo.cgi/geometry

_______________________________________________
Geometry mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/geometry
Reply | Threaded
Open this post in threaded view
|

Re: convex_hull - 3D possible?

Oliver Weinheimer
Hello Menelaos,

I was afraid about an answer like yours :-)
I think this restriction can not to be found in the documentation.
Nevertheless, thank you for your answer.

Oliver
Reply | Threaded
Open this post in threaded view
|

Re: convex_hull - 3D possible?

Bruno Lalande
Hi,

We should probably statically assert that the geometry is 2D, to prevent confusion. I will add this assertion.

Regards
Bruno


_______________________________________________
Geometry mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/geometry