Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tikz_missing_primitives_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{
15 pts.append(Point(-12, -8));
16 pts.append(Point(-8, 10));
17 pts.append(Point(0, -12));
18 pts.append(Point(8, 9));
19 pts.append(Point(14, -4));
20 pts.append(Point(2, 16));
21 pts.append(Point(0, 0));
22 return pts;
23}
24
26{
27 Polygon p;
28 p.add_vertex(Point(-6, -3));
29 p.add_vertex(Point(4, -3));
30 p.add_vertex(Point(2, 5));
31 p.close();
32 return p;
33}
34
36{
37 Polygon q;
38 q.add_vertex(Point(-4, -2));
39 q.add_vertex(Point(3, -2));
40 q.add_vertex(Point(0, 4));
41 q.close();
42 return q;
43}
44
46{
49 hps.append(HP(Point(0, 1), Point(0, 0))); // x >= 0
50 hps.append(HP(Point(0, 0), Point(1, 0))); // y >= 0
51 hps.append(HP(Point(8, 0), Point(8, 1))); // x <= 8
52 hps.append(HP(Point(1, 8), Point(0, 8))); // y <= 8
53 hps.append(HP(Point(8, 0), Point(0, 8))); // x + y <= 8
54 return hps;
55}
56
58{
60 segs.append(Segment(Point(-14, -8), Point(14, 10)));
61 segs.append(Segment(Point(-12, 11), Point(13, -8)));
62 segs.append(Segment(Point(-14, 2), Point(14, 2)));
63 return segs;
64}
65
66} // namespace
67
68int main(int argc, char * argv[])
69{
70 const std::string output_path =
71 argc > 1 ? argv[1] : "tikz_missing_primitives_example.tex";
72
73 std::ofstream out(output_path);
74 if (not out)
75 {
76 std::cerr << "Cannot open output file: " << output_path << '\n';
77 return 1;
78 }
79
80 Tikz_Plane delaunay_plane(180, 105, 5, 5);
81 delaunay_plane.put_cartesian_axis();
82 delaunay_plane.set_point_radius_mm(0.65);
85 Text(Point(-14, 19),
86 "Delaunay sites=" + std::to_string(dt.sites.size()) +
87 ", triangles=" + std::to_string(dt.triangles.size())),
88 make_tikz_draw_style("black"),
90
91 Tikz_Plane minkowski_plane(180, 105, 5, 5);
92 minkowski_plane.put_cartesian_axis();
96 Text(Point(-8, 10),
97 "Minkowski vertices=" + std::to_string(sum.size())),
98 make_tikz_draw_style("black"),
100
101 Tikz_Plane halfplane_plane(180, 105, 5, 5);
102 halfplane_plane.put_cartesian_axis();
106 Text(Point(-1, 10),
107 "Half-plane intersection vertices=" +
108 std::to_string(feasible.size())),
109 make_tikz_draw_style("black"),
111
112 Tikz_Plane sweep_plane(180, 105, 5, 5);
113 sweep_plane.put_cartesian_axis();
114 sweep_plane.set_point_radius_mm(0.7);
118 Text(Point(-15, 13),
119 "Line sweep intersections=" +
120 std::to_string(intersections.size())),
121 make_tikz_draw_style("black"),
123
124 out << "\\documentclass[tikz,border=8pt]{standalone}\n"
125 << "\\usepackage{tikz}\n"
126 << "\\begin{document}\n\n";
127
128 delaunay_plane.draw(out, true);
129 out << "\n\\vspace{4mm}\n\n";
130 minkowski_plane.draw(out, true);
131 out << "\n\\vspace{4mm}\n\n";
132 halfplane_plane.draw(out, true);
133 out << "\n\\vspace{4mm}\n\n";
134 sweep_plane.draw(out, true);
135 out << "\n\\end{document}\n";
136
137 std::cout << "Generated " << output_path << '\n';
138 std::cout << "Compile with: pdflatex " << output_path << '\n';
139 return 0;
140}
Simple dynamic array with automatic resizing and functional operations.
Definition tpl_array.H:139
T & append(const T &data)
Append a copy of data
Definition tpl_array.H:245
Dynamic singly linked list with functional programming support.
Definition htlist.H:1155
T & append(const T &item)
Definition htlist.H:1271
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
const size_t & size() const
Get the number of vertices.
Definition polygon.H:477
Represents a line segment between two points.
Definition point.H:827
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
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
DelaunayTriangulationBowyerWatson::Result visualize_delaunay(Tikz_Plane &plane, const DynList< Point > &points, const DelaunayTriangulationBowyerWatson &algorithm={}, const Tikz_Style &triangle_style=tikz_wire_style("blue"), const bool draw_sites=true, const Tikz_Style &site_style=tikz_points_style("black"))
Compute and insert Delaunay triangulation as triangle outlines.
Polygon visualize_half_plane_intersection(Tikz_Plane &plane, const Array< HalfPlaneIntersection::HalfPlane > &halfplanes, const HalfPlaneIntersection &algorithm={}, const Tikz_Style &boundary_style=tikz_wire_style("gray!60", true, true), const Tikz_Style &result_style=tikz_area_style("red", "red!25", 0.50))
Compute and draw bounded half-plane intersection.
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.
Array< SweepLineSegmentIntersection::Intersection > visualize_line_sweep(Tikz_Plane &plane, const Array< Segment > &segments, const SweepLineSegmentIntersection &algorithm={}, const Tikz_Style &segment_style=tikz_wire_style("blue!60"), const Tikz_Style &intersection_style=tikz_points_style("red"))
Compute and draw Bentley-Ottmann line-sweep intersections.
Tikz_Style make_tikz_draw_style(const std::string &draw_color)
Create a basic draw style with a custom color.
Definition tikzgeom.H:156
Polygon visualize_minkowski_sum(Tikz_Plane &plane, const Polygon &first, const Polygon &second, const MinkowskiSumConvex &algorithm={}, const Tikz_Style &first_style=tikz_area_style("blue", "blue!14", 0.30), const Tikz_Style &second_style=tikz_area_style("green!60!black", "green!16", 0.30), const Tikz_Style &result_style=tikz_area_style("red", "red!26", 0.60))
Compute and draw Minkowski sum of two convex polygons.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
Helpers to visualize computational-geometry algorithm results in TikZ.