2017-01-03 71 views
2

我正在使用Kernel :: Circle_2和CGAL :: Arr_circle_segment_traits_2。检查给定点是否位于圆的(未)有界边/边界上(CGAL)

给定一个点(这组特征的嵌套类型Point_2),我想检查它是在有界边,无边还是在给定圆的边界上。

有类Circle_2的函数叫做bounded_side,但它仅支持Kernel :: Point_2的点。当我使用CGAL :: to_double()将点转换为此类时,我失去了准确性。

是否有另一种方法来执行此检查? 我将信息存储在2D_Arrangement中,如果有帮助的话。

回答

1

您可以使用下面的代码。请注意,2D点的坐标类型为Sqrt_extension

#include <CGAL/Exact_predicates_exact_constructions_kernel.h> 
    #include <CGAL/Arr_circle_segment_traits_2.h> 

    typedef CGAL::Exact_predicates_exact_constructions_kernel K; 
    typedef CGAL::Arr_circle_segment_traits_2<K> Traits; 
    typedef Traits::Point_2::CoordNT Sqrt_extension; 

    CGAL::Bounded_side 
    incircle(const typename K::Circle_2& circle, 
      const typename Traits::Point_2& p) 
    { 
     const K::Point_2& center = circle.center(); 
     K::FT sq_rad = circle.squared_radius(); 

     switch(CGAL::compare( CGAL::square(p.x()-center.x())-sq_rad, 
          -CGAL::square(p.y()-center.y()))) 
     { 
     case CGAL::LARGER: 
      return CGAL::ON_UNBOUNDED_SIDE; 
     case CGAL::SMALLER: 
      return CGAL::ON_BOUNDED_SIDE; 
     case CGAL::EQUAL: 
      break; 
     } 
     return CGAL::ON_BOUNDARY; 
    } 

    int main() 
    { 

     K::Circle_2 circle(K::Point_2(0,0), 2); 

     Traits::Point_2 out(Sqrt_extension(1,2,3) , Sqrt_extension(4,5,6)); 
     CGAL_assertion(incircle(circle, out) == CGAL::ON_UNBOUNDED_SIDE); 

     Traits::Point_2 in(Sqrt_extension(1) , Sqrt_extension(0)); 
     CGAL_assertion(incircle(circle, in) == CGAL::ON_BOUNDED_SIDE); 

     Traits::Point_2 bnd(Sqrt_extension(0,1,2) , Sqrt_extension(0)); 
     CGAL_assertion(incircle(circle, bnd) == CGAL::ON_BOUNDARY); 

     return 0; 
    } 
+0

谢谢@sloriot! – Mega