1 //! \file examples/Example_2/ex_envelope_circles.cpp
2 // Constructing the envelopes of a set of circles using the circle-segment
3 // traits.
4
5 #include <CGAL/Exact_rational.h>
6 #include <CGAL/Cartesian.h>
7 #include <CGAL/Arr_circle_segment_traits_2.h>
8 #include <CGAL/Arrangement_2.h>
9 #include <CGAL/Envelope_diagram_1.h>
10 #include <CGAL/envelope_2.h>
11
12 typedef CGAL::Exact_rational Number_type;
13 typedef CGAL::Cartesian<Number_type> Kernel;
14 typedef Kernel::Point_2 Kernel_point_2;
15 typedef Kernel::Circle_2 Circle_2;
16 typedef CGAL::Arr_circle_segment_traits_2<Kernel> Traits_2;
17 typedef Traits_2::Curve_2 Curve_2;
18 typedef CGAL::Envelope_diagram_1<Traits_2> Diagram_1;
19
20 /*! Print the given envelope diagram. */
print_diagram(const Diagram_1 & diag)21 void print_diagram (const Diagram_1& diag)
22 {
23 Diagram_1::Edge_const_handle e = diag.leftmost();
24 Diagram_1::Vertex_const_handle v;
25
26 while (e != diag.rightmost())
27 {
28 std::cout << "Edge: ";
29 if (! e->is_empty())
30 {
31 Circle_2 circ = e->curve().supporting_circle();
32 std::cout << " (x - " << CGAL::to_double(circ.center().x()) << ")^2 +"
33 << " (y - " << CGAL::to_double(circ.center().y()) << ")^2 = "
34 << CGAL::to_double(circ.squared_radius()) << std::endl;
35 }
36 else
37 std::cout << " [empty]" << std::endl;
38
39 v = e->right();
40 std::cout << "Vertex (" << CGAL::to_double(v->point().x()) << ' '
41 << CGAL::to_double(v->point().y()) << ')' << std::endl;
42
43 e = v->right();
44 }
45 CGAL_assertion (e->is_empty());
46 std::cout << "Edge: [empty]" << std::endl;
47
48 return;
49 }
50
51 /*! The main program. */
main()52 int main ()
53 {
54 // Create four input circles.
55 Curve_2 circles[4];
56
57 circles[0] = Circle_2 (Kernel_point_2 (1, 3), CGAL::square(2));
58 circles[1] = Circle_2 (Kernel_point_2 (4, 5), CGAL::square(4));
59 circles[2] = Circle_2 (Kernel_point_2 (5, 1), CGAL::square(1));
60 circles[3] = Circle_2 (Kernel_point_2 (6, 7), CGAL::square(2));
61
62 // Compute the minimization diagram that represents their lower envelope.
63 Diagram_1 min_diag;
64
65 lower_envelope_2 (&(circles[0]), &(circles[4]), min_diag);
66 print_diagram (min_diag);
67
68 // Compute the maximization diagram that represents the upper envelope.
69 Diagram_1 max_diag;
70
71 upper_envelope_2 (&(circles[0]), &(circles[4]), max_diag);
72 print_diagram (max_diag);
73
74 return (0);
75 }
76