This project implements various computational geometry algorithms, focusing on convex hulls, linear programming, Delaunay triangulation, and geometric search.
The code is organized into multiple modules, each solving specific geometry-related problems and demonstrating core computational methods.
- Incremental Algorithm (Graham Scan): Sorts points by x-coordinates and constructs the hull by adding points and removing non-hull points.
- Gift Wrapping Algorithm: Builds the hull by iteratively selecting boundary points in a clockwise direction.
- Divide and Conquer Algorithm: Divides points into subsets, recursively computes hulls for each subset, and merges them.
- QuickHull (2D and 3D): Computes the hull using the QuickHull method for both 2D and 3D points.
This module solves linear programming problems, parsing constraints from a configuration file and solving them using the scipy.optimize.linprog
function.
Utilizes Voronoi diagrams and Delaunay triangulation techniques. The triangulation's duality with the Voronoi diagram allows for visualization and efficient computation of geometric relationships.
Implements a 2D KD-tree to conduct rectangular range searches, retrieving points within specified boundaries efficiently.
.
βββ convex_hull
β βββ main.py # Main entry point for running algorithms
β βββ utils.py # Helper functions for data handling and visualization
| βββ files # Directory containing input and output of program
β βββ algorithms # Directory containing algorithm implementations
β βββ graham_scan.py
β βββ gift_wrapping.py
β βββ divide_and_conquer.py
β βββ quickhull.py
β
βββ linear
β βββ constraints.txt # Input file with problem constraints
β βββ linear.py # Solves the linear programming problem
β βββ utils.py # Helper functions for reading constraints
β
βββ delaunay
β βββ points.txt # Input file with random points for triangulation
β βββ main.py # Main file to run Delaunay triangulation
β βββ utils.py # Helper functions for reading points and visualization
β
βββ geom_search
βββ points.txt # Input file with random points
βββ result.txt # Output file with points within a defined search area
βββ main.py # Main file to run KD-tree based search
βββ kd_tree.py # KD-tree implementation
βββ utils.py # Helper functions for reading and visualizing points
To run this project, you need Python 3.x and the following packages:
scipy
(forscipy.spatial.ConvexHull
andscipy.optimize.linprog
)matplotlib
(for visualization)
Install dependencies with:
pip install -r src/requirements.txt
Navigate to the src/convex_hull/src
folder and run the main script to choose and execute any of the convex hull algorithms:
python main.py
- Incremental Algorithm (Graham Scan)
- Gift Wrapping Algorithm
- Divide and Conquer Algorithm
- QuickHull (2D and 3D)
Navigate to the src/linear
directory and and run the main script:
python main.py
Ensure constraints are specified in constraints.txt following the required format.
Navigate to the src/delaunay
directory and and run the main script:
python main.py
Navigate to the src/geom_search
directory and and run the main script:
python main.py
- Convex Hull Algorithms: Outputs are saved in the
files/output
directory. Visualization is available for each step except for the QuickHull algorithm. - Linear Programming: Displays the optimal solution to the objective function.
- Delaunay Triangulation and Voronoi Diagram: Visualization of Delaunay triangulation and Voronoi diagrams for the generated points.
- Geometric Search: Highlights points within the defined rectangular boundary and saves results to
result.txt
.
- Convex Hull Algorithms: Complexity varies by algorithm, ranging from (O(n \log n)) for the Graham Scan and Divide and Conquer algorithms, to (O(nh)) for Gift Wrapping, where (h) is the number of hull vertices.
- Delaunay Triangulation: Has a time complexity of (O(n \log n)), where (n) is the number of points.
- KD-Tree Range Search: Constructing the KD-tree requires (O(n \log n)), and searching takes (O(n + k)), where (k) is the number of reported points.