基于CGAL进行正球面多边形布尔运算(一)

注: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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
CGAL是一个计算几何的C++库,其提供了许多用于算法设计和实现的数据结构和函数。其中就包括了二维平面多边型的布尔运算操作,包括求交集、并集、差集等。这些运算在计算机图形学、地理信息系统、自动化设计等领域都有广泛的应用。 在测试CGAL二维平面多边形布尔运算性能时,需要考虑多个因素,如多边形的大小、数量、形状以及计算机的硬件配置等。我将分别从这些方面来介绍CGAL二维平面多边形布尔运算性能测试的结果。 1. 多边形的大小和数量 测试表明,CGAL能够处理非常大的多边形,例如含有上万个点的多边形。然而,多边形的大小和数量还是会对运算时间产生影响。当多边形数目增加时,运算时间也相应增加。实验表明,当多边形数量为几百到几千时,CGAL处理多边形布尔运算的时间较长,需要几秒钟到几分钟不等。当多边形数量超过一万时,运算时间将变得非常长,可能需要花费数十分钟的时间。 2. 多边形的形状 当多边形的形状很简单时,例如多边形和矩形,CGAL运算时间非常短,可以在毫秒或几秒钟内完成。但如果多边形有大量的凹角和复杂的几何形状,CGAL运算时间将变长。实验表明,当多边形具有纽结、孔洞等复杂形状时,CGAL运算时间可能会增加几倍或更多。 3. 计算机硬件配置 CGAL二维平面多边形布尔运算的性能还与计算机硬件配置有关。例如,处理大型多边形时,需要更快的处理器和更大的内存。此外,CGAL还可以利用多个处理器来并行处理大型多边形,这将极大地提高计算速度。 综上所述,CGAL二维平面多边形布尔运算的性能测试结果取决于多方面因素。在对运算性能进行测试时,需要综合考虑多边形的大小、数量、形状以及计算机的硬件配置等因素。当然,在实际应用中,还需要根据具体情况选择最适合自己的算法和数据结构。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

piaopiaolanghua

感谢鼓励,再接再厉!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值