4

I am trying to find out the intersection points of two unit-radius circles in CGAL. Inspired by the CGAL sample codes and tutorials, I have succeeded in creating the following code. But unfortunately, I am unable to print out the points. I have noticed that the size of the vector is the number of intersection points. Any help will be appreciated since I am new to 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;
    }
aghost
  • 235
  • 2
  • 12

1 Answers1

3

I tested your code and it seems to work. Note that the intersection points are stored as Circular_arc_point_2. Using your code I added only the following lines:

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;
}

As points I used p(0,0), r(2,0), as circles c1(p,4), c2(r,1), then the received output was:

2
7/4 -4360591588697965/4503599627370496
7/4 4360591588697965/4503599627370496
gue
  • 1,868
  • 1
  • 16
  • 21
  • I really appreciate that you have helped me out. But would you please let me know (if possible) how did you figure this out? Is there a systematic way? I think I am unaware of something. – aghost Nov 27 '18 at 13:20
  • 1
    I use the CGAL::intersection method sometimes and thus I knew that it should be possible to access elements in the result using boost::get. Then, I read through a few other posts about circular arc intersection and figured out, also via the CGAL doc, that something like boostRetVal must be returned. Granted, the clang error messages did help here. Then, I only had to find a way to get these roots_of_2 values into a point. – gue Nov 27 '18 at 13:25