File: hilbert_sort_on_sphere.cpp

package info (click to toggle)
cgal 4.9-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 85,584 kB
  • sloc: cpp: 640,841; ansic: 140,696; sh: 708; fortran: 131; makefile: 114; python: 92
file content (49 lines) | stat: -rw-r--r-- 1,664 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/point_generators_3.h>
#include <CGAL/hilbert_sort_on_sphere.h>
#include <iostream>
#include <vector>

typedef CGAL::Exact_predicates_inexact_constructions_kernel     K;
typedef K::Point_3                                              Point;
typedef K::Vector_3                                             Vector;
typedef K::Sphere_3                                             Sphere;
typedef CGAL::Creator_uniform_3<double,Point>                   Creator_3;

int main ()
{
  std::size_t size = 32;
  CGAL::Random random (42);
  std::vector<Point> v;

  // unit sphere
  std::cout << "UNIT SPHERE: " << std::endl;

  v.reserve(size);
                                                                    
  CGAL::Random_points_on_sphere_3<Point> unit_sphere(1.0, random);  // generate points
  for (std::size_t i = 0; i < size; ++i) v.push_back(*unit_sphere++);

  CGAL::hilbert_sort_on_sphere(v.begin(), v.end());                 // sort

  for(std::size_t i=0; i<size; ++i) std::cout << v[i] << std::endl; //output

  v.clear();

  // given sphere
  std::cout << "GIVEN SPHERE: " << std::endl;

  v.reserve(size);

  Vector trans = Vector(3,4,5);
  Sphere sphere = Sphere(CGAL::ORIGIN + trans, 4);
  CGAL::Random_points_on_sphere_3<Point> given_sphere(2.0, random);  // generate points
  for (std::size_t i = 0; i < size; ++i) v.push_back(*given_sphere++ + trans);

  CGAL::hilbert_sort_on_sphere(v.begin(), v.end(),                   // sort
    sphere.squared_radius(), sphere.center());  

  for(std::size_t i=0; i<size; ++i) std::cout << v[i] << std::endl; //output

  return 0;
}