一堆在球面上的大圆将球面切割成球面多边形。我想知道每个多边形的面积。(实际上,我只需要最小的面积,但我不认为这会改变任何事情。)
CGAL::Nef_polyhedron_S2似乎非常适合这个任务,但我有两个问题。首先,我不确定如何最好地向CGAL提出问题。下面是一个初步尝试,但我确定它不是最佳选择。对于我的使用情况,使用精确核心太慢了。这也导致了第二个问题:相同的代码在不精确的核心下导致段错误。
CGAL::Nef_polyhedron_S2似乎非常适合这个任务,但我有两个问题。首先,我不确定如何最好地向CGAL提出问题。下面是一个初步尝试,但我确定它不是最佳选择。对于我的使用情况,使用精确核心太慢了。这也导致了第二个问题:相同的代码在不精确的核心下导致段错误。
#include <CGAL/Nef_polyhedron_S2.h>
#include <CGAL/Random.h>
#include <iostream>
#define EXACT 1
#if EXACT
// TOO SLOW
#include <CGAL/Exact_integer.h>
#include <CGAL/Homogeneous.h>
typedef CGAL::Exact_integer RT;
typedef CGAL::Homogeneous<RT> Kernel;
#else
// SEGFAULTS
#include <CGAL/Cartesian.h>
typedef CGAL::Cartesian<double> Kernel;
#endif
typedef CGAL::Nef_polyhedron_S2<Kernel> Nef_polyhedron;
typedef Nef_polyhedron::Sphere_circle Sphere_circle;
typedef Kernel::Vector_3 Vector_3;
typedef Kernel::Plane_3 Plane_3;
// ChatGPT-4's Marsaglia implementation as a placeholder
Vector_3 create_random_unit_vector(CGAL::Random& rng) {
double x1, x2, s;
do {
x1 = 2 * rng.get_double() - 1;
x2 = 2 * rng.get_double() - 1;
s = x1 * x1 + x2 * x2;
} while (s >= 1); // Continue looping until s is less than 1.
double z = 1 - 2 * s;
double scale = 2 * std::sqrt(1 - z * z);
double x = scale * x1;
double y = scale * x2;
const int N = 1000000;
return Vector_3((int)(x * N), (int)(y * N), (int)(z * N));
}
int main()
{
CGAL::Random rng(1);
const int n = 10;
std::cout << "starting construction" << std::endl;
Nef_polyhedron N(Nef_polyhedron::EMPTY);
for (int i=0; i<n; ++i) {
Vector_3 v = create_random_unit_vector(rng);
Plane_3 plane(CGAL::ORIGIN, v);
Sphere_circle S(plane);
N = N + Nef_polyhedron(S) * Nef_polyhedron(S.opposite());
}
std::cout << N.number_of_sfaces() << " faces" << std::endl;
std::cout << "supposed to be " << n * n - n + 2 << std::endl;
return 0;
}