Check if a circle lies inside another circle or not
Given two circles with radii and centres given. The task is to check whether the smaller circle lies inside the bigger circle or not.
Examples:
Input: x1 = 10, y1 = 8, x2 = 1, y2 = 2, r1 = 30, r2 = 10 Output: The smaller circle lies completely inside the bigger circle without touching each other at a point of circumference. Input :x1 = 7, y1 = 8;x2 = 3, y2 = 5;r1 = 30, r2 = 25 Output :The smaller circle lies completely inside the bigger circle with touching each other at a point of circumference.
Approach:
Here three cases can come,

The smaller circle lies completely inside the bigger circle without touching each other at a point of circumference.
If this case happens, the sum of the distance between the centres and smaller radius is lesser than the bigger radius, then obviously the smaller circle lies completely inside the circle, without touching the circumference.
The smaller circle lies completely inside the bigger circle with touching each other at a point of the circumference. If this case happens, the sum of the distance between the centres and smaller radius is equal to the bigger radius, then obviously the smaller circle lies completely inside the circle, with touching the circumference.
The smaller does not lies inside the bigger circle completely.If this case happens, then sum of the distance between the centers and smaller radius is greater than the bigger radius, then obviously the smaller circle does not lies completely inside the circle.
Below is the implementation of the above approach:
CPP
// C++ program to check if one circle // lies inside another circle or not. #include <bits/stdc++.h> using namespace std; void circle(int x1, int y1, int x2, int y2, int r1, int r2) { int distSq = sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2))); if (distSq + r2 == r1) cout << "The smaller circle lies completely" << " inside the bigger circle with " << "touching each other " << "at a point of circumference. " << endl; else if (distSq + r2 < r1) cout << "The smaller circle lies completely" << " inside the bigger circle without" << " touching each other " << "at a point of circumference. " << endl; else cout << "The smaller does not lies inside" << " the bigger circle completely." << endl; } // Driver code int main() { int x1 = 10, y1 = 8; int x2 = 1, y2 = 2; int r1 = 30, r2 = 10; circle(x1, y1, x2, y2, r1, r2); return 0; } |
chevron_right
filter_none
Java
// Java program to check if one circle // lies inside another circle or not. import java.io.*; class GFG { static void circle(int x1, int y1, int x2, int y2, int r1, int r2) { int distSq = (int)Math.sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2))); if (distSq + r2 == r1) { System.out.println("The smaller circle lies completely" + " inside the bigger circle with " + "touching each other " + "at a point of circumference. ") ; } else if (distSq + r2 < r1) { System.out.println("The smaller circle lies completely" + " inside the bigger circle without" + " touching each other " + "at a point of circumference.") ; } else { System.out.println("The smaller does not lies inside" + " the bigger circle completely.") ; } } // Driver code public static void main (String[] args) { int x1 = 10, y1 = 8; int x2 = 1, y2 = 2; int r1 = 30, r2 = 10; circle(x1, y1, x2, y2, r1, r2); } } // This code is contributed by ajit_00023. |
chevron_right
filter_none
Python
# Python3 program to check if one circle # lies inside another circle or not. def circle(x1, y1, x2,y2, r1, r2): distSq = (((x1 - x2)* (x1 - x2))+ ((y1 - y2)* (y1 - y2)))**(.5) if (distSq + r2 == r1): print("The smaller circle lies completely" " inside the bigger circle with " "touching each other " "at a poof circumference. ") elif (distSq + r2 < r1): print("The smaller circle lies completely" " inside the bigger circle without" " touching each other " "at a poof circumference. ") else: print("The smaller does not lies inside" " the bigger circle completely.") # Driver code x1 ,y1 = 10,8x2 ,y2 = 1, 2r1 ,r2 = 30,10circle(x1, y1, x2, y2, r1, r2) # This code is contributed by mohit kumar 29 |
chevron_right
filter_none
C#
// C# program to check if one circle // lies inside another circle or not. using System; class GFG { static void circle(int x1, int y1, int x2, int y2, int r1, int r2) { int distSq = (int)Math.Sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2))); if (distSq + r2 == r1) { Console.WriteLine("The smaller circle lies completely" + " inside the bigger circle with " + "touching each other " + "at a point of circumference. ") ; } else if (distSq + r2 < r1) { Console.WriteLine("The smaller circle lies completely" + " inside the bigger circle without" + " touching each other " + "at a point of circumference.") ; } else { Console.WriteLine("The smaller does not lies inside" + " the bigger circle completely.") ; } } // Driver code static public void Main () { int x1 = 10, y1 = 8; int x2 = 1, y2 = 2; int r1 = 30, r2 = 10; circle(x1, y1, x2, y2, r1, r2); } } // This code is contributed by AnkitRai01 |
chevron_right
filter_none
PHP
<?php // PHP program to check if one circle // lies inside another circle or not. function circle($x1, $y1, $x2, $y2, $r1, $r2) { $distSq = sqrt((($x1 - $x2) * ($x1 - $x2)) + (($y1 - $y2) * ($y1 - $y2))); if ($distSq + $r2 == $r1) echo "The smaller circle lies completely ", "inside the bigger circle with ", "touching each other ", "at a point of circumference. \n"; else if ($distSq + $r2 < $r1) echo "The smaller circle lies completely ", "inside the bigger circle without ", "touching each other ", "at a point of circumference. \n"; else echo "The smaller does not lies inside ", "the bigger circle completely. \n"; } // Driver code $x1 = 10; $y1 = 8; $x2 = 1; $y2 = 2; $r1 = 30; $r2 = 10; circle($x1, $y1, $x2, $y2, $r1, $r2); // This code is contributed by ihritik ?> |
chevron_right
filter_none
Output:
The smaller circle lies completely inside the bigger circle without touching each other at a point of circumference.
Recommended Posts:
- Check if a given circle lies completely inside the ring formed by two concentric circles
- Find if a point lies inside a Circle
- Queries on count of points lie inside a circle
- Find minimum radius such that atleast k point lie inside the circle
- How to check if a given point lies inside or outside a polygon?
- Check whether a given point lies on or inside the rectangle | Set 3
- Check if a point lies on or inside a rectangle | Set-2
- Check whether a point lies inside a sphere or not
- Check whether a given point lies inside a triangle or not
- Check whether a given point lies inside a rectangle or not
- Program to calculate area of inner circle which passes through center of outer circle and touches its circumference
- Equation of circle when three points on the circle are given
- Find area of the larger circle when radius of the smaller circle and difference in the area is given
- Check whether it is possible to join two points given on circle such that distance between them is k
- Check if a line touches or intersects a circle
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



