平移 CGAL 多边形,而无需循环穿过折点
Translate CGAL Polygon without looping through vertices
我刚开始使用CGAL,因此我提出了问题,因为我觉得你应该能够比循环顶点更容易地翻译CGAL::P olygon_2。
我目前的做法是这样的:
//Headers and typdef
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Boolean_set_operations_2.h>
#include <CGAL/aff_transformation_tags.h>
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::Point_2 Point_2;
typedef CGAL::Polygon_2<Kernel> Polygon_2;
typedef CGAL::Aff_transformation_2<Kernel> Transformation;
//Declare Polygon
Polygon_2 P;
P.push_back(Point_2(0, 0));
P.push_back(Point_2(5, 0));
P.push_back(Point_2(3.5, 1.5));
//Loop through vertices and translate
Transformation translate(CGAL::TRANSLATION, CGAL_Vector(0.2, 0));
typename CGAL::Polygon_2<Kernel>::Vertex_iterator vit;
//NOTE: This is the for loop that looks inefficient to me.
for (vit = P.vertices_begin(); vit != P.vertices_end(); ++vit) {
*vit = translate(*vit);
}
有人可以告诉我这是否是正确的方法,或者给我指示如何做得更好。
您可以调用transform
free 函数,该函数将完全按照您的要求执行。
因此,在代码中,执行以下操作:
Transformation translate(CGAL::TRANSLATION, CGAL_Vector(0.4, 0));
P = transform(translate, P);
相关文章:
- 如何循环打印顶点结构
- 如何在C++中从两个单独的for循环中添加两个数组
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 正在尝试了解输入验证循环
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- 循环后如何继续阅读
- Ardunio UNO解决了多个重叠的定时器循环
- Eigen如何在容器循环中干净地附加矩阵
- 在某些循环内使用vector.push_back时出现分段错误
- 我正在使用嵌套的while循环来解析具有多行的文本文件,但由于某种原因,它只通过第一行,我不知道为什么
- 为什么我的for循环不能正确获取argv
- 如何声明特征矩阵,然后通过嵌套循环初始化它
- while循环中while循环的时间复杂度是多少
- C++中的高效循环缓冲区,它将被传递给C样式数组函数参数
- 为什么在这个代码结束循环中没有得到结束
- 在基于范围的for循环中使用结构化绑定声明
- 用于C++中带有数组和指针的循环
- 循环中的随机函数
- 是什么阻止DOMTimerCoordinator::NextID进入无休止的循环
- 平移 CGAL 多边形,而无需循环穿过折点