Check whether given circle resides in boundary maintained by two other circles
Given outer circle radius R and inner circle radius r, making circles from the same center and forming the boundary between them. Now, given X and Y coordinates which denote the center of the new circle to be formed with radius rad, your task is to check whether the circle with coordinates X and Y as the center can fit in the boundary of circles formed or not.
Input: R = 8, r = 4, x = 5, y = 3, rad = 1
Input: R =9, r = 4, x = 5, y = 3, rad = 1
Input : R = 8, r = 4, x = 5, y = 3, rad = 3.
Output: Doesn’t Fit
Approach: The idea is to calculate the distance between the center (0, 0) and the coordinates of the circle to be checked.
- distance + radius (of the circle to be checked) is less than or equal to Outer Radius and
- distance – radius (of the circle to be checked) is greater than or equal to Radius Inner circle,
- It will fit
Below is the implementation of the above approach:
Time Complexity: O(log n) since using inbuilt sqrt and pow function
Auxiliary Space: O(1)
This article is contributed by Aarti_Rathi and Rohit Thapliyal. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.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.
Please Login to comment...