Ejemplo n.º 1
0
def test_animation():
    # 1. set parameters
    init_pegs = np.array([[0.25, 0.38], [0.4, 0.1],
                          [0.6, 0.4], [0.0, 0.6], [0.4, 0.6], [0.2, 0.8]])
    init_pegs = np.array([[0.25, 0.35], [0.4, 0.1],
                          [0.6, 0.4], [0.05, 0.6], [0.4, 0.6], [0.22, 0.7],
                          [-0.25, 1.5]])
    init_nodes = np.array([[0.0, 0.0], [0.3, 0.5],
                           [1.0, 0.5], [1.5, 0.2]])
    direction = 1
    diameter = 0.2
    init_setting = (init_nodes, init_pegs, direction, diameter)

    # 2. simulate unrolling process
    trajectory = simulate_unrolling(init_nodes, init_pegs, diameter, direction)
    origins, beziers, arcs, diameters, collide_pegs = trajectory

    # 3. plot the trajectory
    # fig, ax = plt.subplots()
    # plot_trajectory(init_setting, trajectory, ax=ax)
    # plt.show()

    # animation example
    num_pts = 400
    step = 2
    outfile = 'unrolling-with-original.mp4'
    film_writer_title = 'unrolling'
    circle_pnts = 40
    unrolling_animation(init_setting, trajectory, num_pts, step, circle_pnts,
                     outfile=outfile, film_writer_title=film_writer_title)
Ejemplo n.º 2
0
def test_rotation(angle):
    # 1. set parameters
    init_pegs = np.array([[0.25, 0.35], [0.4, 0.1], [0.47, 0.29], [0.38, 0.38],
        [0.6, 0.4],  [0.4, 0.6], [0.20, 0.7],
        [0.20, 0.15], [0.05, 1.27], [0.25, 0.90], [0.03, 0.40],
        [0.58, 0.63], [0.15, 0.05], [0.31, 0.20],
        [0.64, 0.23], [0.31, 0.93], [0.03, 0.38],
        [0.30, 0.03], [0.56, 0.06], [0.13, 1.0],
        [0.38, 0.74], [0.11, 1.28], [0.17, 1.09],
        [-0.01, 1.13], [0.42, 0.49],
        [0.00, 0.88], [-0.11, 1.28], [0.45, 0.47],
        [0.12, 0.33], [-0.02, 1.31],
        [0.15, 0.69], [0.14, 0.46], # YZ
        [0.19, 0.49], [-0.23, 0.648], # YZ ADD
        [-0.15, 0.62], # [0.05, 0.60]
        ])
    init_nodes = np.array([[0.0, 0.0], [0.3, 0.5],
        [1.0, 0.5], [1.5, 0.2]])

    T = np.array([[np.cos(angle), -np.sin(angle)], [np.sin(angle), np.cos(angle)]])
    init_nodes = np.dot(T, init_nodes.transpose()).transpose()

    direction = 1
    diameter = 0.1
    init_setting = (init_nodes, init_pegs, direction, diameter)

    # 2. simulate unrolling process
    trajectory = simulate_unrolling(init_nodes, init_pegs, diameter, direction)
    origins, beziers, arcs, diameters, collide_pegs = trajectory

    # 3. plot the trajectory
    fig, ax = plt.subplots()
    plot_trajectory(init_setting, trajectory, ax=ax)
    plt.show()
Ejemplo n.º 3
0
def test_unrolling():
    # 1. set parameters
    init_pegs = np.array([[0.25, 0.38], [0.4, 0.1], [0.6, 0.4], [0.0, 0.6],
                          [0.4, 0.6], [0.2, 0.8]])
    init_nodes = np.array([[0.0, 0.0], [0.3, 0.5], [1.0, 0.5], [1.5, 0.2]])
    direction = 1
    diameter = 0.2
    init_setting = (init_nodes, init_pegs, direction, diameter)

    # 2. simulate unrolling process
    trajectory = simulate_unrolling(init_nodes, init_pegs, diameter, direction)
    origins, beziers, arcs, diameters, collide_pegs = trajectory

    # 3. plot the trajectory
    fig, ax = plt.subplots()
    plot_trajectory(init_setting, trajectory, ax=ax)
    plt.show()
