Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
geom_example.C File Reference

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>
Include dependency graph for geom_example.C:

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[])
 

Detailed Description

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 Overview

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.

Algorithms Demonstrated

1. Polygon Triangulation

Problem: Decompose a simple polygon into triangles.

Algorithm: Ear-Cutting (CuttingEarsTriangulation)

  • An "ear" is a triangle formed by three consecutive vertices
  • Repeatedly "cut off" ears until polygon is fully triangulated
  • Time: O(n²) worst case, O(n) for convex polygons
  • Space: O(n)

Applications:

  • Computer graphics: Rendering polygons
  • Mesh generation: Finite element analysis
  • Game development: Collision detection
  • GIS: Polygon decomposition

2. Convex Hull Algorithms

Problem: Find the smallest convex polygon containing all points.

Three algorithms are demonstrated:

BruteForceConvexHull

  • Check all possible edges
  • Time: O(n³)
  • Use: Educational, small datasets

GiftWrappingConvexHull (Jarvis March)

  • Start with leftmost point, "wrap" around points
  • Time: O(nh) where h = number of hull points
  • Use: Output-sensitive, good when h is small

QuickHull

  • Divide and conquer approach
  • Time: O(n log n) average, O(n²) worst case
  • Use: General purpose, most practical

Applications:

  • Collision detection: Bounding shapes
  • Pattern recognition: Shape analysis
  • Computer vision: Object detection
  • Robotics: Path planning

Complexity Comparison

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

Colombian Geography Theme

Examples use real Colombian locations:

  • Cities: Bogotá, Medellín, Cali, Barranquilla
  • Landmarks: Mountains, rivers, regions
  • Makes examples more relatable and interesting

Geometric Data Structures

The example uses:

  • Point: 2D coordinates (x, y)
  • Polygon: Ordered list of points
  • PointSet: Collection of points for hull computation

Usage

# Run all geometric algorithm demos
./geom_example
# Run specific algorithm
./geom_example -s triangulation
./geom_example -s convexhull
See also
geom_algorithms.H Geometric algorithm implementations
Author
Leandro Rabindranath León

Definition in file geom_example.C.

Function Documentation

◆ demo_convex_hull_cities()

◆ demo_convex_hull_performance()

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().

◆ demo_coverage_area()

◆ demo_geometric_primitives()

void demo_geometric_primitives ( )

◆ demo_triangulation_basic()

◆ demo_triangulation_complex()

◆ main()

◆ print_header()

void print_header ( const string &  title)

Definition at line 148 of file geom_example.C.

References Aleph::maps().

◆ print_point()

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().

◆ print_polygon()

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().

◆ print_subheader()

void print_subheader ( const string &  subtitle)

◆ print_triangle()

void print_triangle ( const Triangle t,
int  index 
)

◆ to_double()

double to_double ( const Geom_Number n)
inline

◆ triangle_area()

double triangle_area ( const Triangle t)

◆ usage()

static void usage ( const char *  prog)
static

Definition at line 661 of file geom_example.C.

References Aleph::maps().

Referenced by main().