首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用#CGAL实现二维网格的三角形角度

使用#CGAL实现二维网格的三角形角度
EN

Stack Overflow用户
提问于 2017-02-11 04:55:53
回答 1查看 127关注 0票数 0

这个问题已经有了答案,但对于2D网格:Angles of triangles of a 3D mesh using #CGAL

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

如果有什么不同的话,那就是这个网格是由CDT生成的。

EN

回答 1

Stack Overflow用户

发布于 2017-02-11 06:01:57

这很简单,但我认为这可能会对某些人有所帮助,因为Laurent Rineauin在最初的3D网格问题中的评论提出了解决方案是不同的。所以就是这样:

代码语言:javascript
复制
// 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;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42168529

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档