是否有一个 CGAL 函数可以检查一个点是否在带孔的线性多边形内?
Is there a CGAL function that checks if a point is inside a linear polygon with holes?
我想检查一个点是在有孔的多边形之内还是之外。具体来说,我感兴趣的是给定点是否位于带孔的多边形的“填充区域”内;如果这个点在一个洞里,我会认为它在有洞的多边形之外。
我知道有一个 CGAL 函数 check_inside
可以检查一个点是否位于多边形内(没有孔)。还有一个 CGAL 函数 connect_holes
,它绘制了一条路径,从带孔的多边形中每个孔的最高顶点到多边形本身。我可以看到使用这些函数的两个解决方法来实现我的 objective,但我想知道是否有一个 CGAL 函数可以直接执行此操作。
参见 oriented_side() CGAL::General_polygon_set_2<> 的成员函数。显然,还有一个免费(重载)的功能(出于某种原因未记录)。
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Boolean_set_operations_2.h>
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::Point_2 Point_2;
typedef CGAL::Polygon_2<Kernel> Polygon_2;
typedef CGAL::Polygon_with_holes_2<Kernel> Polygon_with_holes_2;
# define nice(os) ((os == CGAL::ON_ORIENTED_BOUNDARY) ? "on boundary" : \
(os == CGAL::POSITIVE) ? "inside" : "outside")
int main() {
Polygon_2 hole;
hole.push_back(Point_2(1, 1));
hole.push_back(Point_2(1, 2));
hole.push_back(Point_2(2, 2));
hole.push_back(Point_2(2, 1));
Polygon_2 out;
out.push_back(Point_2(0, 0));
out.push_back(Point_2(3, 0));
out.push_back(Point_2(3, 3));
out.push_back(Point_2(0, 3));
Polygon_with_holes_2 pwh(out, &hole, &hole+1);
std::cout << pwh << std::endl;
auto os = CGAL::oriented_side(Point_2(0, 0), pwh);
std::cout << "(0,0) is : " << nice(os) << std::endl;
os = CGAL::oriented_side(Point_2(0.5, 0.5), pwh);
std::cout << "(0,0) is : " << nice(os) << std::endl;
os = CGAL::oriented_side(Point_2(1, 1), pwh);
std::cout << "(0,0) is : " << nice(os) << std::endl;
os = CGAL::oriented_side(Point_2(2.5, 2.5), pwh);
std::cout << "(0,0) is : " << nice(os) << std::endl;
os = CGAL::oriented_side(Point_2(3, 3), pwh);
std::cout << "(0,0) is : " << nice(os) << std::endl;
os = CGAL::oriented_side(Point_2(3.5, 3.5), pwh);
std::cout << "(0,0) is : " << nice(os) << std::endl;
return 0;
}
我想检查一个点是在有孔的多边形之内还是之外。具体来说,我感兴趣的是给定点是否位于带孔的多边形的“填充区域”内;如果这个点在一个洞里,我会认为它在有洞的多边形之外。
我知道有一个 CGAL 函数 check_inside
可以检查一个点是否位于多边形内(没有孔)。还有一个 CGAL 函数 connect_holes
,它绘制了一条路径,从带孔的多边形中每个孔的最高顶点到多边形本身。我可以看到使用这些函数的两个解决方法来实现我的 objective,但我想知道是否有一个 CGAL 函数可以直接执行此操作。
参见 oriented_side() CGAL::General_polygon_set_2<> 的成员函数。显然,还有一个免费(重载)的功能(出于某种原因未记录)。
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Boolean_set_operations_2.h>
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::Point_2 Point_2;
typedef CGAL::Polygon_2<Kernel> Polygon_2;
typedef CGAL::Polygon_with_holes_2<Kernel> Polygon_with_holes_2;
# define nice(os) ((os == CGAL::ON_ORIENTED_BOUNDARY) ? "on boundary" : \
(os == CGAL::POSITIVE) ? "inside" : "outside")
int main() {
Polygon_2 hole;
hole.push_back(Point_2(1, 1));
hole.push_back(Point_2(1, 2));
hole.push_back(Point_2(2, 2));
hole.push_back(Point_2(2, 1));
Polygon_2 out;
out.push_back(Point_2(0, 0));
out.push_back(Point_2(3, 0));
out.push_back(Point_2(3, 3));
out.push_back(Point_2(0, 3));
Polygon_with_holes_2 pwh(out, &hole, &hole+1);
std::cout << pwh << std::endl;
auto os = CGAL::oriented_side(Point_2(0, 0), pwh);
std::cout << "(0,0) is : " << nice(os) << std::endl;
os = CGAL::oriented_side(Point_2(0.5, 0.5), pwh);
std::cout << "(0,0) is : " << nice(os) << std::endl;
os = CGAL::oriented_side(Point_2(1, 1), pwh);
std::cout << "(0,0) is : " << nice(os) << std::endl;
os = CGAL::oriented_side(Point_2(2.5, 2.5), pwh);
std::cout << "(0,0) is : " << nice(os) << std::endl;
os = CGAL::oriented_side(Point_2(3, 3), pwh);
std::cout << "(0,0) is : " << nice(os) << std::endl;
os = CGAL::oriented_side(Point_2(3.5, 3.5), pwh);
std::cout << "(0,0) is : " << nice(os) << std::endl;
return 0;
}