Given a convex hull, we need to add a given number of points to the convex hull and print the convex hull after every point addition. The points should be in anti-clockwise order after addition of every point.
Input : Convex Hull : (0, 0), (3, -1), (4, 5), (-1, 4) Point to add : (100, 100) Output : New convex hull : (-1, 4) (0, 0) (3, -1) (100, 100)
We first check whether the point is inside the given convex hull or not. If it is, then nothing has to be done we directly return the given convex hull. If the point is outside the convex hull, we find the lower and upper tangents, and then merge the point with the given convex hull to find the new convex hull, as shown in the figure.
The red outline shows the new convex hull after merging the point and the given convex hull.
To find the upper tangent, we first choose a point on the hull that is nearest to the given point. Then while the line joining the point on the convex hull and the given point crosses the convex hull, we move anti-clockwise till we get the tangent line.
The figure shows the moving of the point on the convex hull for finding the upper tangent.
Note: It is assumed here that the input of the initial convex hull is in the anti-clockwise order, otherwise we have to first sort them in anti-clockwise order then apply the following code.
(-1, 4) (0, 0) (3, -1) (100, 100)
The time complexity of the above algorithm is O(n*q), where q is the number of points to be added.
This article is contributed by Amritya Vagmi and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Deleting points from Convex Hull
- Perimeter of Convex hull for a given set of points
- Convex Hull | Set 1 (Jarvis's Algorithm or Wrapping)
- Convex Hull | Set 2 (Graham Scan)
- Quickhull Algorithm for Convex Hull
- Convex Hull using Divide and Conquer Algorithm
- Convex Hull | Monotone chain algorithm
- Check if the given point lies inside given N points of a Convex Polygon
- Number of Integral Points between Two Points
- Count of obtuse angles in a circle with 'k' equidistant points between 2 given points
- Minimum number of points to be removed to get remaining points on one side of axis
- Find the point on X-axis from given N points having least Sum of Distances from all other points
- Ways to choose three points with distance between the most distant points <= L
- Tangents between two Convex Polygons
- Find number of diagonals in n sided convex polygon
- Check whether two convex regular polygon have same center or not
- Check if given polygon is a convex polygon or not
- Check if it is possible to reach vector B by rotating vector A and adding vector C to it
- Closest Pair of Points using Divide and Conquer algorithm
- Closest Pair of Points | O(nlogn) Implementation
Improved By : chitranayal