File: circular_arcs.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 (95 lines) | stat: -rw-r--r-- 3,794 bytes parent folder | download | duplicates (3)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! \file examples/Arrangement_on_surface_2/circular_arc.cpp
// Constructing an arrangement of various circular arcs and line segments.

#include <CGAL/Cartesian.h>
#include <CGAL/Exact_rational.h>
#include <CGAL/Arr_circle_segment_traits_2.h>
#include <CGAL/Arrangement_2.h>

typedef CGAL::Cartesian<CGAL::Exact_rational>         Kernel;
typedef Kernel::Circle_2                              Circle_2;
typedef Kernel::Segment_2                             Segment_2;
typedef CGAL::Arr_circle_segment_traits_2<Kernel>     Traits_2;
typedef Traits_2::CoordNT                             CoordNT;
typedef Traits_2::Point_2                             Point_2;
typedef Traits_2::Curve_2                             Curve_2;
typedef CGAL::Arrangement_2<Traits_2>                 Arrangement_2;

int main()
{
  std::list<Curve_2>  curves;

  // Create a circle centered at the origin with squared radius 2.
  Kernel::Point_2 c1 = Kernel::Point_2(0, 0);
  Circle_2 circ1 = Circle_2(c1, CGAL::Exact_rational(2));

  curves.push_back(Curve_2(circ1));

  // Create a circle centered at (2,3) with radius 3/2 - note that
  // as the radius is rational we use a different curve constructor.
  Kernel::Point_2 c2 = Kernel::Point_2(2, 3);

  curves.push_back(Curve_2(c2, CGAL::Exact_rational(3, 2)));

  // Create a segment of the line (y = x) with rational endpoints.
  Kernel::Point_2 s3 = Kernel::Point_2(-2, -2);
  Kernel::Point_2 t3 = Kernel::Point_2(2, 2);
  Segment_2 seg3 = Segment_2(s3, t3);

  curves.push_back(Curve_2(seg3));

  // Create a line segment with the same supporting line (y = x), but
  // having one endpoint with irrational coefficients.
  CoordNT sqrt_15 = CoordNT(0, 1, 15); // = sqrt(15)
  Point_2 s4 = Point_2(3, 3);
  Point_2 t4 = Point_2(sqrt_15, sqrt_15);

  curves.push_back(Curve_2(seg3.supporting_line(), s4, t4));

  // Create a circular arc that correspond to the upper half of the
  // circle centered at (1,1) with squared radius 3. We create the
  // circle with clockwise orientation, so the arc is directed from
  // (1 - sqrt(3), 1) to (1 + sqrt(3), 1).
  Kernel::Point_2 c5 = Kernel::Point_2(1, 1);
  Circle_2 circ5 = Circle_2(c5, 3, CGAL::CLOCKWISE);
  CoordNT one_minus_sqrt_3 = CoordNT(1, -1, 3);
  CoordNT one_plus_sqrt_3 = CoordNT(1, 1, 3);
  Point_2 s5 = Point_2(one_minus_sqrt_3, CoordNT(1));
  Point_2 t5 = Point_2(one_plus_sqrt_3, CoordNT(1));

  curves.push_back(Curve_2(circ5, s5, t5));

  // Create a circular arc of the unit circle, directed clockwise from
  // (-1/2, sqrt(3)/2) to (1/2, sqrt(3)/2). Note that we orient the
  // supporting circle accordingly.
  Kernel::Point_2 c6 = Kernel::Point_2(0, 0);
  CoordNT sqrt_3_div_2 = CoordNT(CGAL::Exact_rational(0),
                                 CGAL::Exact_rational(1,2),
                                 CGAL::Exact_rational(3));
  Point_2 s6 = Point_2(CGAL::Exact_rational(-1, 2), sqrt_3_div_2);
  Point_2 t6 = Point_2(CGAL::Exact_rational(1, 2), sqrt_3_div_2);

  curves.push_back(Curve_2(c6, 1, CGAL::CLOCKWISE, s6, t6));

  // Create a circular arc defined by two endpoints and a midpoint,
  // all having rational coordinates. This arc is the upper-right
  // quarter of a circle centered at the origin with radius 5.
  Kernel::Point_2 s7 = Kernel::Point_2(0, 5);
  Kernel::Point_2 mid7 = Kernel::Point_2(3, 4);
  Kernel::Point_2 t7 = Kernel::Point_2(5, 0);

  curves.push_back(Curve_2(s7, mid7, t7));

  // Construct the arrangement of the curves.
  Arrangement_2 arr;

  insert(arr, curves.begin(), curves.end());

  // Print the size of the arrangement.
  std::cout << "The arrangement size:" << std::endl
            << "   V = " << arr.number_of_vertices()
            << ",  E = " << arr.number_of_edges()
            << ",  F = " << arr.number_of_faces() << std::endl;

  return 0;
}