Count points from an array that lies inside a semi | Python implementation of 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
def getPointsIns ( x1 , y1 , radius , x2 , y2 , points ) : NEW_LINE INDENT for point in points : NEW_LINE INDENT condOne = ( point [ 1 ] - y2 ) * ( x2 - x1 ) - ( y2 - y1 ) * ( point [ 0 ] - x2 ) >= 0 NEW_LINE condTwo = radius >= ( ( y1 - point [ 1 ] ) ** 2 + ( x1 - point [ 0 ] ) ** 2 ) ** ( 0.5 ) NEW_LINE if condOne and condTwo : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT X = 0 NEW_LINE Y = 0 NEW_LINE R = 5 NEW_LINE P = 5 NEW_LINE Q = 0 NEW_LINE arr = [ [ 2 , 3 ] , [ 5 , 6 ] , [ - 1 , 4 ] , [ 5 , 5 ] ] NEW_LINE print ( getPointsIns ( X , Y , R , P , Q , arr ) ) NEW_LINE