

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if a circle lies inside another circle or not in C++
Suppose we have two circles (center points, and the radius values), we have to check one circle is fit inside another circle or not. There are three possible causes.
The smaller circle lies completely inside the bigger one, without touching each other. In this case, the sum of the distance between the centers, and the smaller radius, is lesser than a bigger radius. So the smaller one will be inside the bigger one.
The second case is the smaller circle is inside the bigger ones, but also touches the circumference of the bigger circle.
The third case is, some part of the smaller circle is inside the bigger one.
To solve this, we have to find the distance between two centers, then using the distance and the radius values, we will determine those cases.
Example
#include <iostream> #include <cmath> using namespace std; void isCircleInside(int x_big, int y_big, int x_small, int y_small, int r_big, int r_small) { int distSq = sqrt(((x_big - x_small) * (x_big - x_small)) + ((y_big - y_small) * (y_big - y_small))); if (distSq + r_small == r_big) cout << "Inside the bigger circle, touching circimferene" << endl; else if (distSq + r_small < r_big) cout << "Completely inside the bigger circle" << endl; else cout << "Not inside the bigger circle" << endl; } int main() { int x1 = 10, y1 = 8; int x2 = 1, y2 = 2; int r1 = 30, r2 = 10; isCircleInside(x1, y1, x2, y2, r1, r2); }
Output
Completely inside the bigger circle
- Related Questions & Answers
- Find if a point lies inside a Circle in C++
- Check if a given circle lies completely inside the ring formed by two concentric circles in C++
- C++ Program to Check if a Point d lies inside or outside a circle defined by Points a, b, c in a Plane
- Check if a point lies on or inside a rectangle in Python
- Check if a line touches or intersects a circle in C++
- Check if a given point lies inside a Polygon
- Place text inside a circle in Matplotlib
- Plot a circle inside a rectangle in Matplotlib
- Draw a circle using OpenCV function circle()
- Check whether a given point lies inside a Triangle
- How to plot a rectangle inside a circle in Matplotlib?
- Queries on count of points lie inside a circle in C++
- Queries to check if it is possible to join boxes in a circle in C++
- How can I display an image inside SVG circle in HTML5?
- Circle Sort in C++