![]() |
VOOZH | about |
There are two circles A and B with their centres C1(x1, y1) and C2(x2, y2) and radius R1 and R2. The task is to check both circles A and B touch each other or not.
Examples :
Input : C1 = (3, 4)
C2 = (14, 18)
R1 = 5, R2 = 8
Output : Circles do not touch each other.Input : C1 = (2, 3)
C2 = (15, 28)
R1 = 12, R2 = 10
Output : Circles intersect with each other.Input : C1 = (-10, 8)
C2 = (14, -24)
R1 = 30, R2 = 10
Approach:
Distance between centres C1 and C2 is calculated as
C1C2 = sqrt((x1 - x2)2 + (y1 - y2)2).
There are three conditions that arise.
Below is the implementation of the above approach:
Circle touch to each other
Time Complexity: O(log(n)) because using inbuilt sqrt function
Auxiliary Space: O(1)
This article is contributed by Aarti_Rathi and Dharmendra kumar.