这个问题已经有了答案,但对于2D网格:Angles of triangles of a 3D mesh using #CGAL
我知道关于2D的答案是不同的。那么:如何在CGAL中计算二维网格的三角形的角度?我可以通过配对来获取顶点和它们各自的Vector,但我正在寻找一种直接计算角度的方法,而不需要检查它是外角还是内角。
如果有什么不同的话,那就是这个网格是由CDT生成的。
发布于 2017-02-11 06:01:57
这很简单,但我认为这可能会对某些人有所帮助,因为Laurent Rineauin在最初的3D网格问题中的评论提出了解决方案是不同的。所以就是这样:
// faces_iterator iterates through the triangles of l_cdt CDT triangulation
CGAL::Point_2<K> vertex1 = l_cdt.triangle(faces_iterator)[0];
CGAL::Point_2<K> vertex2 = l_cdt.triangle(faces_iterator)[1];
CGAL::Point_2<K> vertex3 = l_cdt.triangle(faces_iterator)[2];
double a = CGAL::sqrt((vertex2.x() - vertex3.x()) * (vertex2.x() - vertex3.x()) + (vertex2.y() - vertex3.y()) * (vertex2.y() - vertex3.y()));
double b = CGAL::sqrt((vertex1.x() - vertex3.x()) * (vertex1.x() - vertex3.x()) + (vertex1.y() - vertex3.y()) * (vertex1.y() - vertex3.y()));
double c = CGAL::sqrt((vertex2.x() - vertex1.x()) * (vertex2.x() - vertex1.x()) + (vertex2.y() - vertex1.y()) * (vertex2.y() - vertex1.y()));
// constants::PI is just π, for conversion to degrees instead of radians
double angle1 = ((std::acos((b*b + c*c - a*a) / (2*b*c))) * 180) / constants::PI;
double angle2 = ((std::acos((a*a + c*c - b*b) / (2*a*c))) * 180) / constants::PI;
double angle3 = ((std::acos((a*a + b*b - c*c) / (2*b*a))) * 180) / constants::PI;https://stackoverflow.com/questions/42168529
复制相似问题