【问题标题】:CGAL: How to efficiently calculate the area of facets of a polyhedron?CGAL:如何有效地计算多面体的面面积?
【发布时间】:2013-05-23 23:45:57
【问题描述】:

我有一个多面体,它的面是三角形。我知道在 CGAL 中,Triangle_3 类提供了“squared_area”方法,通过它我们可以计算三角形的面积。有什么方法可以将其应用于多面体面?或者关于如何计算每个面的面积的任何想法?

【问题讨论】:

  • 不熟悉cgal,但是三角形的一个优点是可以确定它们是平面的,因此它们具有相当明显且定义明确的区域。只要您有超过 3 个角,平面性就会成为问题。如果您确定它们是平面的,则可以使用 link 之类的东西来查找该区域
  • 我刚刚重读了这篇文章——你的意思是“多面体”还是“多边形面”?
  • 多面体..无论如何我得到了正确的答案..感谢您尝试帮助我..:)

标签: c++ computational-geometry area cgal


【解决方案1】:

这是一个例子:

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polyhedron_3.h>
#include <numeric>
#include <functional>
#include <boost/iterator/transform_iterator.hpp>

typedef CGAL::Simple_cartesian<double> K;
typedef CGAL::Polyhedron_3<K> Polyhedron;

struct Compute_area:
  public std::unary_function<const Polyhedron::Facet, double>
{
  double operator()(const Polyhedron::Facet& f) const{
    return K::Compute_area_3()(
      f.halfedge()->vertex()->point(),
      f.halfedge()->next()->vertex()->point(),
      f.halfedge()->opposite()->vertex()->point() );
  }
};

int main()
{
  Polyhedron p;
  p.make_tetrahedron(
    K::Point_3(0,0,0),
    K::Point_3(0,1,0),
    K::Point_3(1,1,0),
    K::Point_3(1,1,3)
  );

CGAL_assertion( p.is_pure_triangle() );

  Compute_area ca;

  std::cout <<
    std::accumulate(
      boost::make_transform_iterator(p.facets_begin(), ca),
      boost::make_transform_iterator(p.facets_end(), ca),
      0.)
  << std::endl;
}

编辑 CGAL 的最新版本中提供了免费功能CGAL::Polygon_mesh_processing::area()

【讨论】:

    【解决方案2】:

    扩展@sloriot 答案,因为std::unary_function 在 C++11 中已弃用,将从 C++14 开始删除。但是,unary_function 不再需要,Compute_area 可以简单地实现为

    struct Compute_area
    {
       double operator()(const Polyhedron::Facet& f) const {
       return K::Compute_area_3()(
         f.halfedge()->vertex()->point(),
         f.halfedge()->next()->vertex()->point(),
         f.halfedge()->opposite()->vertex()->point() );
        }
    };                                                                              
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-12
      • 1970-01-01
      • 1970-01-01
      • 2011-06-08
      • 2021-09-05
      • 2010-12-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多