Finding intersection between straight line and contour

前端 未结 3 1474
不知归路
不知归路 2021-01-20 01:49

I am trying to find the intersection point of a straight(dashed red) with the contour-line highlighted in red(see plot). I used .get_paths in the second plot to isolate said

3条回答
  •  孤城傲影
    2021-01-20 02:32

    This is a way that I used to solve this problem

    def straight_intersection(straight1, straight2):
        p1x = straight1[0][0]
        p1y = straight1[0][1]
        p2x = straight1[1][0]
        p2y = straight1[1][1]
        p3x = straight2[0][0]
        p3y = straight2[0][1]
        p4x = straight2[1][0]
        p4y = straight2[1][1]
        x = p1y * p2x * p3x - p1y * p2x * p4x - p1x * p2y * p4x + p1x * p2y * p3x - p2x * p3x * p4y + p2x * p3y * p4x + p1x * p3x * p4y - p1x * p3y * p4x
        x = x / (p2x * p3y - p2x * p4y - p1x * p3y + p1x * p4y + p4x * p2y - p4x * p1y - p3x * p2y + p3x * p1y)
        y = ((p2y - p1y) * x + p1y * p2x - p1x * p2y) / (p2x - p1x)
        return (x, y)
    

提交回复
热议问题