def problem3():
    f = open('in_out/3_in.txt', 'r')
    g = open('in_out/my_out/my_3_out.txt', 'w')

    A, B, C = helper.readPoints(f, 3)

    nrPoints = int(f.readline())
    points = helper.readPoints(f, nrPoints)

    for point in points:
        triangle = Polygon(*(A, B, C))
        circle = triangle.circumcircle
        where = helper.pointPositionCircle(circle, point)

        g.write('({}, {}) - {}\n'.format(point[0], point[1], where))
def problem4():
    f = open('in_out/4_in.txt', 'r')
    g = open('in_out/my_out/my_4_out.txt', 'w')

    A, B, C = helper.readPoints(f, 3)

    nrPoints = int(f.readline())
    points = helper.readPoints(f, nrPoints)

    helper.plotTriangleCircle([A, B, C], points, 4)
    for D in points:
        helper.plotTriangleCircle([A, B, C], [D], 4)
        helper.plotTriangleCircle([A, B, D], [C], 4)

        legal = illegalEdge(A, B, C, D)
        g.write('AC edge is {}\n'.format(legal))

        legal = illegalEdge(A, B, D, C)
        g.write('BD edge is {}\n'.format(legal))
        g.write('\n')
示例#3
0
def problem3():
    f = open('in_out/3.in', 'r')
    g = open('in_out/my_output/3.out', 'w')

    polygonPoints = hlp.readPoints(f)
    pointList = hlp.readPoints(f)

    hlp.plot(polygonPoints, False)
    hlp.plot(pointList)
    plt.title('Problem 3 - Point Position Relative to a Polygon')
    plt.show()

    for p in pointList:
        pos = position(p, polygonPoints)

        if pos < 0:
            g.write('outside\n')
        elif pos > 0:
            g.write('inside\n')
        else:
            g.write('on edge\n')
def problem2():
    f = open('in_out/2.in', 'r')
    g = open('in_out/my_output/2.out', 'w')

    pointList = hlp.readPoints(f)
    convex_hull = hlp.convexHull(pointList)

    hlp.plot(pointList)
    hlp.plot(convex_hull, False)
    plt.title('Problem 2 - Convex Hull')
    plt.show()

    for pt in convex_hull:
        g.write(str(pt[0]) + ' ' + str(pt[1]) + '\n')
def problem4():
    f = open('in_out/4.in', 'r')
    g = open('in_out/my_output/4.out', 'w')

    pointList = hlp.readPoints(f)

    tspPath = TSP(pointList)

    hlp.plot(pointList)
    hlp.plot(tspPath, False)
    plt.title('Problem 4 - TSP')
    plt.show()

    for point in tspPath:
        g.write(str(point[0]) + ' ' + str(point[1]) + '\n')
    g.write(str(tspPath[0][0]) + ' ' + str(tspPath[0][1]))