int main () { // Construct an arrangement of four polylines named A--D. Arrangement_2 arr; Point_2 points1[5] = {Point_2(0,0), Point_2(2,4), Point_2(3,3), Point_2(4,4), Point_2(6,0)}; insert (arr, Curve_2 (Polyline_2 (points1, points1 + 5), "A")); Point_2 points2[3] = {Point_2(1,5), Point_2(3,3), Point_2(5,5)}; insert (arr, Curve_2 (Polyline_2 (points2, points2 + 3), "B")); Point_2 points3[4] = {Point_2(1,0), Point_2(2,2), Point_2(4,2), Point_2(5,0)}; insert (arr, Curve_2 (Polyline_2 (points3, points3 + 4), "C")); Point_2 points4[2] = {Point_2(0,2), Point_2(6,2)}; insert (arr, Curve_2 (Polyline_2 (points4, points4 + 2), "D")); // Print all edges that correspond to an overlapping polyline. Arrangement_2::Edge_iterator eit; for (eit = arr.edges_begin(); eit != arr.edges_end(); ++eit) { if (eit->curve().data().length() > 1) { std::cout << "[" << eit->curve() << "] " << "named: " << eit->curve().data() << std::endl; // Rename the curve associated with the edge. arr.modify_edge (eit, X_monotone_curve_2 (eit->curve(), "overlap")); } } return 0; }
void CriticalCurves::setParameters(double radius_1, double radius_2, Arrangements_2 insets_1, Arrangements_2 insets_2) { Arrangement_2_iterator inset_1 = insets_1.begin(); Arrangement_2_iterator inset_2 = insets_2.begin(); while (inset_1 != insets_1.end() && inset_2 != insets_2.end()) { Arrangement_2 arrangement; // Add the curves of the inset. for (Edge_iterator edge = inset_1->edges_begin(); edge != inset_1->edges_end(); ++edge) { insert(arrangement, edge->curve()); } // Add the critical curves of type I. for (Edge_iterator edge = inset_2->edges_begin(); edge != inset_2->edges_end(); ++edge) { if (CGAL::COLLINEAR == edge->curve().orientation()) { // Displaced a segment. Nt_traits nt_traits; Algebraic_ft factor = nt_traits.convert(Rational(radius_1) + Rational(radius_2)); Conic_point_2 source = edge->curve().source(); Conic_point_2 target = edge->curve().target(); Algebraic_ft delta_x = target.x() - source.x(); Algebraic_ft delta_y = target.y() - source.y(); Algebraic_ft length = nt_traits.sqrt(delta_x * delta_x + delta_y * delta_y); Algebraic_ft translation_x = factor * delta_y / length; Algebraic_ft translation_y = - factor * delta_x / length; Conic_point_2 point_1(source.x() + translation_x, source.y() + translation_y); Conic_point_2 point_2(target.x() + translation_x, target.y() + translation_y); Algebraic_ft a = - delta_y; Algebraic_ft b = delta_x; Algebraic_ft c = factor * length - (source.y() * target.x() - source.x() * target.y()); X_monotone_curve_2 x_monotone_curve(a, b, c, point_1, point_2); insert(arrangement, x_monotone_curve); } else { // Displaces an arc. Rational two(2); Rational four(4); Rational r = edge->curve().r(); Rational s = edge->curve().s(); Rational t = edge->curve().t(); Rational u = edge->curve().u(); Rational v = edge->curve().v(); Rational w = edge->curve().w(); Nt_traits nt_traits; Rational x_center = - u / (two * r); Rational y_center = - v / (two * r); Rat_point_2 rat_center(x_center, y_center); Conic_point_2 center(nt_traits.convert(x_center), nt_traits.convert(y_center)); Rational radius = Rational(radius_1) + two * Rational(radius_2); Algebraic_ft coefficient = nt_traits.convert(radius / Rational(radius_2)); Conic_point_2 source_1 = edge->curve().source(); Algebraic_ft x_source_2 = center.x() + coefficient * (source_1.x() - center.x()); Algebraic_ft y_source_2 = center.y() + coefficient * (source_1.y() - center.y()); Conic_point_2 source_2(x_source_2, y_source_2); Conic_point_2 target_1 = edge->curve().target(); Algebraic_ft x_target_2 = center.x() + coefficient * (target_1.x() - center.x()); Algebraic_ft y_target_2 = center.y() + coefficient * (target_1.y() - center.y()); Conic_point_2 target_2(x_target_2, y_target_2); Rat_circle_2 circle(rat_center, radius * radius); Conic_arc_2 conic_arc(circle, CGAL::COUNTERCLOCKWISE, source_2, target_2); insert(arrangement, conic_arc); } } // Add the critical curves of type II. for (Edge_iterator edge = inset_2->edges_begin(); edge != inset_2->edges_end(); ++edge) { double x = CGAL::to_double(edge->curve().source().x()); double y = CGAL::to_double(edge->curve().source().y()); double radius = radius_1 + radius_2; Rat_point_2 center(x, y); Rat_circle_2 circle(center, radius * radius); Conic_arc_2 conic_arc(circle); insert(arrangement, conic_arc); } // Remove the curves which are not include in the inset. Objects objects; Face_handle face; for (Edge_iterator edge = arrangement.edges_begin(); edge != arrangement.edges_end(); ++edge) { CGAL::zone(*inset_1, edge->curve(), std::back_inserter(objects)); for (Object_iterator object = objects.begin(); object != objects.end(); ++object) { if (assign(face, *object)) { if (face->is_unbounded()) { remove_edge(arrangement, edge); break; } } } objects.clear(); } // Print essential information on the standard input. std::cout << "Arrangement:" << std::endl; std::cout << " Number of vertices: " << arrangement.number_of_vertices() << std::endl; std::cout << " Number of edges : " << arrangement.number_of_edges() << std::endl; std::cout << " Number of face : " << arrangement.number_of_faces() << std::endl; this->critical_curves.push_back(arrangement); ++inset_1; ++inset_2; } // Commit changes. emit(criticalCurvesChanged()); return; }
int main () { // Construct an arrangement containing three RED line segments. Arrangement_2 arr; Landmarks_pl pl (arr); Segment_2 s1 (Point_2(-1, -1), Point_2(1, 3)); Segment_2 s2 (Point_2(2, 0), Point_2(3, 3)); Segment_2 s3 (Point_2(0, 3), Point_2(2, 5)); insert (arr, Colored_segment_2 (s1, RED), pl); insert (arr, Colored_segment_2 (s2, RED), pl); insert (arr, Colored_segment_2 (s3, RED), pl); // Insert three BLUE line segments. Segment_2 s4 (Point_2(-1, 3), Point_2(4, 1)); Segment_2 s5 (Point_2(-1, 0), Point_2(4, 1)); Segment_2 s6 (Point_2(-2, 1), Point_2(1, 4)); insert (arr, Colored_segment_2 (s4, BLUE), pl); insert (arr, Colored_segment_2 (s5, BLUE), pl); insert (arr, Colored_segment_2 (s6, BLUE), pl); // Go over all vertices and print just the ones corresponding to intersection // points between RED segments and BLUE segments. Note that we skip endpoints // of overlapping sections. Arrangement_2::Vertex_const_iterator vit; Segment_color color; for (vit = arr.vertices_begin(); vit != arr.vertices_end(); ++vit) { // Go over the incident halfedges of the current vertex and examine their // colors. bool has_red = false; bool has_blue = false; Arrangement_2::Halfedge_around_vertex_const_circulator eit, first; eit = first = vit->incident_halfedges(); do { // Get the color of the current half-edge. if (eit->curve().data().size() == 1) { color = eit->curve().data().front(); if (color == RED) has_red = true; else if (color == BLUE) has_blue = true; } ++eit; } while (eit != first); // Print the vertex only if incident RED and BLUE edges were found. if (has_red && has_blue) { std::cout << "Red-blue intersection at (" << vit->point() << ")" << std::endl; } } // Locate the edges that correspond to a red-blue overlap. Arrangement_2::Edge_iterator eit; for (eit = arr.edges_begin(); eit != arr.edges_end(); ++eit) { // Go over the incident edges of the current vertex and examine their // colors. bool has_red = false; bool has_blue = false; Traits_2::Data_container::const_iterator dit; for (dit = eit->curve().data().begin(); dit != eit->curve().data().end(); ++dit) { if (*dit == RED) has_red = true; else if (*dit == BLUE) has_blue = true; } // Print the edge only if it corresponds to a red-blue overlap. if (has_red && has_blue) std::cout << "Red-blue overlap at [" << eit->curve() << "]" << std::endl; } return 0; }