Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tikz_convex_hull_example.cc
Go to the documentation of this file.
1#include <fstream>
2#include <iostream>
3#include <string>
4
6
7using namespace Aleph;
8
9int main(int argc, char * argv[])
10{
11 const std::string output_path =
12 argc > 1 ? argv[1] : "tikz_convex_hull_example.tex";
13
14 std::ofstream out(output_path);
15 if (not out)
16 {
17 std::cerr << "Cannot open output file: " << output_path << '\n';
18 return 1;
19 }
20
22 pts.append(Point(-28, -8));
23 pts.append(Point(-24, 16));
24 pts.append(Point(-19, 7));
25 pts.append(Point(-15, -14));
26 pts.append(Point(-10, 10));
27 pts.append(Point(-8, -3));
28 pts.append(Point(-3, 17));
29 pts.append(Point(2, 4));
30 pts.append(Point(6, -13));
31 pts.append(Point(11, 12));
32 pts.append(Point(17, -4));
33 pts.append(Point(20, 14));
34 pts.append(Point(24, -10));
35 pts.append(Point(26, 5));
36
37 Tikz_Plane plane(180, 110, 6, 6);
38 plane.put_cartesian_axis();
39 plane.set_point_radius_mm(0.9);
40
43 hull_style.thick = true;
45
48 plane, pts, hull_algo,
52 true);
53
54 put_in_plane(plane, Text(Point(-26, 20), "Convex Hull (Andrew)"),
56 put_in_plane(plane, Text(Point(11, -16), "n = 14, h = " + std::to_string(hull.size())),
58
59 out << "\\documentclass[tikz,border=8pt]{standalone}\n"
60 << "\\usepackage{tikz}\n"
61 << "\\begin{document}\n\n";
62 plane.draw(out, true);
63 out << "\n\\end{document}\n";
64
65 std::cout << "Generated " << output_path << '\n'
66 << "Compile with: pdflatex " << output_path << '\n';
67
68 return 0;
69}
70
Andrew's monotonic chain convex hull algorithm.
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
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
static constexpr int Layer_Default
Definition tikzgeom.H:187
static constexpr int Layer_Foreground
Definition tikzgeom.H:188
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
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
Tikz_Style tikz_wire_style(const std::string &color="black", const bool dashed=false, const bool with_arrow=false)
Creates a style optimized for wireframe segments and polygons.
Polygon visualize_convex_hull(Tikz_Plane &plane, const DynList< Point > &points, const HullAlgorithm &hull_algorithm, const Tikz_Style &point_style=tikz_points_style("black", 0.6), const Tikz_Style &hull_style=tikz_wire_style("red"), const Tikz_Style &hull_vertex_style=tikz_points_style("red"), const int point_layer=Tikz_Plane::Layer_Default, const int hull_layer=Tikz_Plane::Layer_Foreground, const bool draw_hull_vertices=true)
Runs a convex hull algorithm and visualizes the result.
Tikz_Style tikz_points_style(const std::string &color="black", const double opacity=-1.0)
Creates a style optimized for point clouds.
Style descriptor for TikZ primitives.
Definition tikzgeom.H:86
Helpers to visualize computational-geometry algorithm results in TikZ.