File: ellipsoid.cpp

package info (click to toggle)
cgal 4.13-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 101,504 kB
  • sloc: cpp: 703,154; ansic: 163,044; sh: 674; fortran: 616; python: 411; makefile: 115
file content (60 lines) | stat: -rw-r--r-- 2,014 bytes parent folder | download | duplicates (8)
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
50
51
52
53
54
55
56
57
58
59
60
#include <CGAL/Cartesian_d.h>
#include <CGAL/MP_Float.h>
#include <CGAL/point_generators_d.h>
#include <CGAL/Approximate_min_ellipsoid_d.h>
#include <CGAL/Approximate_min_ellipsoid_d_traits_d.h>

#include <vector>
#include <iostream>

typedef CGAL::Cartesian_d<double>                              Kernel;
typedef CGAL::MP_Float                                         ET;
typedef CGAL::Approximate_min_ellipsoid_d_traits_d<Kernel, ET> Traits;
typedef Traits::Point                                          Point;
typedef std::vector<Point>                                     Point_list;
typedef CGAL::Approximate_min_ellipsoid_d<Traits>              AME;

int main()
{
  const int      n = 1000;                // number of points
  const int      d = 2;                   // dimension
  const double eps = 0.01;                // approximation ratio is (1+eps)

  // create a set of random points:
  Point_list P;
  CGAL::Random_points_in_cube_d<Point> rpg(d,100.0);
  for (int i = 0; i < n; ++i) {
    P.push_back(*rpg);
    ++rpg;
  }

  // compute approximation:
  Traits traits;
  AME ame(eps, P.begin(), P.end(), traits);

  // write EPS file:
  if (ame.is_full_dimensional() && d == 2)
    ame.write_eps("example.eps");

  // output center coordinates:
  std::cout << "Cartesian center coordinates: ";
  for (AME::Center_coordinate_iterator c_it = ame.center_cartesian_begin();
       c_it != ame.center_cartesian_end();
       ++c_it)
    std::cout << *c_it << ' ';
  std::cout << ".\n";

  if (d == 2 || d == 3) {
    // output  axes:
    AME::Axes_lengths_iterator axes = ame.axes_lengths_begin();
    for (int i = 0; i < d; ++i) {
      std::cout << "Semiaxis " << i << " has length " << *axes++  << "\n"
                << "and Cartesian coordinates ";
      for (AME::Axes_direction_coordinate_iterator
             d_it = ame.axis_direction_cartesian_begin(i);
           d_it != ame.axis_direction_cartesian_end(i); ++d_it)
        std::cout << *d_it << ' ';
      std::cout << ".\n";
    }
  }
}