Exemplo n.º 1
0
def line_intersection_test():
    a = numpy.array([1, 0])
    b = numpy.array([1, 1])
    c = numpy.array([0, 1])
    d = numpy.array([0, 0])

    line_a = [a, b]
    line_b = [b, c]
    line_c = [c, d]
    line_d = [d, a]

    print line_intersect(line_a, line_b)
Exemplo n.º 2
0
def line_intersection_test():
    a = numpy.array([1, 0])
    b = numpy.array([1, 1])
    c = numpy.array([0, 1])
    d = numpy.array([0, 0])

    line_a = [a, b]
    line_b = [b, c]
    line_c = [c, d]
    line_d = [d, a]

    print line_intersect(line_a, line_b)
Exemplo n.º 3
0
    def _intersect_point(self, p1, p2, p3, w):
        """takes three points and ...
        1. finds two lines p1->p2 and p2->p3
        2. shifts lines by width w
        3. returns the points where the shifted lines intersect"""
        x1, y1 = p1.x, p1.y
        x2, y2 = p2.x, p2.y
        x3, y3 = p3.x, p3.y

        # line 1 angle rotated 90 degrees
        a = math.atan2(y1 - y2, x1 - x2) + (math.pi / 2)

        x1 += math.cos(a) * w
        y1 += math.sin(a) * w
        x2 += math.cos(a) * w
        y2 += math.sin(a) * w

        # line 2 angle rotated 90 degrees
        a = math.atan2(y2 - y3, x2 - x3) + (math.pi / 2)

        x2 += math.cos(a) * w
        y2 += math.sin(a) * w
        x3 += math.cos(a) * w
        y3 += math.sin(a) * w

        return util.line_intersect(x1,y1,x2,y2,x2,y2,x3,y3)
Exemplo n.º 4
0
 def isIntersecting(data):
     if util.line_intersect(data['line1x1'], data['line1y1'],
                            data['line1x2'], data['line1y2'],
                            data['line2x1'], data['line2y1'],
                            data['line2x2'], data['line2y2']) == None:
         return False
     return True
Exemplo n.º 5
0
    def _intersect_point(self, p1, p2, p3, w):
        """takes three points and ...
        1. finds two lines p1->p2 and p2->p3
        2. shifts lines by width w
        3. returns the points where the shifted lines intersect"""
        x1, y1 = p1.x, p1.y
        x2, y2 = p2.x, p2.y
        x3, y3 = p3.x, p3.y

        # line 1 angle rotated 90 degrees
        a = math.atan2(y1 - y2, x1 - x2) + (math.pi / 2)

        x1 += math.cos(a) * w
        y1 += math.sin(a) * w
        x2 += math.cos(a) * w
        y2 += math.sin(a) * w

        # line 2 angle rotated 90 degrees
        a = math.atan2(y2 - y3, x2 - x3) + (math.pi / 2)

        x2 += math.cos(a) * w
        y2 += math.sin(a) * w
        x3 += math.cos(a) * w
        y3 += math.sin(a) * w

        return util.line_intersect(x1, y1, x2, y2, x2, y2, x3, y3)
Exemplo n.º 6
0
 def distToIntersect4(data):
     intersect = util.line_intersect(data['line1x1'], data['line1y1'],
                                     data['line1x2'], data['line1y2'],
                                     data['line2x1'], data['line2y1'],
                                     data['line2x2'], data['line2y2'])
     if intersect == None:
         return -1
     else:
         Len = data['line1Len']
         subLen = np.sqrt((data['line2x2'] - intersect[0])**2 +
                          (data['line2y2'] - intersect[1])**2)
         surface = data['width'] * data['height']
         return (abs(Len - (subLen * 2)) / surface)