2017-02-10 81 views
0

已经有一个这个问题,但对于一个二维网格答案: Angles of triangles of a 3D mesh using #CGAL角网使用#CGAL

据我所知,答案就2D是不同的。那么:如何计算CGAL中2D网格的三角形角度?我可以通过成对来获得顶点和它们各自的Vector,但是我正在寻找一种直接计算角度的方法,而不必检查它是外角还是内角。

如果它有什么区别,这个网格是由CDT生成的。

回答

0

这很简单,但我认为这可能有助于某人,因为Laurent Rineauin在最初的三维网格问题中提出的评论提出解决方案是不同的。所以这里是:

// 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; 
+1

我相信你可以使用'CGAL :: squared_distance'来计算a,b和c。 –

+0

是的,这是真的.. – foxTox