Reputation: 361
In a 3D CGALTriangulation I'm trying to get the normals by this way
Vector n = CGAL::normal(p1, p2, p3);
Code in context:
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();
EDIT
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);
}
Upvotes: 0
Views: 117
Reputation: 6274
The orientation of a facet cannot be found that way. To set p1
, p2
, and p3
, use that piece of code:
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();
See the documentation of vertex_triple_index
.
Upvotes: 3