Count points from an array that lies inside a semi | C # 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 ;
using System ; 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 ++ ) { bool 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 ) } ; Console . Write ( getPointsIns ( X , Y , R , P , Q , arr ) ) ; } } public class pair { public int a ; public int b ; public pair ( int a , int b ) { this . a = a ; this . b = b ; } }