OpenGenus / cosmos

World's largest Contributor driven code dataset | Used in Quark Search Engine, @OpenGenus IQ, OpenGenus Visual Project
http://internship.opengenus.org
GNU General Public License v3.0
13.56k stars 3.67k forks source link

Adding the Quickhull algorithm to find Convex Hull #6125

Open Raven1233 opened 2 years ago

Raven1233 commented 2 years ago

This is a(n):

Details:

The QuickHull algorithm is a Divide and Conquer algorithm similar to QuickSort. Let a[0…n-1] be the input array of points. Following are the steps for finding the convex hull of these points.

  1. Find the point with minimum x-coordinate lets say, min_x and similarly the point with maximum x-coordinate, max_x. Make a line joining these two points, say L. This line will divide the whole set into two parts. Take both the parts one by one and proceed further.

  2. For a part, find the point P with maximum distance from the line L. P forms a triangle with the points min_x, max_x. It is clear that the points residing inside this triangle can never be the part of convex hull.

  3. The above step divides the problem into two sub-problems (solved recursively). Now the line joining the points P and min_x and the line joining the points P and max_x are new lines and the points residing outside the triangle is the set of points.

  4. Repeat point no. 3 till there no point left with the line. Add the end points of this point to the convex hull.

Raven1233 commented 2 years ago

I have already sent the PR. Please do review it.

Raven1233 commented 2 years ago

@AdiChat Sir, I have sent the PR for this problem. Could your please review my PR?

AdiChat commented 2 years ago

@Raven1233 Sure, I will review it.