CGAL:如何有效地计算多面体的面面积? [英] CGAL: How to efficiently calculate the area of facets of a polyhedron?

查看:23
本文介绍了CGAL:如何有效地计算多面体的面面积?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a polyhedron whose facets are triangles. I am aware that in CGAL, Triangle_3 class offers 'squared_area' method through which we can calculate the area of a triangle. Is there any way we can apply this to polyhedral facets? Or any ideas as to how to calculate area of each facet?

推荐答案

这是一个例子:

#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::Polygon_mesh_processing::area() 在 CGAL 的最新版本中可用.

EDIT There is the free function CGAL::Polygon_mesh_processing::area() that is available in recent releases of CGAL.

这篇关于CGAL:如何有效地计算多面体的面面积?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