Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tikz_polygons_example.cc
Go to the documentation of this file.
1#include <fstream>
2#include <iostream>
3#include <string>
4
5#include <tikzgeom.H>
6
7using namespace Aleph;
8
9namespace
10{
11
13{
14 Polygon poly;
15 poly.add_vertex(Point(-40, -20));
16 poly.add_vertex(Point(-12, -26));
17 poly.add_vertex(Point(8, -6));
18 poly.add_vertex(Point(-4, 20));
19 poly.add_vertex(Point(-34, 16));
20 poly.close();
21 return poly;
22}
23
25{
26 Polygon poly;
27 poly.add_vertex(Point(18, -20));
28 poly.add_vertex(Point(58, -20));
29 poly.add_vertex(Point(62, 2));
30 poly.add_vertex(Point(41, -4));
31 poly.add_vertex(Point(30, 16));
32 poly.add_vertex(Point(16, 6));
33 poly.close();
34 return poly;
35}
36
37void add_polygon_vertices(Tikz_Plane & plane, const Polygon & poly)
38{
39 for (Polygon::Vertex_Iterator it(poly); it.has_curr(); it.next_ne())
40 put_in_plane(plane, it.get_current_vertex().to_point());
41}
42
44{
45 for (size_t i = 0; i < poly.size(); ++i)
46 put_in_plane(plane, poly.get_vertex(i));
47}
48
49} // namespace
50
51int main(int argc, char * argv[])
52{
53 const std::string output_path =
54 argc > 1 ? argv[1] : "tikz_polygons_example.tex";
55
56 std::ofstream out(output_path);
57 if (not out)
58 {
59 std::cerr << "Cannot open output file: " << output_path << '\n';
60 return 1;
61 }
62
63 Tikz_Plane plane(190, 120, 5, 5);
64 plane.put_cartesian_axis();
65 plane.set_point_radius_mm(0.9);
66
69 const Regular_Polygon regular(Point(96, 6), 17.0, 7, 0.2);
70
71 put_in_plane(plane, convex);
72 put_in_plane(plane, concave);
73 put_in_plane(plane, regular);
74
75 add_polygon_vertices(plane, convex);
76 add_polygon_vertices(plane, concave);
78
79 put_in_plane(plane, Text(Point(-24, 27), "Convexo"));
80 put_in_plane(plane, Text(Point(33, 24), "Concavo"));
81 put_in_plane(plane, Text(Point(96, 30), "Regular (7 lados)"));
82
83 out << "\\documentclass[tikz,border=8pt]{standalone}\n"
84 << "\\usepackage{tikz}\n"
85 << "\\begin{document}\n\n";
86
87 plane.draw(out, true);
88
89 out << "\n\\end{document}\n";
90
91 std::cout << "Generated " << output_path << '\n'
92 << "Compile with: pdflatex " << output_path << '\n';
93
94 return 0;
95}
96
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
A regular polygon defined by center, side length, and vertex count.
Definition polygon.H:1132
Point get_vertex(const size_t &i) const
Get the i-th vertex of the polygon.
Definition polygon.H:1197
const size_t & size() const
Get the number of vertices.
Definition polygon.H:1178
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
void add_polygon_vertices(SvgScene &scene, const ::Polygon &poly, const bool as_highlight=false)
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
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.
Iterator over the vertices of a polygon.
Definition polygon.H:489
TikZ/LaTeX geometric drawing utilities.