Angles of triangles of a 3D mesh using #CGAL

耗尽温柔 提交于 2019-12-07 13:14:26

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!