注:CGAL中的球面布尔运算,支持的是正圆球,好像不支持椭球。假如不考虑地球扁率,可用于地表的多边形在三维的框架下进行交、并、差运算,而不是映射到二维平面进行运算(做平面映射,或直接用经纬度进行运算)。
【关于CGAL】
CGAL: The Computational Geometry Algorithms Library,计算几何算法库。
官网:www.cgal.org
【参考文档】
https://doc.cgal.org/latest/Nef_S2/classCGAL_1_1Nef__polyhedron__S2.html
https://doc.cgal.org/5.5.2/Nef_S2/classCGAL_1_1Nef__polyhedron__S2.html
https://doc.cgal.org/5.5.2/Nef_S2/Nef_S2_2nef_s2_construction_8cpp-example.html
【相关类】
An instance of data type Nef_polyhedron_S2<Traits> is a subset of the sphere S2 that is the result of forming complements and intersections starting from a finite set H of halfspaces bounded by a plane containing the origin.
Halfspaces correspond to hemispheres of S2 and are therefore modeled by oriented great circles of type Sphere_circle. Nef_polyhedron_S2 is closed under all binary set operations intersection, union, difference, complement and under the topological operations boundary, closure, and interior.
template< class Nef_polyhedronTraits_S2,
class Nef_polyhedronItems_S2 = CGAL::SM_items,
class Nef_polyhedronMarks = bool >
class Nef_polyhedron_S2;
The first parameter requires one of the following exact kernels: Homogeneous, Simple_homogeneous parametrized with Gmpz, leda_integer or any other number type modeling Z, or Cartesian, Simple_cartesian parametrized with Gmpq, leda_rational, Quotient<Gmpz> or any other number type modeling Q.
The second parameter and the third parameter are for future considerations. Neither Nef_polyhedronItems_S2 nor Nef_polyhedronMarks is specifed, yet. Do not use other than the default types for these two template parameters.
【相关头文件】
#include <CGAL/Nef_polyhedron_S2.h>
【球面多边形构造函数】
Nef_polyhedron_S2 (Content sphere=EMPTY)
creates an instance N of type Nef_polyhedron_S2<K> and initializes it to the empty set if sphere == EMPTY and to the whole sphere if sphere == COMPLETE.
Nef_polyhedron_S2 (Sphere_circle c, Boundary circle=INCLUDED)
creates a Nef polyhedron N containing the half-sphere left of c including c if circle==INCLUDED, excluding c if circle==EXCLUDED.
template<class Forward_iterator >
Nef_polyhedron_S2 (Forward_iterator first, Forward_iterator beyond, Boundary b=INCLUDED)
creates a Nef polyhedron N from the set of sphere segments in the iterator range [first,beyond).
【球面多边形求交示例代码】
#include <CGAL/Exact_integer.h>
#include <CGAL/Homogeneous.h>
#include <CGAL/Nef_polyhedron_S2.h>
#include <cassert>
typedef CGAL::Exact_integer RT;
typedef CGAL::Homogeneous<RT> Kernel;
typedef CGAL::Nef_polyhedron_S2<Kernel> Nef_polyhedron;
typedef Nef_polyhedron::Sphere_point Sphere_point;
typedef Nef_polyhedron::Sphere_segment Sphere_segment;
typedef Nef_polyhedron::Sphere_circle Sphere_circle;
int main()
{
Nef_polyhedron N1(Nef_polyhedron::COMPLETE);
Sphere_circle c(1,1,1); // c : x + y + z = 0
Nef_polyhedron N2(c, Nef_polyhedron::INCLUDED);
Nef_polyhedron N3(N2.complement());
assert(N1 == N2.join(N3));
Sphere_point p1(1,0,0), p2(0,1,0), p3(0,0,1);
Sphere_segment s1(p1,p2), s2(p2,p3), s3(p3,p1);
Sphere_segment triangle[3] = { s1, s2, s3 };
Nef_polyhedron N4(triangle, triangle+3);
Nef_polyhedron N5;
N5 += N2;
N5 = N5.intersection(N4);
assert(N5 <= N2 && N5 != N4);
return 0;
}
————————————————————————————
#include <CGAL/Exact_integer.h>
#include <CGAL/Homogeneous.h>
#include <CGAL/Nef_polyhedron_S2.h>
typedef CGAL::Exact_integer RT;
typedef CGAL::Homogeneous<RT> Kernel;
typedef CGAL::Nef_polyhedron_S2<Kernel> Nef_polyhedron;
typedef Nef_polyhedron::Sphere_circle Sphere_circle;
int main()
{
Nef_polyhedron N1(Sphere_circle(1,0,0));
Nef_polyhedron N2(Sphere_circle(0,1,0), Nef_polyhedron::EXCLUDED);
Nef_polyhedron N3 = N1 * N2;
return 0;
}
————————————————————————————
#include <CGAL/Exact_integer.h>
#include <CGAL/Homogeneous.h>
#include <CGAL/Nef_polyhedron_S2.h>
#include <CGAL/Exact_rational.h>
#include <CGAL/Cartesian.h>
//typedef CGAL::Exact_rational FT;
//typedef CGAL::Cartesian<FT> Kernel;
typedef CGAL::Cartesian<double> Kernel;
//typedef CGAL::Exact_integer RT;
//typedef CGAL::Homogeneous<RT> Kernel;
typedef CGAL::Nef_polyhedron_S2<Kernel> Nef_polyhedron;
typedef Nef_polyhedron::Sphere_circle Sphere_circle;
int main()
{
Nef_polyhedron N1(Sphere_circle(1.5,0,0));
Nef_polyhedron N2(Sphere_circle(0,1.5,0), Nef_polyhedron::EXCLUDED);
Nef_polyhedron N3 = N1 * N2;
std::cout << N3 << "\n\n";
std::cout << N3.number_of_sfaces() << "\n";
return 0;
}
输出:
Nef_polyhedron_S2
Sphere_map_2
vertices 2
edges 4
loops 0
faces 2
0 { 0 2, 0, -0 -0 2.25}
1 { 0 3, 0, -0 -0 -2.25}
0 { 1, 3, 3, 0, 0, 1, -3.375 -0 -0 0 }
1 { 0, 2, 2, 1, 1, 1, 3.375 0 0 -0 }
2 { 3, 1, 1, 0, 1, 0, 0 3.375 0 -0 }
3 { 2, 0, 0, 1, 0, 0, -0 -3.375 -0 0 }
0 { 0 , , , 0 }
1 { 1 , , , 1 }
2
【其他参考】
(1)关于Exact_integer和Exact_rational
#include <CGAL/Exact_integer.h> //Exact_integer is an exact integer number type.
#include <CGAL/Exact_rational.h> //Exact_rational is an exact rational number type, constructible from double.
(2)CGAL环境配置参考:
https://blog.csdn.net/qq_32867925/article/details/127021063
https://blog.csdn.net/qq_36686437/article/details/126807537
(3)依赖库
CGAL从5.0版本之后以纯头文件的形式提供,但是依赖 Boost和 GMP、MPFR库。
Since Version 5.0, CGAL is now header-only by default, meaning that you do not need to build and install CGAL. Usage of CGAL as a header-only library。 //INSTALL.md