- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Finding Quadrant of a Coordinate with respect to a Circle in C++
We have one circle (center coordinate and radius), we have to find the quadrant of another given point (x, y) lies with respect to the center of the circle, if this is present in the circle, print quadrant, otherwise print error as the point is present outside.
Suppose the center of the circle is (h, k), the coordinate of the point is (x, y). We know that the equation of the circle is −
(๐ฅ−โ)2+(๐ฆ−๐)2+๐2=0
Now there are few conditions, based on which we can decide the result.
๐๐ (๐ฅ−โ)2+(๐ฆ−๐)2> ๐, ๐กโ๐๐ ๐กโ๐ ๐๐๐๐๐ก ๐๐ ๐๐ข๐ก๐ ๐๐๐ ๐กโ๐ ๐๐๐๐๐๐
๐๐ (๐ฅ−โ)2+(๐ฆ−๐)2= 0, ๐กโ๐๐ ๐กโ๐ ๐๐๐๐๐ก ๐๐ ๐๐ ๐กโ๐ ๐๐๐๐๐๐
๐๐ (๐ฅ−โ)2+(๐ฆ−๐)2< ๐, ๐กโ๐๐ ๐กโ๐ ๐๐๐๐๐ก ๐๐ ๐๐๐ ๐๐๐ ๐กโ๐ ๐๐๐๐๐๐
Example
#include<iostream> #include<cmath> using namespace std; int getQuadrant(int h, int k, int rad, int x, int y) { if (x == h && y == k) return 0; int val = pow((x - h), 2) + pow((y - k), 2); if (val > pow(rad, 2)) return -1; if (x > h && y >= k) return 1; if (x <= h && y > k) return 2; if (x < h && y <= k) return 3; if (x >= h && y < k) return 4; } int main() { int h = 0, k = 3; int rad = 2; int x = 1, y = 4; int ans = getQuadrant(h, k, rad, x, y); if (ans == -1) cout << "Point is Outside of the circle" << endl; else if (ans == 0) cout << "Present at the center" << endl; else cout << ans << " Quadrant" << endl; }
Output
1 Quadrant
- Related Articles
- In the below figure, ( O A C B ) is a quadrant of a circle with centre ( O ) and radius ( 3.5 mathrm{~cm} ). If ( O D=2 mathrm{~cm} ), find the area of the quadrant ( O A C B )."
- Find the area of a quadrant of a circle whose circumference is 22 cm.
- In the figure, OACB is a quadrant of a circle with centre O and radius 3.5 cm. If $OD = 2 cm$, find the area of the (i) quadrant OACB.(ii) shaded region."
- 2A+B+C ----->+E;It is the first-order reaction with respect to A, A, second order with respect to B and zero-order with respect to C. Give the differential rate equation for the reaction.
- Check if possible to move from given coordinate to desired coordinate in C++
- The circumference of a circle is $22 cm$. Calculate the area of its quadrant $( in cm^{2})$.
- State Snell's law of refraction of light. Write an expression to relate refractive index of a medium with speed to light in vacuum.The refractive index of a medium 'a' with respect to medium 'b' is 2/3 and the refractive index of medium 'b' with respect to medium 'c' is 4/3. Find the refractive index of medium 'c' with respect to medium 'a'.
- In the figure, ABC is a quadrant of a circle of radius 14 cm and a semicircle is drawn with BC as diameter. Find the area of the shaded region."
- C++ Program to Apply Above-Below-on Test to Find the Position of a Point with respect to a Line
- In the figure, OACB is a quadrant of a circle with centre O and radius 3.5 cm. If $OD = 2 cm$, find the area of the shaded region."
- What is a coordinate graph?
- In the below figure, ( O A C B ) is a quadrant of a circle with centre ( O ) and radius ( 3.5 mathrm{~cm} ). If ( O D=2 mathrm{~cm} ), find the area of the shaded region."
- In the below figure, ( O A B C ) is a square of side ( 7 mathrm{~cm} ). If ( O A P C ) is a quadrant of a circle with centre O, then find the area of the shaded region. (Use ( pi=22 / 7 ) )"
- How to find the coordinate of a value in an R matrix?
- The refractive index of water with respect to air is $frac {4}{3}$. The refractive index of air with respect to water will be:(a) 1.75 (b) 0.50 (c) 0.75 (d) 0.25
