G10_Graham Scan Algorithm (Convex Hulls)
G10_Graham Scan Algorithm (Convex Hulls)
(Convex Hulls)
By
Group: 10
Group Details
# Name ID
2 Problem Statement
3 Brief History
4 Terminologies
6 Pseudocode
8 Visual Representation
9 Applications
Graham Scan Algorithm - Definition
● A Convex Hull is the smallest convex polygon that completely encloses all the given
points.
● The algorithm sorts the points based on their polar angles and processes them to
Graham” in 1972.
Add the pivot and the point with the smallest polar
Step 3: Initialize the Convex Hull angle to the Convex Hull.
Steps of the Algorithm (Continued)
Step 4: Scan and Construct ● Remove the second-to-last point if a right turn
(counterclockwise) is detected.
Step 4: Scan and Construct ● Remove the second-to-last point if a right turn
(counterclockwise) is detected.
struct Point {
int x, y;
};
2. Orientation Function
The orientation function is crucial for determining the turn direction (clockwise,
counterclockwise or collinear).
int min_y = 0;
for (int i = 1; i < n; i++) {
if (points[i].y < points[min_y].y ||
(points[i].y == points[min_y].y && points[i].x < points[min_y].x)) {
min_y = i;
}
}
swap(points[0], points[min_y]);
Point pivot = points[0];
Pseudocode (Continued)
return hull; //This line will provide the final convex hull result.
Illustration 01
(with Example)
Example
Input Points:
(0, 0), (1, 1), (2, 2), (2, 0), (2, 4), (3, 3), (3, 1)
1. Pivot: (0, 0)
2. Sorted Points: (0, 0), (2, 0), (3, 1), (2, 2), (3, 3), (2, 4), (1, 1)
3. Convex Hull Construction:
● Start with (0, 0) and (2, 0).
● Process each point; remove (3, 1) as it makes a right turn.
● Final Convex Hull: (0, 0), (2, 0), (3, 3), (2, 4), (1, 1)
Special Cases
1. Collinear Points:
If multiple points are collinear, include only the endpoints of the line
segment.
2. Duplicate Points:
Ignore duplicates during preprocessing.
Visual Representation (Convex Hull)
Visual Representation - 1
Visual Representation - 2
Visual Representation - 3
Visual Representation - 4
Visual Representation - 5
Visual Representation - 6
Visual Representation - 7
Visual Representation - 8
Visual Representation - 9
Visual Representation - 10
Visual Representation - 11
Visual Representation - 12
Visual Representation - 13
Visual Representation - 14
Visual Representation - 15
Visual Representation - 16
Visual Representation (Final View)
Applications
1. Geographic Mapping:
Determining the boundary of geographical regions.
2. Pattern Recognition:
Detecting outer boundaries of objects in images.
3. Game Development:
Collision detection for objects.
4. Robotics:
Pathfinding and obstacle avoidance.
5. Data Clustering:
Outlier detection by identifying boundary points.
Do you have any questions?
THANKS
CREDITS: This presentation template was created by Slidesgo,
including icons by Flaticon, and infographics & images by Freepik