【问题标题】:Obtaining the intersection points of two circles in CGAL在CGAL中获取两个圆的交点
【发布时间】:2018-11-27 03:47:26
【问题描述】:

我试图找出 CGAL 中两个单位半径圆的交点。受 CGAL 示例代码和教程的启发,我成功地创建了以下代码。但不幸的是,我无法打印出分数。我注意到向量的大小是交点的数量。任何帮助将不胜感激,因为我是 CGAL 的新手。

    #include <CGAL/Circular_kernel_intersections.h>
    #include <CGAL/Exact_circular_kernel_2.h>

    typedef CGAL::Exact_circular_kernel_2             Circular_k;
    typedef CGAL::Point_2<Circular_k>                 Point_2;
    typedef CGAL::Circle_2<Circular_k>                Circle_2;
    typedef CGAL::Circular_arc_2<Circular_k>          Circular_arc_2;
    typedef CGAL::CK2_Intersection_traits<Circular_k, Circle_2, Circle_2>::type Intersection_result;

    using namespace std;

    int main() {

        Point_2 p(2,2), r(5.5,2);
        Circle_2 c1(p,1), c2(r,1);

        vector<Intersection_result> res;
        intersection(c1,c2,back_inserter(res));

        cout << res.size() << endl;
    }

【问题讨论】:

    标签: c++ computational-geometry cgal


    【解决方案1】:

    我测试了您的代码,它似乎可以工作。请注意,交点存储为Circular_arc_point_2。使用您的代码,我只添加了以下几行:

    using boostRetVal = std::pair<CGAL::Circular_arc_point_2<CGAL::Filtered_bbox_circular_kernel_2<CGAL::Circular_kernel_2<CGAL::Cartesian<CGAL::Gmpq>, CGAL::Algebraic_kernel_for_circles_2_2<CGAL::Gmpq> > > > , unsigned>;
    
    for(const auto& element : res) {
      auto algPoint = std::get<0>( boost::get< boostRetVal >(element) );
      auto point = Point_2(to_double(algPoint.x()), to_double(algPoint.y()));
      std::cout << point << std::endl;
    }
    

    作为我使用p(0,0)r(2,0)的点,作为圈子c1(p,4)c2(r,1),那么接收到的输出是:

    2
    7/4 -4360591588697965/4503599627370496
    7/4 4360591588697965/4503599627370496
    

    【讨论】:

    • 非常感谢您帮助我。但是,请您告诉我(如果可能的话)您是如何解决这个问题的?有系统的方法吗?我想我不知道什么。
    • 我有时使用 CGAL::intersection 方法,因此我知道应该可以使用 boost::get 访问结果中的元素。然后,我阅读了其他一些关于圆弧相交的帖子,并通过 CGAL 文档发现必须返回类似 boostRetVal 的内容。当然,clang 错误消息在这里确实有所帮助。然后,我只需要找到一种方法将这些roots_of_2 值变成一个点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-12
    • 1970-01-01
    • 1970-01-01
    • 2013-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多