Exemplo n.º 1
0
    def AltClosestIntersectionPoint( self, p1, p2 ):
        border = p1.borderId
        print "AltClosestIntersectionPoint"
        #print ("BorderId:", border)
        line = Line( p2, p1 )
        intersectionPointList = []
        # check intersecting outer borders on line to closest pair point
        for l in self.outerBorder.lineList:
            p = line.GetIntersectionPoint( l )
            if p and p.intersectingLine.p1.borderId != border:
                # print 'Found OB intersection!'
                intersectionPointList.append( p )
        # check intersecting inner borders on line to closest pair point
        for shape in self.innerBorders:
            for l in shape.lineList:
                p = line.GetIntersectionPoint( l )
                if p and p.intersectingLine.p1.borderId != border:
                    #print 'Found IB intersection!'
                    #print ("intersection has border Id:", p.intersectingLine.p1.borderId )
                    intersectionPointList.append( p )

        # if any intersections found return the closest
        if len(intersectionPointList) > 0:
            # print 'Returning Closest Intersection point!'
            return self.ClosestPoint( intersectionPointList, p1 )
        else:
            return None
Exemplo n.º 2
0
    def ClosestIntersectionPointOnBorder( self, p1, p2, border ):
        line = Line(p1, p2)
        intersectionPointList = []
        # check intersecting outer borders on line to closest pair point
        if border == 0:
            for l in self.outerBorder.lineList:
                p = line.GetIntersectionPoint(l)
                if p:
                    # print 'Found OB intersection!'
                    intersectionPointList.append(p)
        elif border > 0:
            # check intersecting inner borders on line to closest pair point
            shape = self.innerBorders[border - 1]
            for l in shape.lineList:
                p = line.GetIntersectionPoint(l)
                if p:
                    #print 'Found IB intersection!'
                    #print p.intersectingLine.p1.borderId
                    intersectionPointList.append(p)

        # if any intersections found return the closest
        if len(intersectionPointList) > 0:
            # print 'Returning Closest Intersection point!'
            return self.ClosestPoint(intersectionPointList, p2)
        else:
            return None
Exemplo n.º 3
0
    def ClosestIntersectionPointToDst( self, p1, p2 ):
        line = Line(p1, p2)
        intersectionPointList = []
        # check intersecting outer borders on line to closest pair point
        for l in self.outerBorder.lineList:
            p = line.GetIntersectionPoint(l)
            if p:
                # print 'Found OB intersection!'
                intersectionPointList.append(p)

        # check intersecting inner borders on line to closest pair point
        for shape in self.innerBorders:
            for l in shape.lineList:
                p = line.GetIntersectionPoint(l)
                if p:
                    # print 'Found IB intersection!'
                    # print p.borderId
                    intersectionPointList.append(p)
        # if any intersections found return the closest
        if len(intersectionPointList) > 0:
            # print 'Returning Closest Intersection point!'
            return self.ClosestPoint(intersectionPointList, p2)
        else:
            return None
Exemplo n.º 4
0
    def LineSweep(self):
        self.sweepLines = []
        self.collisionGroups = []

        distX = self.boundingBox[0].DistToPoint(self.boundingBox[1].x,
                                                self.boundingBox[1].y)
        distY = self.boundingBox[0].DistToPoint(self.boundingBox[3].x,
                                                self.boundingBox[3].y)
        print('Distance X:', distX)
        print('Distance Y:', distY)

        if self.sweepAngle == 0 or self.sweepAngle == 180:

            # traverse down on y-axis
            y = 0
            count = 0
            trigger = self.sweepOffset
            while True:
                if y >= distY:
                    break

                # "Fire line ray"
                if y >= trigger:
                    p1 = Point(self.boundingBox[0].x,
                               self.boundingBox[0].y + y)
                    p2 = Point(self.boundingBox[0].x + distX,
                               self.boundingBox[0].y + y)
                    l = Line(p1, p2)

                    collisionsOnSameLine = []
                    # check line intersections and collect intersect points from lawn boundarys
                    for line in self.outerBorder.lineList:
                        point = l.GetIntersectionPoint(line)
                        if point:
                            collisionsOnSameLine.append(point)

                    # check collision with obstacles
                    if len(self.innerBorders) > 0:
                        for shape in self.innerBorders:
                            # check line intersections and collect intersect points from lawn boundarys
                            for line in shape.lineList:
                                point = l.GetIntersectionPoint(line)
                                if point:
                                    collisionsOnSameLine.append(point)
                                    #prevPoint = point

                    self.SortPoints(collisionsOnSameLine)
                    self.VertexPointAdjust(collisionsOnSameLine)

                    #
                    if len(collisionsOnSameLine) % 2 != 0:
                        print("Error! odd number of collisions on line!")
                        print("num collisions on this line",
                              len(collisionsOnSameLine))
                        for point in collisionsOnSameLine:
                            print point.x

                    if len(collisionsOnSameLine) > 0:
                        self.collisionGroups.append(collisionsOnSameLine)

                    trigger += self.sweepOffset
                    count += 1
                    self.sweepLines.append(l)
                y += 1

            count = 0
            for points in self.collisionGroups:
                for point in points:
                    count += 1

            print("Number of collision points: ", count)
            return