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.
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 email@example.com. 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.
- Deleting points from Convex Hull
- Perimeter of Convex hull for a given set of points
- Quickhull Algorithm for Convex Hull
- Convex Hull | Set 2 (Graham Scan)
- Convex Hull using Divide and Conquer Algorithm
- Convex Hull | Set 1 (Jarvis's Algorithm or Wrapping)
- Convex Hull | Monotone chain algorithm
- Tangents between two Convex Polygons
- Find number of diagonals in n sided convex polygon
- Minimum number of points to be removed to get remaining points on one side of axis
- Count of obtuse angles in a circle with 'k' equidistant points between 2 given points
- Ways to choose three points with distance between the most distant points <= L
- Number of Integral Points between Two Points
- Circle and Lattice Points
- Number of quadrilaterals possible from the given points