Search code examples
meshcgal

Angles of triangles of a 3D mesh using #CGAL


I would like to know if it is possible to compute the angles of triangles of a 3D mesh (represented with a graph) using a function of CGAL ?

Thanks


Solution

  • If you have a non-degenerated triangle with three points a, b, and c, the angle of triangle, the cosine of the angle at a is the scalar product of two vectors divided by their lengths:

    CGAL::Vector_3<K> v1 = b - a;
    CGAL::Vector_3<K> v2 = c - a;
    double cosine = v1 * v2 / CGAL::sqrt(v1*v1) / CGAL::sqrt(v2 * v2);
    

    where K is the type of kernel that you are using for the points. The angle itself in radius can be computed by:

    double angle = std::acos(cosine);
    

    Of course, for degenerate triangles, the lengths can be zero, and the expression above will compute 0./0. (that is a not-a-number). You have to deal with that case separately.