Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tikz_visibility_calipers_example.cc
Go to the documentation of this file.
1#include <fstream>
2#include <iostream>
3#include <string>
4
5#include <tikzgeom_scene.H>
6
7using namespace Aleph;
8
9namespace
10{
11
13{
14 Polygon p;
15 p.add_vertex(Point(-12, -6));
16 p.add_vertex(Point(12, -8));
17 p.add_vertex(Point(17, 3));
18 p.add_vertex(Point(6, 14));
19 p.add_vertex(Point(-10, 11));
20 p.close();
21 return p;
22}
23
25{
26 Polygon p;
27 p.add_vertex(Point(0, 0));
28 p.add_vertex(Point(22, 0));
29 p.add_vertex(Point(22, 20));
30 p.add_vertex(Point(12, 20));
31 p.add_vertex(Point(12, 9));
32 p.add_vertex(Point(8, 9));
33 p.add_vertex(Point(8, 20));
34 p.add_vertex(Point(0, 20));
35 p.close();
36 return p;
37}
38
39} // namespace
40
41int main(int argc, char * argv[])
42{
43 const std::string output_path =
44 argc > 1 ? argv[1] : "tikz_visibility_calipers_example.tex";
45
46 std::ofstream out(output_path);
47 if (not out)
48 {
49 std::cerr << "Cannot open output file: " << output_path << '\n';
50 return 1;
51 }
52
53 Tikz_Scene scene(220, 120, 5, 5, true);
54 scene.put_cartesian_axis();
55 scene.set_point_radius_mm(0.7);
56
58 const auto rc = scene.visualize_rotating_calipers(convex);
59
61 const Point query(3, 17);
62 const Polygon vis = scene.visualize_visibility_polygon(room, query);
63
64 scene.add(Text(Point(-15, 24),
65 "Rotating calipers: diameter^2=" +
66 std::to_string(geom_number_to_double(rc.diameter.distance_squared))),
67 make_tikz_draw_style("black"),
69
70 scene.add(Text(Point(-15, 21),
71 "Visibility polygon vertices=" + std::to_string(vis.size())),
72 make_tikz_draw_style("black"),
74
75 scene.draw_standalone(out);
76
77 std::cout << "Generated " << output_path << '\n';
78 std::cout << "Compile with: pdflatex " << output_path << '\n';
79 return 0;
80}
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
static constexpr int Layer_Overlay
Definition tikzgeom.H:189
High-level scene wrapper to compose objects and algorithm visualizations.
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
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.
double geom_number_to_double(const Geom_Number &n)
Converts a Geom_Number to its double precision representation.
Definition point.H:122
Tikz_Style make_tikz_draw_style(const std::string &draw_color)
Create a basic draw style with a custom color.
Definition tikzgeom.H:156