【问题标题】:Translate CGAL Polygon without looping through vertices平移 CGAL 多边形而不循环顶点
【发布时间】:2017-08-01 14:15:22
【问题描述】:

我刚开始使用 CGAL,因此我的问题是,因为我觉得您应该能够比循环遍历顶点更容易地翻译 CGAL::Polygon_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);
        }

有人可以告诉我这是否是正确的方法,或者给我指点如何做得更好。

【问题讨论】:

    标签: c++ polygon cgal


    【解决方案1】:

    您可以调用transform free 函数,该函数将完全按照您的要求进行操作。

    所以在代码中,做:

    Transformation translate(CGAL::TRANSLATION, CGAL_Vector(0.4, 0));
    P = transform(translate, P);
    

    【讨论】:

      猜你喜欢
      • 2014-03-16
      • 1970-01-01
      • 2018-08-28
      • 1970-01-01
      • 1970-01-01
      • 2016-09-13
      • 2019-12-14
      • 2011-09-26
      • 1970-01-01
      相关资源
      最近更新 更多