https://github.com/helyousfi/convex-hull-algorithm
https://github.com/helyousfi/convex-hull-algorithm
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/helyousfi/convex-hull-algorithm
- Owner: helyousfi
- Created: 2024-06-10T19:38:22.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-06-13T20:45:45.000Z (over 1 year ago)
- Last Synced: 2025-02-26T20:37:18.826Z (7 months ago)
- Language: C++
- Size: 6.73 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Graham Scan Algorithm Pseudo Code
## Introduction
The Graham Scan algorithm is used to find the convex hull of a set of points in a 2D plane. The convex hull is the smallest polygon that can enclose all the given points.## Pseudo Code
### Function Definitions
#### Function: `GrahamScan(points)`
```plaintext
Input: A list of points `points` in the plane
Output: A list of points representing the vertices of the convex hull in counter-clockwise order1. Find the point with the lowest y-coordinate, break ties by x-coordinate. Call this point P0.
2. Sort the remaining points based on the polar angle with P0, ties are broken by distance to P0.
3. Initialize an empty stack S and push P0 onto S.
4. Push the first two points from the sorted list onto S.
5. For each point p in the sorted list starting from the third point:
a. While the turn formed by the top two points of S and p makes a non-left turn (not counter-clockwise):
i. Pop the top point from S.
b. Push p onto S.
6. The stack S contains the vertices of the convex hull in counter-clockwise order.To compile the project:
1. Open your terminal.
2. Type the following commands:```bash
mkdir build
cd build
cmake ..
cmake --build .```