Finding Quadrant of a Coordinate with respect to a Circle | Python3 Program to find the quadrant of a given coordinate w . rt . the centre of a circle ; Thus function returns the quadrant number ; Coincides with center ; Outside circle ; 1 st quadrant ; 2 nd quadrant ; 3 rd quadrant ; 4 th quadrant ; Coordinates of centre ; Radius of circle ; Coordinates of the given po
import math NEW_LINE def getQuadrant ( X , Y , R , PX , PY ) : NEW_LINE INDENT if ( PX == X and PY == Y ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT val = ( math . pow ( ( PX - X ) , 2 ) + math . pow ( ( PY - Y ) , 2 ) ) ; NEW_LINE if ( val > pow ( R , 2 ) ) : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT if ( PX > X and PY >= Y ) : NEW_LINE INDENT return 1 ; NEW_LINE DEDENT if ( PX <= X and PY > Y ) : NEW_LINE INDENT return 2 ; NEW_LINE DEDENT if ( PX < X and PY <= Y ) : NEW_LINE INDENT return 3 ; NEW_LINE DEDENT if ( PX >= X and PY < Y ) : NEW_LINE INDENT return 4 ; NEW_LINE DEDENT DEDENT X = 0 ; NEW_LINE Y = 3 ; NEW_LINE R = 2 ; NEW_LINE PX = 1 ; NEW_LINE PY = 4 ; NEW_LINE ans = getQuadrant ( X , Y , R , PX , PY ) ; NEW_LINE if ( ans == - 1 ) : print ( " Lies ▁ Outside ▁ the ▁ circle " ) ; NEW_LINE elif ( ans == 0 ) : print ( " Coincides ▁ with ▁ centre " ) ; NEW_LINE else : print ( ans , " Quadrant " ) ; NEW_LINE