Finding Quadrant of a Coordinate with respect to 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 point
function getQuadrant ( X , Y , R , PX , PY ) { if ( PX == X && PY == Y ) return 0 ; let val = Math . pow ( ( PX - X ) , 2 ) + Math . pow ( ( PY - Y ) , 2 ) ; if ( val > Math . pow ( R , 2 ) ) return - 1 ; if ( PX > X && PY >= Y ) return 1 ; if ( PX <= X && PY > Y ) return 2 ; if ( PX < X && PY <= Y ) return 3 ; if ( PX >= X && PY < Y ) return 4 ; } let X = 0 , Y = 3 ; let R = 2 ; let PX = 1 , PY = 4 ; let ans = getQuadrant ( X , Y , R , PX , PY ) ; if ( ans == - 1 ) document . write ( " " + " " ) ; else if ( ans == 0 ) document . write ( " " + " " ) ; else document . write ( ans + " " + " " ) ;