您可以使用下面的代碼。請注意,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;
}
謝謝@sloriot! – Mega