一、概述
给定球半径和点的个数,生成球面点云。
1、主要函数
头文件
#include <CGAL/point_generators_3.h>
函数
CGAL::Random_points_on_sphere_3<Point_3> g(rS);
std::copy_n(g, n, std::back_inserter(points));
n
:点的个数。rS
:球半径。
二、代码实现
#include <vector>
#include <iostream>
#include <CGAL/algorithm.h>
#include <CGAL/IO/write_points.h>
#include <CGAL/point_generators_3.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::FT Coord_type;
typedef K::Point_3 Point_3;
int main()
{
// ------------------------------参数设置------------------------------
int n = 10000; // 点的个数
double rS = 2.0; // 球的半径
std::vector< Point_3> points;
points.reserve(n);
std::cout << "在半径为:"<<rS<<"的球面上随机生成" << n << "个点。" << std::endl;
// ---------------------------生成球形点云-----------------------------
CGAL::Random_points_on_sphere_3<Point_3> g(rS);
std::copy_n(g, n, std::back_inserter(points));
// -----------------------------保存点云-------------------------------
const std::string output_filename("randomSphere.xyz");
if (!CGAL::IO::write_points(output_filename, points, CGAL::parameters::stream_precision(17)))
{
return -1;
}
return 0;
}
三、结果展示
在半径为:2的球面上随机生成10000个点。