0% found this document useful (0 votes)
3 views

Convex Hull algorithm

Uploaded by

pavithra.r
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Convex Hull algorithm

Uploaded by

pavithra.r
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Convex Hull

A convex hull of a set of points is the smallest convex polygon that encloses all the points. It
can be visualized as the shape formed by stretching a rubber band around the outermost
points.

Properties of a Convex Hull

1. The convex hull is a subset of the given points.


2. It forms a polygon where any line segment between two points in the hull lies entirely
inside or on the boundary.
3. It includes all the extreme points (outermost points).

Algorithms to Find Convex Hull

Several algorithms can compute the convex hull, with different complexities and approaches.
Common ones include:

1. Graham's Scan (Time complexity: O(nlog⁡n)O(n \log n)O(nlogn))


2. Jarvis March (Gift Wrapping) (Time complexity: O(nh)O(nh)O(nh), where hhh is
the number of hull vertices)
3. QuickHull (Time complexity: Average O(nlog⁡n)O(n \log n)O(nlogn), Worst
O(n2)O(n^2)O(n2))
4. Divide and Conquer (Time complexity: O(nlog⁡n)O(n \log n)O(nlogn))
5. Monotone Chain (Andrew's Algorithm) (Time complexity: O(nlog⁡n)O(n \log
n)O(nlogn))

Graham's Scan Algorithm

Steps:

1. Find the Starting Point:


o Choose the point with the lowest yyy-coordinate. If there’s a tie, pick the one
with the lowest xxx-coordinate. This will be the pivot.
2. Sort Points by Polar Angle:
o Sort the remaining points based on the polar angle they make with the pivot
point (counterclockwise order).
3. Construct the Hull:
o Use a stack to maintain the vertices of the convex hull:
 Push the pivot point onto the stack.
 Iterate through the sorted points:
 Check the orientation of the last two points on the stack and the
current point.
If the orientation is clockwise, pop the last point from the stack

(it's not part of the hull).
 Push the current point onto the stack.
 Continue until all points are processed.
4. Return the Stack:
o The stack contains the vertices of the convex hull in counterclockwise order.

Example

Input Points:

P={(0,0),(1,1),(2,2),(2,0),(2,4),(3,3),(0,3)}P = \{(0, 0), (1, 1), (2, 2), (2, 0), (2, 4), (3, 3), (0,
3)\}P={(0,0),(1,1),(2,2),(2,0),(2,4),(3,3),(0,3)}

Steps:

1. Find the Starting Point:


o Lowest yyy-coordinate: (0,0)(0, 0)(0,0).
2. Sort Points by Polar Angle (relative to (0,0)(0, 0)(0,0)):
o Sorted points: (0,0),(2,0),(1,1),(2,2),(3,3),(2,4),(0,3)(0, 0), (2, 0), (1, 1), (2, 2),
(3, 3), (2, 4), (0, 3)(0,0),(2,0),(1,1),(2,2),(3,3),(2,4),(0,3).
3. Construct the Hull:
o Start with (0,0)(0, 0)(0,0) and iterate through the sorted points.
o Use the orientation test to determine clockwise, counterclockwise, or collinear
turns.
o Maintain the stack:
 Push (0,0)(0, 0)(0,0), then (2,0)(2, 0)(2,0), and so on.
 If a clockwise turn is detected, remove the last point on the stack.
o Final stack: (0,0),(2,0),(3,3),(2,4),(0,3)(0, 0), (2, 0), (3, 3), (2, 4), (0, 3)(0,0),
(2,0),(3,3),(2,4),(0,3).

Output:

The convex hull points are:

{(0,0),(2,0),(3,3),(2,4),(0,3)}\{(0, 0), (2, 0), (3, 3), (2, 4), (0, 3)\}{(0,0),(2,0),(3,3),(2,4),(0,3)}

Visualization

The convex hull forms a polygon connecting (0,0)→(2,0)→(3,3)→(2,4)→(0,3)→(0,0)(0, 0) \


to (2, 0) \to (3, 3) \to (2, 4) \to (0, 3) \to (0, 0)(0,0)→(2,0)→(3,3)→(2,4)→(0,3)→(0,0).

Applications
1. Computer Graphics:
o Shape boundary detection.
2. GIS:
o Region outlining and clustering.
3. Robotics:
o Path planning and obstacle avoidance.
4. Data Analysis:
o Finding the boundary of a dataset.

Complexity

 Sorting Points: O(nlog⁡n)O(n \log n)O(nlogn)


 Stack Operations: O(n)O(n)O(n)
 Overall: O(nlog⁡n)O(n \log n)O(nlogn) for Graham's Scan.

Other algorithms may be more efficient for specific cases, but Graham's Scan is robust and
widely used.

You might also like