2017-02-10 83 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