

- 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
Find if a point lies inside a Circle in C++
Suppose, one circle is given (the center coordinate and radius), another point is also given. We have to find whether the point is inside the circle or not. To solve it, we have to find the distance of the given point from circle center. If that distance is less or equal to the radius, then that is inside the circle, otherwise not.
Example
#include <iostream> #include <cmath> using namespace std; bool isInsideCircle(int cx, int cy, int r, int x, int y) { int dist = (x - cx) * (x - cx) + (y - cy) * (y - cy); if ( dist <= r * r) return true; else return false; } int main() { int x = 4, y = 4, cx = 1, cy = 1, rad = 6; if(isInsideCircle(cx, cy, rad, x, y)){ cout <<"Inside Circle"; } else { cout <<"Outside Circle"; } }
Output
Inside Circle
- Related Questions & Answers
- Check if a given point lies inside a Polygon
- Check if a circle lies inside another circle or not in C++
- Check if a point lies on or inside a rectangle in Python
- Check whether a given point lies inside a Triangle
- 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 given circle lies completely inside the ring formed by two concentric circles in C++
- Find minimum radius such that atleast k point lie inside the circle in C++
- Find intersection point of lines inside a section in C++
- Plot a circle inside a rectangle in Matplotlib
- Place text inside a circle in Matplotlib
- Generate Random Point in a Circle in C++
- Check if a point is inside, outside or on the ellipse in C++
- Check if a point is inside, outside or on the parabola in C++
- How to plot a rectangle inside a circle in Matplotlib?
- Check whether the point (x, y) lies on a given line in Python
Advertisements