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 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.
- Closest Pair of Points using Divide and Conquer algorithm
- Convex Hull | Set 1 (Jarvis's Algorithm or Wrapping)
- Convex Hull | Set 2 (Graham Scan)
- Closest Pair of Points | O(nlogn) Implementation
- Find Simple Closed Path for a given set of points
- Orientation of 3 ordered points
- Count Integral points inside a Triangle
- Number of Integral Points between Two Points
- Non-crossing lines to connect points in a circle
- Count maximum points on same line
- Circle and Lattice Points
- Queries on count of points lie inside a circle
- Quickhull Algorithm for Convex Hull
- Minimum lines to cover all points
- How to check if given four points form a square