// Copyright (c) 2010 INRIA Sophia-Antipolis (France). // All rights reserved. // // This file is part of CGAL (www.cgal.org) // // $URL: https://github.com/CGAL/cgal/blob/v5.1/Generator/include/CGAL/point_generators_d.h $ // $Id: point_generators_d.h 8bb22d5 2020-03-26T14:23:37+01:00 Sébastien Loriot // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial // // Author(s) : Olivier Devillers #ifndef CGAL_POINT_GENERATORS_D_H #define CGAL_POINT_GENERATORS_D_H 1 #include #include #include #include #include #include namespace CGAL { template < class P > class Random_points_in_ball_d : public Random_generator_base

{ void generate_point(); int dimension; public: typedef Random_points_in_ball_d

This; Random_points_in_ball_d( int dim, double a = 1, Random& rnd = get_default_random()) // g is an input iterator creating points of type `P' uniformly // distributed in the open sphere with radius r, i.e. |`*g'| < r . : Random_generator_base

( a, rnd), dimension(dim) { generate_point(); } This& operator++() { generate_point(); return *this; } This operator++(int) { This tmp = *this; ++(*this); return tmp; } }; template < class P > void Random_points_in_ball_d

:: generate_point() { double norm = 0; std::vector< double > coord(dimension); for(int i=0; i_rnd.get_double(); a = std::sqrt( -2* std::log(1-a) ); double b=this->_rnd.get_double(); b = std::cos(2*CGAL_PI*b); coord[i]= a*b; norm += coord[i]*coord[i]; } norm = this->d_range * std::pow(this->_rnd.get_double(),1.0/dimension) /std::sqrt(norm); for(int i=0; id_item = P(dimension, coord.begin(), coord.end() ); } template < class P > class Random_points_on_sphere_d : public Random_generator_base

{ void generate_point(); int dimension; public: typedef Random_points_on_sphere_d

This; Random_points_on_sphere_d( int dim, double a = 1, Random& rnd = get_default_random()) // g is an input iterator creating points of type `P' uniformly // distributed on the sphere with radius r, i.e. |`*g'| == r . : Random_generator_base

( a, rnd), dimension(dim) { generate_point(); } This& operator++() { generate_point(); return *this; } This operator++(int) { This tmp = *this; ++(*this); return tmp; } }; template < class P > void Random_points_on_sphere_d

:: generate_point() { double norm = 0; std::vector< double > coord(dimension); for(int i=0; i_rnd.get_double(); a = std::sqrt( -2* std::log(1-a) ); double b=this->_rnd.get_double(); b = std::cos(2*CGAL_PI*b); coord[i]= a*b; norm += coord[i]*coord[i]; } norm = this->d_range /std::sqrt(norm); for(int i=0; id_item = P(dimension, coord.begin(), coord.end() ); } template < class P > class Random_points_in_cube_d : public Random_generator_base

{ void generate_point(); int dimension; public: typedef Random_points_in_cube_d

This; Random_points_in_cube_d( int dim, double a = 1, Random& rnd = get_default_random()) : Random_generator_base

( a, rnd), dimension(dim) { generate_point(); } This& operator++() { generate_point(); return *this; } This operator++(int) { This tmp = *this; ++(*this); return tmp; } }; template < class P > void Random_points_in_cube_d

:: generate_point() { typedef typename Kernel_traits

::Kernel::RT RT; CGAL_assume(dimension>0); std::vector coord(dimension); for(int i=0; id_range * ( 2 * this->_rnd.get_double() - 1.0)); P p(dimension, coord.begin(), coord.end() ); this->d_item = p; } template OutputIterator points_on_cube_grid_d( int dimension, double a, std::size_t n, OutputIterator o, Creator creator) { // typedef typename OutputIterator::container_type::value_type Point; if (n == 0) return o; // take m smallest such that m^dimension > n int m=int(std::floor(std::pow(static_cast(n),1/(double)dimension))); while(true) { int nn=1; for (int i=0; i=n) break; ++m; } double base = -a; // Left and bottom boundary. double step = 2*a/(m-1); std::vector indices(dimension); std::vector coord(dimension); //initialize indices int j; for(j=0; j< dimension; ++j) { indices[j]=0; } std::size_t i=0; while (true) { //compute point for(j=0; j< dimension; ++j) { coord[j]=base+step*indices[j]; } *o = creator(coord.begin(), coord.end() ); ++i; if (i==n) break; ++o; // find index to increment for ( j=0; j < dimension; ++j) if ( indices[j]0) { --j; indices[j]=0; } } return o; } } //namespace CGAL #include #endif // CGAL_POINT_GENERATORS_D_H // // EOF //