检查给定点是否在圆的(无)有界 side/boundary 上(CGAL)

Check whether a given point is on the (un)bounded side/boundary of a circle (CGAL)

我正在使用 Kernel::Circle_2 和 CGAL::Arr_circle_segment_traits_2。

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

有classCircle_2的函数叫bounded_side,但只支持Kernel::Point_2的点。当我使用 CGAL::to_double() 将点转换为这个 class 时,我失去了准确性。

还有其他方法可以执行此检查吗? 如果有帮助,我将信息存储在 2D_Arrangement 中。

您可以使用以下代码。请注意,二维点的坐标类型为 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;
    }