Ejemplo n.º 4
0
    # cases 7 different shape
    init_nodes = np.array([[0.0, 0.0], [0.3, -0.5],
        [1.0, 1.0], [1.5, 0.2]])


    angle = 0 # 20 30 for cases 6, 0 30 for cases 7
    angle = np.deg2rad(angle)
    T = np.array([[np.cos(angle), -np.sin(angle)], [np.sin(angle), np.cos(angle)]])
    init_nodes = np.dot(T, init_nodes.transpose()).transpose()

    direction = 1
    diameter = 0.1
    init_setting = (init_nodes, init_pegs, direction, diameter)

    # 2. simulate unrolling process
    trajectory = simulate_unrolling(init_nodes, init_pegs, diameter, direction)
    origins, beziers, arcs, diameters, collide_pegs = trajectory


    # 3. plot the trajectory
    fig, ax = plt.subplots()
    plot_trajectory(init_setting, trajectory, ax=ax)
    # ax.plot(pivots[:, 0], pivots[:, 1], 'ro', markersize=2)
    plt.show()

    # 4. unrolling animation
    """
    num_pts = 400
    step = 2
    outfile = 'cases7/unrolling-0.mp4'
    # outfile = None
Ejemplo n.º 5
0
def pipeline():
    """ contains cases 1-7 """
    # case 1-1
    case = 1
    init_nodes = np.array([[0.0, 0.0], [0.3, 0.5], [1.0, 0.5], [1.5, 0.2]])
    angle = 0
    name = 'case-{:d}-{:d}'.format(case, angle)
    pivots = np.array([[-0.18, -0.29], [0.25, 0.35], [0.19, 0.49],
                       [-0.2, 0.63], [-0.23, 0.648], [-0.5324176, 0.34558240]])

    # case 1-50
    """
    case = 1
    init_nodes = np.array([[0.0, 0.0], [0.3, 0.5],
        [1.0, 0.5], [1.5, 0.2]])
    angle = 50
    name = 'case-{:d}-{:d}'.format(case, angle)
    pivots = None
    """

    # case 2-1
    """
    case = 2
    init_nodes = np.array([[0.0, 0.0], [0.3, 0.5],
        [1.0, 0.1], [1.58, 0.2]])
    angle = 0
    name = 'case-{:d}-{:d}'.format(case, angle)
    pivots = np.array([[-0.25, -0.1], [0.38, 0.38], [0.19, 0.49],
        [-0.15, 0.62], [-0.23, 0.648]])
    """
    # case 2-2
    """
    case = 2
    init_nodes = np.array([[0.0, 0.0], [0.3, 0.5],
        [1.0, 0.1], [1.58, 0.2]])
    angle = 30
    name = 'case-{:d}-{:d}'.format(case, angle)
    pivots = np.array([[-0.25, 0.0], [0.03, 0.38], [0.03, 0.40],
        [-0.15, 0.62], [-0.23, 0.648]])
    """

    # case 2-3
    """
    case = 2
    init_nodes = np.array([[0.0, 0.0], [0.3, 0.5],
        [1.0, 0.1], [1.58, 0.2]])
    angle = 60
    name = 'case-{:d}-{:d}'.format(case, angle)
    pivots = np.array([[-0.25, -0.1], [0.13, 1.0], [0, 0.88], [-0.23, 0.648]])
    """

    # case 3-1
    """
    # length = 0.8 * original angle = 61
    case = 3
    init_nodes = np.array([[0, 0], [0.24, 0.4], [0.736, 0.48],
        [1.1808, 0.3424]])
    length = 0.8
    angle = 61
    name = 'case-{:d}-{:d}'.format(case, angle)
    pivots = np.array([[-0.25, 0.0], [-0.15, 0.62], [-0.23, 0.648], [-0.3, 0.6]])
    """
    # case 3-2
    """
    # length = 0.6 angle = 62.5
    case = 3
    init_nodes = np.array([[0, 0], [0.18, 0.3], [0.504, 0.42], [0.8424, 0.4032]])
    length = 0.6
    angle = 62.5
    name = 'case-{:d}-{:d}'.format(case, int(angle))
    pivots = np.array([[0, -0.2], [-0.15, 0.62], [-0.23, 0.648]])
    """
    # case 3-3
    """
    # length = 0.4 angle = 61
    case = 3
    init_nodes = np.array([[0, 0], [0.12, 0.2], [0.304, 0.32], [0.5136, 0.3728]])
    length = 0.6
    angle = 61
    name = 'case-{:d}-{:d}'.format(case, int(angle))
    pivots = None
    """

    # case 4-1
    """
    case = 4
    init_nodes = np.array([[0.0, 0.0], [0.3, 0.2],
        [1.0, 0.1], [1.65, 0.2]])
    angle = 30
    name = 'case-{:d}-{:d}'.format(case, angle)
    pivots = np.array([[-0.2, -0.2], [0.2, 0.15], [0.31, 0.20], [0.6, 0.4]])
    """

    # case 5-1
    """
    case = 5
    init_nodes = np.array([[0.0, 0.0], [0.3, 0.2],
        [1.0, 0.1], [1.65, 0.05]])
    angle = 30
    name = 'case-{:d}-{:d}'.format(case, angle)
    pivots = np.array([[-0.2, -0.2], [0.25, 0.35], [0.15, 0.69], [-0.02, 1.31]])
    """
    # case 6-1
    """
    case = 6
    init_nodes = np.array([[0.0, 0.0], [0.3, 1.0],
        [1.0, -0.5], [1.5, 0.2]])
    angle = 20
    name = 'case-{:d}-{:d}'.format(case, angle)
    pivots = np.array([[-0.5, 0], [-0.15, 0.62], [-0.01, 1.13], [0.05, 1.27],
        [-0.06, 1.47]])
    """
    # case 6-2
    """
    case = 6
    init_nodes = np.array([[0.0, 0.0], [0.3, 1.0],
        [1.0, -0.5], [1.5, 0.2]])
    angle = 30
    name = 'case-{:d}-{:d}'.format(case, angle)
    pivots = None
    """
    # case 7-1
    """
    case = 7
    init_nodes = np.array([[0.0, 0.0], [0.3, -0.5],
        [1.0, 1.0], [1.5, 0.2]])
    angle = 30
    name = 'case-{:d}-{:d}'.format(case, angle)
    pivots = np.array([[-0.25, 0], [0.30, 0.03], [0.4, 0.1], [0.6, 0.4]])
    """
    # case 7-2
    """
    case = 7
    init_nodes = np.array([[0.0, 0.0], [0.3, -0.5],
        [1.0, 1.0], [1.5, 0.2]])
    angle = 0
    name = 'case-{:d}-{:d}'.format(case, angle)
    pivots = np.array([[-0.25, 0], [0.30, 0.03], [0.4, 0.1],
        [0.47, 0.29], [0.15, 0.69], [0, 0.88]])
    """

    # 1. set initial condition
    directory = 'case-{:d}-{:d}'.format(case, int(angle))
    if not os.path.isdir(directory):
        os.makedirs(directory)
    angle = np.deg2rad(angle)
    T = np.array([[np.cos(angle), -np.sin(angle)],
                  [np.sin(angle), np.cos(angle)]])
    # initial bezier curve control points
    init_nodes = np.dot(T, init_nodes.transpose()).transpose()

    init_pegs = np.array([
        [0.25, 0.35],
        [0.4, 0.1],
        [0.47, 0.29],
        [0.38, 0.38],
        [0.6, 0.4],
        [0.4, 0.6],
        [0.20, 0.7],
        [0.20, 0.15],
        [0.05, 1.27],
        [0.25, 0.90],
        [0.03, 0.40],
        [0.58, 0.63],
        [0.15, 0.05],
        [0.31, 0.20],
        [0.64, 0.23],
        [0.31, 0.93],
        [0.03, 0.38],
        [0.30, 0.03],
        [0.56, 0.06],
        [0.13, 1.0],
        [0.38, 0.74],
        [0.11, 1.28],
        [0.17, 1.09],
        [-0.01, 1.13],
        [0.42, 0.49],
        [0.00, 0.88],
        [-0.11, 1.28],
        [0.45, 0.47],
        [0.12, 0.33],
        [-0.02, 1.31],
        [0.15, 0.69],
        [0.14, 0.46],
        [0.19, 0.49],
        [-0.23, 0.648],
        [-0.15, 0.62],
    ])

    direction = 1
    diameter = 0.1
    init_setting = (init_nodes, init_pegs, direction, diameter)
    save_artifact_figures(init_nodes, direction, diameter, directory, name)

    # 2. simulate unrolling process
    trajectory = simulate_unrolling(init_nodes, init_pegs, diameter, direction)
    origins, beziers, arcs, diameters, collide_pegs = trajectory

    # 3. plot the trajectory
    # fig, ax = plt.subplots()
    # plot_trajectory(init_setting, trajectory, ax=ax)
    # plt.show()

    # 4. create unrolling animation
    num_pts = 400
    step = 2
    circle_pnts = 40
    unrolling_outfile = os.path.join(directory, name + '-unrolling.mp4')
    unrolling_film_writer_title = 'unrolling'
    unrolling_animation(init_setting,
                        trajectory,
                        num_pts,
                        step,
                        circle_pnts,
                        outfile=unrolling_outfile,
                        film_writer_title=unrolling_film_writer_title)

    # 5. create pulling animation
    pulling_film_writer_title = 'pulling'
    pulling_outfile = os.path.join(directory, name + '-pulling.mp4')
    if pivots is not None:
        pivots_file = os.path.join(directory, name + '-pivots.txt')
        create_pulling_animation(init_setting,
                                 trajectory,
                                 pivots,
                                 outfile=pulling_outfile,
                                 film_writer_title=pulling_film_writer_title,
                                 pivots_file=pivots_file)
    else:
        create_freepulling(init_setting,
                           trajectory,
                           outfile=pulling_outfile,
                           film_writer_title='writer',
                           num_ptr=400)

        # only use below section of code in OS X
    call(['open', directory])
Ejemplo n.º 6
0
def pipeline_backup():
    # test_unrolling()
    # test_animation()
    # angle = float(sys.argv[1])
    # angle = np.deg2rad(angle)
    # test_rotation(angle)
    # 1. set parameters
    init_pegs = np.array([
        [0.25, 0.35],
        [0.4, 0.1],
        [0.47, 0.29],
        [0.38, 0.38],
        [0.6, 0.4],
        [0.4, 0.6],
        [0.20, 0.7],
        [0.20, 0.15],
        [0.05, 1.27],
        [0.25, 0.90],
        [0.03, 0.40],
        [0.58, 0.63],
        [0.15, 0.05],
        [0.31, 0.20],
        [0.64, 0.23],
        [0.31, 0.93],
        [0.03, 0.38],
        [0.30, 0.03],
        [0.56, 0.06],
        [0.13, 1.0],
        [0.38, 0.74],
        [0.11, 1.28],
        [0.17, 1.09],
        [-0.01, 1.13],
        [0.42, 0.49],
        [0.00, 0.88],
        [-0.11, 1.28],
        [0.45, 0.47],
        [0.12, 0.33],
        [-0.02, 1.31],
        [0.15, 0.69],
        [0.14, 0.46],  # YZ
        [0.19, 0.49],
        [-0.23, 0.648],  # YZ ADD
        [-0.15, 0.62],  # [0.05, 0.60]
    ])
    np.savetxt('pegs.txt', init_pegs, fmt='%0.8f', delimiter=' ')

    # cases 1
    # init_nodes = np.array([[0.0, 0.0], [0.3, 0.5],
    #    [1.0, 0.5], [1.5, 0.2]])
    # cases 2 different shape
    # init_nodes = np.array([[0.0, 0.0], [0.3, 0.5],
    #    [1.0, 0.1], [1.58, 0.2]])
    # cases 3 different length
    # length = 0.8 * original angle = 61
    # init_nodes = np.array([[0, 0], [0.24, 0.4], [0.736, 0.48],
    #    [1.1808, 0.3424]])
    # length = 0.6 * original angle = 62.5
    # init_nodes = np.array([[0, 0], [0.18, 0.3], [0.504, 0.42], [0.8424, 0.4032]])
    # length = 0.4 * original angle = 61
    # init_nodes = np.array([[0, 0], [0.12, 0.2], [0.304, 0.32], [0.5136, 0.3728]])
    # cases 4 different shape
    # init_nodes = np.array([[0.0, 0.0], [0.3, 0.2],
    #    [1.0, 0.1], [1.65, 0.2]])

    # cases 5 different shape
    # init_nodes = np.array([[0.0, 0.0], [0.3, 0.2],
    #    [1.0, 0.1], [1.65, 0.05]])

    # cases 6 different shape
    # init_nodes = np.array([[0.0, 0.0], [0.3, 1.0],
    #    [1.0, -0.5], [1.5, 0.2]])

    # cases 7 different shape
    init_nodes = np.array([[0.0, 0.0], [0.3, -0.5], [1.0, 1.0], [1.5, 0.2]])

    angle = 0  # 20 30 for cases 6, 0 30 for cases 7
    angle = np.deg2rad(angle)
    T = np.array([[np.cos(angle), -np.sin(angle)],
                  [np.sin(angle), np.cos(angle)]])
    init_nodes = np.dot(T, init_nodes.transpose()).transpose()

    direction = 1
    diameter = 0.1
    init_setting = (init_nodes, init_pegs, direction, diameter)

    # 2. simulate unrolling process
    trajectory = simulate_unrolling(init_nodes, init_pegs, diameter, direction)
    origins, beziers, arcs, diameters, collide_pegs = trajectory

    # 3. plot the trajectory
    fig, ax = plt.subplots()
    plot_trajectory(init_setting, trajectory, ax=ax)
    # ax.plot(pivots[:, 0], pivots[:, 1], 'ro', markersize=2)
    plt.show()

    # 4. unrolling animation
    """
    num_pts = 400
    step = 2
    outfile = 'cases7/unrolling-0.mp4'
    # outfile = None
    film_writer_title = 'unrolling'
    unrolling_animation(init_setting, trajectory, num_pts, step, 40, outfile=outfile,
            film_writer_title=film_writer_title)
    """

    # 5. create pulling animation
    # 1. cases 1
    # angle 60
    # pivots = np.array([[-0.25, -0.2], [-0.15, 0.62], [-0.23, 0.648], [-0.5, 0.4]])
    # angle 26
    # pivots = np.array([[0, -0.2], [0.03, 0.38], [0.03, 0.40], [-0.11, 1.28],
    #    [-0.25, 1.4]])
    # angle 40
    # pivots = np.array([[0, -0.4], [-0.15, 0.62], [-0.23, 0.648]])

    # 2. cases 2 same length different shape
    # angle = 0
    # pivots = np.array([[-0.25, -0.1], [0.38, 0.38], [0.19, 0.49],
    #    [-0.15, 0.62], [-0.23, 0.648]])
    # angle = 30
    # pivots = np.array([[-0.25, 0.0], [0.03, 0.38], [0.03, 0.40],
    #    [-0.15, 0.62], [-0.23, 0.648]])
    # angle = 60
    # pivots = np.array([[-0.25, -0.1], [0.13, 1.0], [0, 0.88], [-0.23, 0.648]])

    # cases 3 different length
    # angle = 61 length = 0.8
    # pivots = np.array([[-0.25, 0.0], [-0.15, 0.62], [-0.23, 0.648], [-0.3, 0.6]])
    # angle = 62.5 length = 0.6
    # pivots = np.array([[0, -0.2], [-0.15, 0.62], [-0.23, 0.648]])
    # angle = 61 length = 0.4
    # outfile=None

    # cases 4 different shape
    # angle = 30
    # pivots = np.array([[-0.2, -0.2], [0.2, 0.15], [0.31, 0.20], [0.6, 0.4]])

    # cases 5 different shape
    # angle = 30
    # pivots = np.array([[-0.2, -0.2], [0.25, 0.35], [0.15, 0.69], [-0.02, 1.31]])

    # case 6 different shape
    # angle = 20
    # pivots = np.array([[-0.5, 0], [-0.15, 0.62], [-0.01, 1.13], [0.05, 1.27],
    #    [-0.06, 1.47]])
    # angle = 30
    # pivots = None

    # case 7 different shape
    # angle = 30
    # pivots = np.array([[-0.25, 0], [0.30, 0.03], [0.4, 0.1], [0.6, 0.4]])
    # angle = 0
    """