47 for (
int i = 0; i < 10; ++i)
49 double angle = M_PI / 2.0 + 2.0 * M_PI * i / 10.0;
50 double r = (i % 2 == 0) ? outer_r : inner_r;
76 cout <<
"Star: " << star_verts.size() <<
" vertices" << endl;
79 for (
size_t k = 1;
k <= 4; ++
k)
83 cout <<
" iter " <<
k <<
": " << sv.size() <<
" vertices" << endl;
89 cout <<
"L-shape: " << l_verts.size() <<
" vertices" << endl;
91 for (
size_t k = 1;
k <= 3; ++
k)
95 cout <<
" iter " <<
k <<
": " << sv.size() <<
" vertices" << endl;
99 ofstream tex(
"chaikin_smoothing_output.tex");
100 tex <<
"\\documentclass[border=5mm]{standalone}\n"
101 <<
"\\usepackage{tikz}\n"
102 <<
"\\usepackage{subcaption}\n"
103 <<
"\\begin{document}\n"
104 <<
"\\begin{figure}\n";
106 auto draw_subfig = [&](
const char * caption,
const Polygon & original,
111 tex <<
"\\begin{minipage}{0.45\\textwidth}\\centering\n";
113 tex <<
"\\captionof{subfigure}{" << caption <<
"}\n"
114 <<
"\\end{minipage}\\hfill\n";
118 draw_subfig(
"Star original", star, star);
120 draw_subfig(
"Star iter=1", star, star1);
121 tex <<
"\n\\medskip\n\n";
123 draw_subfig(
"Star iter=2", star, star2);
125 draw_subfig(
"Star iter=4", star, star4);
127 tex <<
"\n\\bigskip\n\n";
130 draw_subfig(
"L-shape original", lshape, lshape);
132 draw_subfig(
"L-shape iter=1", lshape,
l1);
133 tex <<
"\n\\medskip\n\n";
135 draw_subfig(
"L-shape iter=2", lshape,
l2);
137 draw_subfig(
"L-shape iter=3", lshape,
l3);
139 tex <<
"\\end{figure}\n"
140 <<
"\\end{document}\n";
142 cout <<
"TikZ output written to chaikin_smoothing_output.tex" << endl;
static Polygon make_L_shape()
Build an L-shaped polygon.
static Polygon smooth_polygon(const Polygon &poly, size_t iterations, const Geom_Number &ratio=Geom_Number(1, 4))
Smooth a closed polygon.
static Array< Point > extract_vertices(const Polygon &poly)
Extract vertices from a polygon into an array for indexed access.
Represents a point with rectangular coordinates in a 2D plane.
A general (irregular) 2D polygon defined by a sequence of vertices.
void add_vertex(const Point &point)
Add a vertex to the polygon.
void close()
Close the polygon.
2D TikZ canvas storing geometry objects and emitting LaTeX output.
void draw(std::ostream &output, const bool squarize=true) const
Emit a complete tikzpicture with all inserted objects.
static Polygon make_star()
Star-shaped polygon with 5 reflex vertices.
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_cos_function > > cos(const __gmp_expr< T, U > &expr)
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_sin_function > > sin(const __gmp_expr< T, U > &expr)
Main namespace for Aleph-w library functions.
void put_smoothing_result(Tikz_Plane &plane, const Polygon &original, const Polygon &smoothed, const Tikz_Style &original_style=tikz_wire_style("gray!50"), const Tikz_Style &smoothed_style=tikz_bold_wire_style("violet!80"), const bool draw_vertices=true, const Tikz_Style &vertex_style=tikz_points_style("red"))
Draw original and smoothed polygons overlaid.
Helpers to visualize computational-geometry algorithm results in TikZ.