From 540f09650c410cb6991f9a35ec7157a9805b935a Mon Sep 17 00:00:00 2001 From: "Dennis.Glaeser" <dennis.glaeser@iws.uni-stuttgart.de> Date: Thu, 30 May 2019 22:04:24 +0200 Subject: [PATCH] [grahamconvexhull] add impl for 2d hulls This actually makes use of the 2d in 3d algorithm at the moment. In the future a more efficient implementation for 2d hulls could be implemented. --- dumux/common/geometry/grahamconvexhull.hh | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/dumux/common/geometry/grahamconvexhull.hh b/dumux/common/geometry/grahamconvexhull.hh index 463b61f907..9fff6845c7 100644 --- a/dumux/common/geometry/grahamconvexhull.hh +++ b/dumux/common/geometry/grahamconvexhull.hh @@ -175,6 +175,31 @@ grahamConvexHull2d3d(std::vector<Dune::FieldVector<ctype, 3>>& points) return convexHull; } +/*! + * \ingroup Geometry + * \brief Compute the points making up the convex hull around the given set of unordered points + * \note This is the specialization for 2d space. Here, we make use of the generic implementation + * for the case of coplanar points in 3d space (a more efficient implementation could be provided). + */ +template<class ctype> +std::vector<Dune::FieldVector<ctype, 2>> +grahamConvexHull(const std::vector<Dune::FieldVector<ctype, 2>>& points) +{ + std::vector<Dune::FieldVector<ctype, 3>> tmp; + tmp.reserve(points.size()); + for (const auto& p : points) + tmp.emplace_back( Dune::FieldVector<ctype, 3>({p[0], p[1], 0.0}) ); + + auto result3d = grahamConvexHull2d3d(tmp); + + std::vector<Dune::FieldVector<ctype, 2>> result; + result.reserve(result3d.size()); + for (const auto& p : result3d) + result.emplace_back( Dune::FieldVector<ctype, 2>({p[0], p[1]}) ); + + return result; +} + /*! * \ingroup Geometry * \brief Triangulate area given points of the convex hull -- GitLab