(self, xs, ys, point_1, point_2)
return result
compute the distance from point to a line
        ys: coordinates in the first axis
        xs: coordinates in the second axis
        point_1, point_2: (x, y), the end of the line
compute the distance from point to a line
        ys: coordinates in the first axis
        xs: coordinates in the second axis
        point_1, point_2: (x, y), the end of the line
compute the distance from point to a line ys : coordinates in the first axis xs : coordinates in the second axis point_1 point_2 : ( x y ) the end of the line
def distance(self, xs, ys, point_1, point_2):
        '''
        compute the distance from point to a line
        ys: coordinates in the first axis
        xs: coordinates in the second axis
        point_1, point_2: (x, y), the end of the line
        '''
        height, width = xs.shape[:2]
        square_distance_1 = np.square(xs - point_1[0]) + np.square(ys - point_1[1])
        square_distance_2 = np.square(xs - point_2[0]) + np.square(ys - point_2[1])
        square_distance = np.square(point_1[0] - point_2[0]) + np.square(point_1[1] - point_2[1])

        cosin = (square_distance - square_distance_1 - square_distance_2) / (2 * np.sqrt(square_distance_1 * square_distance_2))
        square_sin = 1 - np.square(cosin)
        square_sin = np.nan_to_num(square_sin)

        result = np.sqrt(square_distance_1 * square_distance_2 * square_sin / square_distance)
        result[cosin < 0] = np.sqrt(np.fmin(square_distance_1, square_distance_2))[cosin < 0]
        # self.extend_line(point_1, point_2, result)
        return result
def distance ( self , xs , ys , point_1 , point_2 ) : height , width = xs . shape [ : 2 ] square_distance_1 = np . square ( xs - point_1 [ 0 ] ) + np . square ( ys - point_1 [ 1 ] ) square_distance_2 = np . square ( xs - point_2 [ 0 ] ) + np . square ( ys - point_2 [ 1 ] ) square_distance = np . square ( point_1 [ 0 ] - point_2 [ 0 ] ) + np . square ( point_1 [ 1 ] - point_2 [ 1 ] ) cosin = ( square_distance - square_distance_1 - square_distance_2 ) / ( 2 * np . sqrt ( square_distance_1 * square_distance_2 ) ) square_sin = 1 - np . square ( cosin ) square_sin = np . nan_to_num ( square_sin ) result = np . sqrt ( square_distance_1 * square_distance_2 * square_sin / square_distance ) result [ cosin < 0 ] = np . sqrt ( np . fmin ( square_distance_1 , square_distance_2 ) ) [ cosin < 0 ] # self.extend_line(point_1, point_2, result) return result