项目作者: tomilov

项目描述 :
Header-only single-class implementation of Quickhull algorithm for convex hulls finding in arbitrary dimension (>1) space.
高级语言: C++
项目地址: git://github.com/tomilov/quickhull.git
创建时间: 2014-11-14T12:05:25Z
项目社区:https://github.com/tomilov/quickhull

开源协议:

下载


NOTE: This library is header-only.

Implementation of the Quickhull algorithm (Barber et al) for the convex hulls finding in arbitrary dimension (>1) space. Also implemented the Mehlhorn algorithm (Mehlhorn et al) for checking convexity of resulting geometric structure.

Example:

  1. #include <quickhull.hpp>
  2. #include <array>
  3. #include <iterator>
  4. #include <limits>
  5. #include <random>
  6. #include <vector>
  7. #include <cstdlib>
  8. int main()
  9. {
  10. using F = float;
  11. constexpr std::size_t dim = 3;
  12. using Points = std::vector<std::array<F, dim>>;
  13. Points points(10); // input
  14. { // fill it somehow (use real data)
  15. std::mt19937 gen;
  16. for (auto & [x, y, z] : points) {
  17. x = std::generate_canonical<F, std::numeric_limits<F>::digits>(gen);
  18. y = std::generate_canonical<F, std::numeric_limits<F>::digits>(gen);
  19. z = std::generate_canonical<F, std::numeric_limits<F>::digits>(gen);
  20. }
  21. }
  22. const auto eps = std::numeric_limits<F>::epsilon();
  23. quick_hull<typename Points::const_iterator> qh{dim, eps};
  24. qh.add_points(std::cbegin(points), std::cend(points));
  25. auto initial_simplex = qh.get_affine_basis();
  26. if (initial_simplex.size() < dim + 1) {
  27. return EXIT_FAILURE; // degenerated input set
  28. }
  29. qh.create_initial_simplex(std::cbegin(initial_simplex), std::prev(std::cend(initial_simplex)));
  30. qh.create_convex_hull();
  31. if (!qh.check()) {
  32. return EXIT_FAILURE; // resulted structure is not convex (generally due to precision errors)
  33. }
  34. qh.facets_; // use as result
  35. }