Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tikz_intersection_example.cc
Go to the documentation of this file.
1#include <fstream>
2#include <iostream>
3#include <string>
4
6
7using namespace Aleph;
8
9namespace
10{
11
13{
14 Polygon p;
15 p.add_vertex(Point(-48, -16));
16 p.add_vertex(Point(-14, -22));
17 p.add_vertex(Point(-3, 8));
18 p.add_vertex(Point(-30, 22));
19 p.close();
20 return p;
21}
22
24{
25 Polygon p;
26 p.add_vertex(Point(-34, -24));
27 p.add_vertex(Point(-2, -5));
28 p.add_vertex(Point(-14, 24));
29 p.add_vertex(Point(-43, 8));
30 p.close();
31 return p;
32}
33
35{
36 Polygon p;
37 p.add_vertex(Point(12, -18));
38 p.add_vertex(Point(54, -18));
39 p.add_vertex(Point(58, 8));
40 p.add_vertex(Point(42, 2));
41 p.add_vertex(Point(28, 20));
42 p.add_vertex(Point(10, 10));
43 p.close();
44 return p;
45}
46
48{
49 Polygon p;
50 p.add_vertex(Point(24, -26));
51 p.add_vertex(Point(62, -8));
52 p.add_vertex(Point(56, 26));
53 p.add_vertex(Point(32, 16));
54 p.add_vertex(Point(18, 26));
55 p.add_vertex(Point(8, -4));
56 p.close();
57 return p;
58}
59
60} // namespace
61
62int main(int argc, char * argv[])
63{
64 const std::string output_path =
65 argc > 1 ? argv[1] : "tikz_intersection_example.tex";
66
67 std::ofstream out(output_path);
68 if (not out)
69 {
70 std::cerr << "Cannot open output file: " << output_path << '\n';
71 return 1;
72 }
73
74 Tikz_Plane plane(210, 120, 6, 6);
75 plane.put_cartesian_axis();
76 plane.set_point_radius_mm(0.8);
77
82
83 // Left: convex-convex exact intersection.
85 put_in_plane(plane, Text(Point(-46, 28), "Convex Intersection"),
87
88 // Right: boolean intersection for general simple polygons.
90 BooleanPolygonOperations::Op::INTERSECTION);
91 put_in_plane(plane, Text(Point(14, 31), "Boolean Intersection"),
93
94 out << "\\documentclass[tikz,border=8pt]{standalone}\n"
95 << "\\usepackage{tikz}\n"
96 << "\\begin{document}\n\n";
97 plane.draw(out, true);
98 out << "\n\\end{document}\n";
99
100 std::cout << "Generated " << output_path << '\n'
101 << "Compile with: pdflatex " << output_path << '\n';
102
103 return 0;
104}
105
Represents a point with rectangular coordinates in a 2D plane.
Definition point.H:229
A general (irregular) 2D polygon defined by a sequence of vertices.
Definition polygon.H:246
void add_vertex(const Point &point)
Add a vertex to the polygon.
Definition polygon.H:677
void close()
Close the polygon.
Definition polygon.H:840
Represents a text string positioned at a 2D point.
Definition point.H:2739
2D TikZ canvas storing geometry objects and emitting LaTeX output.
Definition tikzgeom.H:184
void draw(std::ostream &output, const bool squarize=true) const
Emit a complete tikzpicture with all inserted objects.
Definition tikzgeom.H:1383
void put_cartesian_axis()
Enable Cartesian axes drawing (only when 0 lies in range).
Definition tikzgeom.H:1291
void set_point_radius_mm(const double &radius_mm)
Configure point marker radius.
Definition tikzgeom.H:1275
static constexpr int Layer_Overlay
Definition tikzgeom.H:189
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
void put_in_plane(Tikz_Plane &plane, const Geom &geom_obj)
Insert any supported geometry type in a Tikz_Plane.
Definition tikzgeom.H:1456
Polygon visualize_convex_intersection(Tikz_Plane &plane, const Polygon &subject, const Polygon &clip, const ConvexPolygonIntersectionBasic &intersection_algorithm={}, const Tikz_Style &subject_style=tikz_area_style("blue", "blue!15", 0.45), const Tikz_Style &clip_style=tikz_area_style("orange", "orange!20", 0.45), const Tikz_Style &result_style=tikz_area_style("red", "red!30", 0.60), const int input_layer=Tikz_Plane::Layer_Default, const int result_layer=Tikz_Plane::Layer_Foreground)
Visualizes the intersection of two convex polygons.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
Tikz_Style make_tikz_draw_style(const std::string &draw_color)
Create a basic draw style with a custom color.
Definition tikzgeom.H:156
Array< Polygon > visualize_boolean_operation(Tikz_Plane &plane, const Polygon &a, const Polygon &b, const BooleanPolygonOperations::Op op, const BooleanPolygonOperations &bop={}, const Tikz_Style &a_style=tikz_area_style("blue", "blue!15", 0.35), const Tikz_Style &b_style=tikz_area_style("green!60!black", "green!20", 0.35), const Tikz_Style &result_style=tikz_area_style("red", "red!35", 0.65), const int input_layer=Tikz_Plane::Layer_Default, const int result_layer=Tikz_Plane::Layer_Foreground)
Visualizes a boolean operation (union, intersection, difference) on two polygons.
Helpers to visualize computational-geometry algorithm results in TikZ.