Count points from an array that lies inside a semi | Java program for above approach ; Traverse the array ; Stores if a point lies above the diameter or not ; Stores if the R is less than or equal to the distance between center and point ; Driver code ;
import java . io . * ; class Gfg { public static int getPointsIns ( int x1 , int y1 , int radius , int x2 , int y2 , pair points [ ] ) { int ans = 0 ; for ( int i = 0 ; i < points . length ; i ++ ) { boolean condOne = false , condTwo = false ; if ( ( points [ i ] . b - y2 ) * ( x2 - x1 ) - ( y2 - y1 ) * ( points [ i ] . a - x2 ) >= 0 ) { condOne = true ; } if ( radius >= ( int ) Math . sqrt ( Math . pow ( ( y1 - points [ i ] . b ) , 2 ) + Math . pow ( x1 - points [ i ] . a , 2 ) ) ) { condTwo = true ; } if ( condOne && condTwo ) { ans += 1 ; } } return ans ; } public static void main ( String [ ] args ) { int X = 0 ; int Y = 0 ; int R = 5 ; int P = 5 ; int Q = 0 ; pair arr [ ] = { new pair ( 2 , 3 ) , new pair ( 5 , 6 ) , new pair ( - 1 , 4 ) , new pair ( 5 , 5 ) } ; System . out . print ( getPointsIns ( X , Y , R , P , Q , arr ) ) ; } } class pair { int a ; int b ; pair ( int a , int b ) { this . a = a ; this . b = b ; } }