CGAL 生成球形点云

目录

  • 一、概述
    • 1、主要函数
  • 二、代码实现
  • 三、结果展示

一、概述

  给定球半径和点的个数,生成球面点云。

1、主要函数

头文件

#include 

函数

CGAL::Random_points_on_sphere_3<Point_3> g(rS);
	std::copy_n(g, n, std::back_inserter(points));
  • n:点的个数。
  • rS:球半径。

二、代码实现

#include 
#include 
#include 
#include 
#include 
#include 

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个点。

CGAL 生成球形点云_第1张图片

你可能感兴趣的:(CGAL学习,c++,开发语言,计算机视觉,3d)