Sweep Line Algorithm for Convex Hull in C #1602
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
issue resolved :#1562
Pull Request: Sweep Line Algorithm for Convex Hull in C
Description
This PR introduces a C implementation of the Sweep Line Algorithm to compute the convex hull for a set of 2D points. The convex hull is a minimal convex boundary that can enclose all given points. This sweep line approach enables efficient computation by processing points in sorted order and maintaining the hull dynamically, making it well-suited for large sets of points.
Features Implemented
Files Added
sweep_line_convex_hull.c
: Contains the main C code implementing the sweep line approach for convex hull.README.md
: Documentation covering the algorithm, usage, and example scenarios.Code Overview
Point
struct to storex
andy
coordinates.compare
: Helper function to sort points by x and y coordinates.cross_product
: Calculates the cross product of three points to determine left or right turns.sweep_line_convex_hull
: Computes the convex hull using the sweep line method.sweep_line_convex_hull
to calculate and print the vertices of the convex hull.Example
Consider the input points:
Expected output (convex hull vertices in counter-clockwise order):
Testing
The code has been tested with:
Checklist
README.md
.Additional Notes
The Sweep Line Algorithm provides a foundation for computational geometry tasks that require efficient hull calculations. This PR supports integer coordinates; future extensions could add floating-point support or graphical visualizations.