Aleph-w
7.10.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
7
using namespace
Aleph
;
8
9
namespace
10
{
11
12
Polygon
make_convex_for_calipers()
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
24
Polygon
make_visibility_room()
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
41
int
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
57
const
Polygon
convex = make_convex_for_calipers();
58
const
auto
rc = scene.
visualize_rotating_calipers
(convex);
59
60
const
Polygon
room = make_visibility_room();
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"
),
68
Tikz_Plane::Layer_Overlay
);
69
70
scene.
add
(
Text
(
Point
(-15, 21),
71
"Visibility polygon vertices="
+ std::to_string(vis.
size
())),
72
make_tikz_draw_style
(
"black"
),
73
Tikz_Plane::Layer_Overlay
);
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
}
main
int main()
Definition
bench_gol_1024.cc:57
out
size_t size_t int32_t * out
Definition
ca-c-api.h:120
Aleph::Point
Represents a point with rectangular coordinates in a 2D plane.
Definition
point.H:221
Aleph::Polygon
A general (irregular) 2D polygon defined by a sequence of vertices.
Definition
polygon.H:247
Aleph::Polygon::add_vertex
void add_vertex(const Point &point)
Add a vertex to the polygon.
Definition
polygon.H:686
Aleph::Polygon::close
void close()
Close the polygon.
Definition
polygon.H:851
Aleph::Polygon::size
const size_t & size() const
Get the number of vertices.
Definition
polygon.H:486
Aleph::Text
Represents a text string positioned at a 2D point.
Definition
point.H:2817
Aleph::Tikz_Plane::Layer_Overlay
static constexpr int Layer_Overlay
Definition
tikzgeom.H:205
Aleph::Tikz_Scene
High-level scene wrapper to compose objects and algorithm visualizations.
Definition
tikzgeom_scene.H:97
Aleph::Tikz_Scene::visualize_rotating_calipers
auto visualize_rotating_calipers(Args &&... args)
Definition
tikzgeom_scene.H:533
Aleph::Tikz_Scene::draw_standalone
void draw_standalone(std::ostream &output, const Tikz_Standalone_Document_Options &options={}) const
Definition
tikzgeom_scene.H:650
Aleph::Tikz_Scene::put_cartesian_axis
Tikz_Scene & put_cartesian_axis()
Definition
tikzgeom_scene.H:296
Aleph::Tikz_Scene::visualize_visibility_polygon
auto visualize_visibility_polygon(Args &&... args)
Definition
tikzgeom_scene.H:561
Aleph::Tikz_Scene::add
Tikz_Scene & add(const Geom &object)
Definition
tikzgeom_scene.H:379
Aleph::Tikz_Scene::set_point_radius_mm
Tikz_Scene & set_point_radius_mm(const double radius_mm)
Definition
tikzgeom_scene.H:340
Aleph
Main namespace for Aleph-w library functions.
Definition
Adaptive_Huffman.H:61
Aleph::geom_number_to_double
double geom_number_to_double(const Geom_Number &n)
Converts a Geom_Number to its double precision representation.
Definition
point.H:120
Aleph::make_tikz_draw_style
Tikz_Style make_tikz_draw_style(const std::string &draw_color)
Create a basic draw style with a custom color.
Definition
tikzgeom.H:172
tikzgeom_scene.H
High-level scene management for TikZ geometry visualization.
Examples
tikz_visibility_calipers_example.cc
Generated by
1.9.8