I'm trying to use CGAL to find the intersection between two objects: a Circle_2 and a Line_2. The code compiles but the result is not correct.
This is my code:
typedef CGAL::Exact_circular_kernel_2 Circular_k;
typedef CGAL::Point_2<Circular_k> Point_2;
typedef CGAL::Circular_arc_point_2<Circular_k> CircularArcPoint_2;
typedef CGAL::Direction_2<Circular_k> Direction_2;
typedef CGAL::Line_2<Circular_k> Line_2;
typedef CGAL::Circle_2<Circular_k> Circle_2;
typedef CGAL::CK2_Intersection_traits<Circular_k, Circle_2, Circle_2>::type Intersection_cc_result;
typedef CGAL::CK2_Intersection_traits<Circular_k, Circle_2, Line_2>::type Intersection_cl_result;
int main() {
Point_2 a(0.15, 0.15), b(-0.15, -0.15), c(-0.15, 0.15), d(0.15, -0.15);
double u = 0.5;
double theta = atan(u);
Line_2 r2(b, Direction_2(sin(-1.5708+theta),cos(-1.5708+theta)));
Circle_2 cir(Point_2 (0,0), 4);
std::vector<Intersection_cl_result> out1s;
intersection(cir,r2,back_inserter(out1s));
std::cout<<"size intersection: "<<out1s.size()<<std::endl;
CircularArcPoint_2 v1s;
assign(v1s, out1s[0]);
std::cout <<"v1s = "<< v1s << std::endl;
return 0;
}
This is my output:
size intersection: 2
v1s = EXT[0/1,0/1,0/1] EXT[0/1,0/1,0/1]
I don't understand why i get this: "v1s = EXT[0/1,0/1,0/1] EXT[0/1,0/1,0/1] ". The point "v1s" should be the first result from the intersection of the Circle_2: "cir" and the Line_2: "r2".
What could i do to define this intersection point?
Solved. Changed my code to:
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 >;
std::vector<Intersection_cl_result> out1s;
intersection(cir,r2,back_inserter(out1s));
const auto v1_s =std::get<0>( boost::get<boostRetVal>(out1s[0]));
const auto v1s =Point_2(to_double(v1_s.x()), to_double(v1_s.y()));