|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Comprehensive example demonstrating Aleph-w's computational geometry. More...
#include <iostream>#include <iomanip>#include <cmath>#include <chrono>#include <cstring>#include <geom_algorithms.H>#include <tpl_dynArray.H>Go to the source code of this file.
Functions | |
| void | print_header (const string &title) |
| void | print_subheader (const string &subtitle) |
| double | to_double (const Geom_Number &n) |
| Convert Geom_Number to double. | |
| void | print_point (const Point &p, const string &label="") |
| Print a point with optional label. | |
| void | print_polygon (const Polygon &poly, const string &name) |
| Print a polygon's vertices. | |
| void | print_triangle (const Triangle &t, int index) |
| Print a triangle. | |
| double | triangle_area (const Triangle &t) |
| Calculate area of a triangle using cross product. | |
| void | demo_triangulation_basic () |
| void | demo_triangulation_complex () |
| void | demo_convex_hull_cities () |
| void | demo_convex_hull_performance () |
| void | demo_geometric_primitives () |
| void | demo_coverage_area () |
| static void | usage (const char *prog) |
| int | main (int argc, char *argv[]) |
Comprehensive example demonstrating Aleph-w's computational geometry.
This example showcases fundamental geometric algorithms from geom_algorithms.H, demonstrating how to solve common problems in computational geometry. The examples use Colombian geographical locations and landmarks for real-world context.
Computational geometry deals with algorithms for solving geometric problems, such as finding convex hulls, triangulating polygons, and computing distances. These algorithms are essential in computer graphics, GIS, robotics, and more.
Problem: Decompose a simple polygon into triangles.
Algorithm: Ear-Cutting (CuttingEarsTriangulation)
Applications:
Problem: Find the smallest convex polygon containing all points.
Three algorithms are demonstrated:
Applications:
| Algorithm | Time Complexity | Best For |
|---|---|---|
| Polygon Triangulation | O(n²) | Simple polygons |
| Brute Force Hull | O(n³) | Small datasets, education |
| Gift Wrapping | O(nh) | Few hull points |
| QuickHull | O(n log n) avg | General purpose |
Examples use real Colombian locations:
The example uses:
Definition in file geom_example.C.
| void demo_convex_hull_cities | ( | ) |
Definition at line 344 of file geom_example.C.
References abs(), Aleph::DynList< T >::append(), LocateFunctions< Container, Type >::get_it(), Aleph::maps(), print_header(), print_subheader(), Aleph::HTList::size(), to_double(), and y.
Referenced by main().
| void demo_convex_hull_performance | ( | ) |
Definition at line 450 of file geom_example.C.
References Aleph::DynList< T >::append(), Aleph::maps(), print_header(), Aleph::HTList::size(), and y.
Referenced by main().
| void demo_coverage_area | ( | ) |
Definition at line 593 of file geom_example.C.
References Aleph::DynList< T >::append(), LocateFunctions< Container, Type >::get_it(), Point::get_x(), Point::get_y(), Polygon::Segment_Iterator::has_curr(), Aleph::maps(), print_header(), Aleph::HTList::size(), to_double(), and triangle_area().
Referenced by main().
| void demo_geometric_primitives | ( | ) |
Definition at line 524 of file geom_example.C.
References Triangle::contains_to(), Aleph::maps(), print_header(), print_point(), print_subheader(), Aleph::HTList::size(), to_double(), and triangle_area().
Referenced by main().
| void demo_triangulation_basic | ( | ) |
Definition at line 232 of file geom_example.C.
References Polygon::add_vertex(), Polygon::close(), cos(), LocateFunctions< Container, Type >::get_it(), Aleph::maps(), print_header(), print_polygon(), print_subheader(), print_triangle(), sin(), Aleph::HTList::size(), and triangle_area().
Referenced by main().
| void demo_triangulation_complex | ( | ) |
Definition at line 301 of file geom_example.C.
References LocateFunctions< Container, Type >::get_it(), Aleph::maps(), print_header(), print_polygon(), print_subheader(), print_triangle(), Aleph::HTList::size(), and triangle_area().
Referenced by main().
| int main | ( | int | argc, |
| char * | argv[] | ||
| ) |
Definition at line 667 of file geom_example.C.
References demo_convex_hull_cities(), demo_convex_hull_performance(), demo_coverage_area(), demo_geometric_primitives(), demo_triangulation_basic(), demo_triangulation_complex(), Aleph::maps(), and usage().
| void print_header | ( | const string & | title | ) |
Definition at line 148 of file geom_example.C.
References Aleph::maps().
| void print_point | ( | const Point & | p, |
| const string & | label = "" |
||
| ) |
Print a point with optional label.
Definition at line 173 of file geom_example.C.
References Point::get_x(), Point::get_y(), Aleph::maps(), and to_double().
Referenced by demo_geometric_primitives().
| void print_polygon | ( | const Polygon & | poly, |
| const string & | name | ||
| ) |
Print a polygon's vertices.
Definition at line 184 of file geom_example.C.
References Aleph::maps(), Polygon::size(), and to_double().
Referenced by demo_triangulation_basic(), and demo_triangulation_complex().
| void print_subheader | ( | const string & | subtitle | ) |
Definition at line 156 of file geom_example.C.
References FunctionalMethods< Container, T >::length(), and Aleph::maps().
Referenced by demo_convex_hull_cities(), demo_geometric_primitives(), demo_triangulation_basic(), and demo_triangulation_complex().
| void print_triangle | ( | const Triangle & | t, |
| int | index | ||
| ) |
Print a triangle.
Definition at line 199 of file geom_example.C.
References Triangle::get_p1(), Triangle::get_p2(), Triangle::get_p3(), Point::get_x(), Point::get_y(), Aleph::maps(), and to_double().
Referenced by demo_triangulation_basic(), and demo_triangulation_complex().
|
inline |
Convert Geom_Number to double.
Definition at line 165 of file geom_example.C.
References __gmp_expr< mpq_t, mpq_t >::get_d().
Referenced by demo_convex_hull_cities(), demo_coverage_area(), demo_geometric_primitives(), print_point(), print_polygon(), print_triangle(), and triangle_area().
| double triangle_area | ( | const Triangle & | t | ) |
Calculate area of a triangle using cross product.
Definition at line 214 of file geom_example.C.
References abs(), Triangle::get_p1(), Triangle::get_p2(), Triangle::get_p3(), Point::get_x(), Point::get_y(), Aleph::maps(), and to_double().
Referenced by demo_coverage_area(), demo_geometric_primitives(), demo_triangulation_basic(), and demo_triangulation_complex().
|
static |