Ejemplo n.º 1
0
def testShapeOrientation():
    nodes = [Node([0, 0], 1, 1, 0)]
    nodes.append(Node([5, 1], 1, -1, 1))
    nodes.append(Node([4, -6], 1, 1, 2))
    nodes.append(Node([7, 3], 1, 1, 3))
    s1 = Shape(nodes)

    fig, ax = plt.subplots()
    ax.set_ylim(-10, 10)
    ax.set_xlim(-10, 10)

    plotShape(s1, ax)
    ax.set_title(f"Shape orientation is {s1.o}")

    nodes2 = [Node([0, 0], 1, -1, 0)]
    nodes2.append(Node([7, 3], 1, -1, 3))
    nodes2.append(Node([4, -6], 1, -1, 2))
    nodes2.append(Node([5, 1], 1, 1, 1))
    s2 = Shape(nodes2)

    fig2, ax2 = plt.subplots()
    ax2.set_ylim(-10, 10)
    ax2.set_xlim(-10, 10)

    plotShape(s2, ax2)
    ax2.set_title(f"Shape orientation is {s2.o}")

    plt.show()
Ejemplo n.º 2
0
def animate(i):
    s = halloffame[i]
    ax.clear()
    plotShape(s, ax)
    ax.set_title(f"Generation {i*10}")
    ax.set_xlim(-1, 3)
    ax.set_ylim(1, -3)
Ejemplo n.º 3
0
def testAreaFunction():
    #nodes = [Node([-6,0],1,-1,0)]
    # nodes.append(Node([0,-3],6,-1,1))
    # nodes.append(Node([6,0],1,-1,2))
    # nodes.append(Node([0,-3],1,-1,3))
    nodes = [Node([-5, 5], 1, -1, 0)]
    nodes.append(Node([0, 10], 5, 1, 4))
    nodes.append(Node([5, 5], 1, -1, 1))
    nodes.append(Node([5, -5], 1, -1, 2))
    nodes.append(Node([-5, -5], 1, -1, 3))
    s = Shape(nodes)

    print(f"The area of the shape is: {s.area}")

    fig, ax = plt.subplots()
    ax.set_ylim(-10, 10)
    ax.set_xlim(-10, 10)

    plotShape(s, ax)
    plt.show()
Ejemplo n.º 4
0
def testInBounds():
    nodes = [Node([0, 0], 0.1, -1, 1)]
    nodes.append(Node([0.7, 0], 0.1, -1, 2))
    nodes.append(Node([0.7, -0.3], 0.1, -1, 3))
    nodes.append(Node([0.8, -0.8], 0.3, 1, 4))
    nodes.append(Node([0.7, -1.3], 0.1, -1, 5))
    nodes.append(Node([0, -1.3], 0.1, -1, 6))
    s = Shape(nodes)

    fig, ax = plt.subplots()
    ax.set_ylim(-2, 2)
    ax.set_xlim(-2, 2)
    ax.plot([0.5, 0.5, 2], [-2, -0.5, -0.5], 'k')
    ax.plot([-0.5, -0.5, 2], [-2, 0.5, 0.5], 'k')

    pos = np.array([0.1, 0.4])
    rot = -0.3
    plotShape(s, ax, pos, rot)
    ax.set_title(f"Shape is in bounds: {isInBounds(s, pos, rot)}")
    # TODO make touching lines not intersect according to the function
    plt.show()
Ejemplo n.º 5
0
def testShapePlotting():
    nodes = [Node([0, 0], 1, 1, 0)]
    nodes.append(Node([5, 1], 1, -1, 1))
    nodes.append(Node([4, -6], 1, 1, 2))
    nodes.append(Node([7, 3], 1, 1, 3))
    s = Shape(nodes)

    fig, ax = plt.subplots()
    ax.set_ylim(-10, 10)
    ax.set_xlim(-10, 10)
    plotShape(s, ax, [-5, -5], 0)

    fig, ax = plt.subplots()
    ax.set_ylim(-10, 10)
    ax.set_xlim(-10, 10)
    plotShape(s, ax, [-5, -5], 0.5)

    fig, ax = plt.subplots()
    ax.set_ylim(-10, 10)
    ax.set_xlim(-10, 10)
    plotShape(s, ax, [-5, -5], 1.0)

    fig, ax = plt.subplots()
    ax.set_ylim(-10, 10)
    ax.set_xlim(-10, 10)
    plotShape(s, ax, [-5, -5], 1.5)

    fig, ax = plt.subplots()
    ax.set_ylim(-10, 10)
    ax.set_xlim(-10, 10)
    plotShape(s, ax, [-4, -4], 1.5)

    fig, ax = plt.subplots()
    ax.set_ylim(-10, 10)
    ax.set_xlim(-10, 10)
    plotShape(s, ax, [-3, -3], 1.5)

    plt.show()