提取 CGALTriangulation 的法线

Extracting normals of a CGALTriangulation

在 3D CGAL 三角剖分中,我试图通过这种方式获得法线

    Vector n = CGAL::normal(p1, p2, p3);

上下文中的代码:

for (CGALTriangulation::Finite_facets_iterator it = T.finite_facets_begin();
             it != T.finite_facets_end();
             it++)
        {
            std::pair<CGALTriangulation::Cell_handle, int> f = *it;
            
            const Pointt& p0 = f.first->vertex((f.second))->point();
            
            const Pointt& p1 = f.first->vertex((f.second+1)&3)->point();
            const Pointt& p2 = f.first->vertex((f.second+2)&3)->point();
            const Pointt& p3 = f.first->vertex((f.second+3)&3)->point();

编辑

for (auto f : T.finite_facets())
{

    //all convex hull facets pointing outside
    if (T.is_infinite(T.mirror_facet(f).first)){
        f = T.mirror_facet(f);
    }

    const auto cell = f.first;
    const int i = f.second;
        
    const Point& p1 = cell->vertex( T.vertex_triple_index(i, 0) )->point();
    const Point& p2 = cell->vertex( T.vertex_triple_index(i, 1) )->point();
    const Point& p3 = cell->vertex( T.vertex_triple_index(i, 2) )->point();

    Vector n = CGAL::normal(p1, p2, p3);
}

无法通过这种方式找到小平面的方向。要设置 p1p2p3,请使用该段代码:

const auto cell = f.first;
const int i = f.second;

const Pointt& p1 = cell->vertex(T.vertex_triple_index(i, 0)->point();
const Pointt& p2 = cell->vertex(T.vertex_triple_index(i, 1)->point();
const Pointt& p3 = cell->vertex(T.vertex_triple_index(i, 2)->point();

参见documentation of vertex_triple_index