コード例 #1
0
ファイル: ex05_triangle.py プロジェクト: MatthiasSch/local
def moving_truss_cp_square(n_steps = 40):

    cp = CreasePattern(n_steps = n_steps)

    cp.nodes = [[ 0, 2, 0 ],
                [ 0, 0, 0 ]]

    cp.crease_lines = [[ 0, 1 ]]

    face_z_0 = FF(Rf = z_ - 0)
    face_x_0 = FF(Rf = x_ - 0)
#    face_xy_135 = FF(Rf = x_ + y_ - 1.0)
#    face_xy_round = FF(Rf = x_**2 + (y_)**2 - 1.0)
#    face_x_1_t = FF(Rf = x_ - 1.0 + 1.99 * t_)
#    argument =  2*3.14159*t_   
#    face_x_1_t = FF(Rf = y_ + 3 + sp.sin(argument))
    face_x_1_t = FF(Rf = y_ - 1.0 * (t_ - 1) * sp.Heaviside(t_ - 1) 
                    + 1.0 * (t_ - 3) * sp.Heaviside(t_ - 3) 
                    + 1.0 * (t_ - 5) * sp.Heaviside(t_ - 5) 
                    - 1.0 * (t_ - 7) * sp.Heaviside(t_ - 7))
    
    face_y_1_t = FF(Rf = x_ + 1.0 * t_ * sp.Heaviside(t_) 
                    - 1.0 * (t_ - 1) * sp.Heaviside(t_ - 1) 
                    - 1.0 * (t_ - 3) * sp.Heaviside(t_ - 3) 
                    + 1.0 * (t_ - 5) * sp.Heaviside(t_ - 5)
                    + 1.0 * (t_ - 7) * sp.Heaviside(t_ - 7) 
                    - 1.0 * (t_ - 8) * sp.Heaviside(t_ - 8))
# +3.14159/2.0    
#    face_x_1_t = FF(Rf = y_ - 1.99 * t_)
    cp.cnstr_lst = [(face_z_0, [0, 1]),
                    (face_x_0, [0]),
                    (face_x_1_t, [1]),
                    (face_y_1_t, [1])]

    X = np.zeros((cp.n_dofs,), dtype = float)
#    X[1] = 0.01
#    X[0] = 0.01


    print 'initial lengths\n', cp.c_lengths
    print 'initial vectors\n', cp.c_vectors

    print 'initial R\n', cp.get_R(X)
    print 'initial dR\n', cp.get_dR(X)

    X = cp.solve_ff(X)

    print '========== results =============='
    print 'solution X\n', X
    print 'final positions\n', cp.get_new_nodes(X)
    print 'final vectors\n', cp.get_new_vectors(X)
    print 'final lengths\n', cp.get_new_lengths(X)

    return cp
コード例 #2
0
ファイル: ex05_triangle.py プロジェクト: MatthiasSch/local
def moving_truss_cp_ff(n_steps = 10, dx = -1.99):

    cp = CreasePattern(n_steps = n_steps)

    cp.nodes = [[ 0, 0, 0 ],
                [ 1, 0, 0 ]]

    cp.crease_lines = [[ 0, 1 ]]

    face_z_0 = FF(Rf = z_ - 0)
    face_x_0 = FF(Rf = x_ - 0)
    face_xy_135 = FF(Rf = x_ + y_ - 1.0)
    face_x_1_t = FF(Rf = x_ - 1.0 + 1.99 * t_)
    cp.cnstr_lst = [(face_z_0, [0, 1]),
                    (face_x_0, [0]),
                    (face_xy_135, [1]),
                    (face_x_1_t, [1])]

    X = np.zeros((cp.n_dofs,), dtype = float)
    X[1] = 0.01

    print 'initial lengths\n', cp.c_lengths
    print 'initial vectors\n', cp.c_vectors

    print 'initial R\n', cp.get_R(X)
    print 'initial dR\n', cp.get_dR(X)

    X = cp.solve_ff(X)

    print '========== results =============='
    print 'solution X\n', X
    print 'final positions\n', cp.get_new_nodes(X)
    print 'final vectors\n', cp.get_new_vectors(X)
    print 'final lengths\n', cp.get_new_lengths(X)

    return cp
コード例 #3
0
    def cp_t2(self):

        # ------------------------------------------------------------------------------
        # test with 3 creaselines
        # ------------------------------------------------------------------------------

        cp = CreasePattern()

        cp.nodes = [[0, 0, 0], [1, 0, 0], [1, 1, 0]]

        cp.crease_lines = [[0, 1], [1, 2], [2, 0]]

        cp.constraints = [[0, 0], [0, 1], [0, 2], [1, 2], [2, 2], [1, 1]]

        cp.constraint_values = [0, 0, 0, 0, 0, 0.1]

        X = np.zeros((cp.n_dofs,), dtype=float)

        print "initial lengths\n", cp.c_lengths
        print "initial vectors\n", cp.c_vectors

        print "initial R\n", cp.get_R(X)
        print "initial dR\n", cp.get_dR(X)

        print "constrained dofs\n", cp.cnstr_dofs
        print "free dofs\n", cp.free_dofs

        # Newton-Raphson iteration
        MAX_ITER = 150
        TOLERANCE = 1e-10

        for i in range(MAX_ITER):
            dR = cp.get_dR(X)[:, cp.free_dofs]
            R = cp.get_R(X)
            if np.linalg.norm(R) < TOLERANCE:
                print "==== converged in ", i, "iterations ===="
                break
            dX = np.linalg.solve(dR, -R)
            X[cp.free_dofs] += dX

        print "========== results =============="
        print "solution X\n", X
        print "final positions\n", cp.get_new_nodes(X)
        print "final vectors\n", cp.get_new_vectors(X)
        print "final lengths\n", cp.get_new_lengths(X)
コード例 #4
0
    def cp_t3(self):

        # ------------------------------------------------------------------------------
        # test 6 triangles (standard pattern)
        # 7 nodes
        # 12 creaselines
        # 3 * 7 - 12 constrains needed
        # ------------------------------------------------------------------------------

        cp = CreasePattern()

        cp.nodes = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [-1, 1, 0], [-1, 0, 0], [-1, -1, 0], [1, -1, 0]]

        cp.crease_lines = [
            [0, 1],
            [1, 2],
            [2, 0],
            [2, 3],
            [3, 0],
            [3, 4],
            [4, 0],
            [4, 5],
            [5, 0],
            [5, 6],
            [6, 0],
            [6, 1],
        ]

        cp.constraints = [[0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [4, 1], [2, 0], [6, 0], [4, 2]]

        # lift node 0 in z-axes
        cp.constraint_values = [0, 0.5, 0, 0, 0, 0, 0, 0, 0]

        X = np.zeros((cp.n_dofs,), dtype=float)

        print "initial lengths\n", cp.c_lengths
        print "initial vectors\n", cp.c_vectors

        print "initial R\n", cp.get_R(X)
        print "initial dR\n", cp.get_dR(X)

        print "constrained dofs\n", cp.cnstr_dofs
        print "free dofs\n", cp.free_dofs

        # Newton-Raphson iteration
        MAX_ITER = 150
        TOLERANCE = 1e-10
        n_steps = 8
        cv = np.copy(cp.constraint_values)

        for k in range(n_steps):
            print "step", k
            cp.constraint_values = (k + 1.0) / float(n_steps) * cv
            for i in range(MAX_ITER):
                dR = cp.get_dR(X)[:, cp.free_dofs]
                print "dR", dR.shape
                R = cp.get_R(X)
                if np.linalg.norm(R) < TOLERANCE:
                    print "==== converged in ", i, "iterations ===="
                    break
                dX = np.linalg.solve(dR, -R)
                X[cp.free_dofs] += dX
            cp.set_next_node(X)

        print "========== results =============="
        print "solution X\n", X
        print "final positions\n", cp.get_new_nodes(X)
        print "final vectors\n", cp.get_new_vectors(X)
        print "final lengths\n", cp.get_new_lengths(X)

        # initialise View
        from crease_pattern_view import CreasePatternView

        my_model = CreasePatternView(data=cp)
        print my_model.data.iteration_nodes.shape

        my_model.configure_traits()
コード例 #5
0
    def get_V_du(self, u):
        '''Get the gradient of potential energy with respect to the current nodal position.
        '''
        F = self.F_N
        F_V_du = self.get_F_V_du(u)
        dof_map = (3 * F[:, :, np.newaxis] + np.arange(3)[np.newaxis, np.newaxis, :])
        V_du = np.bincount(dof_map.flatten(), weights=F_V_du.flatten())
        return V_du

if __name__ == '__main__':
    from crease_pattern import CreasePattern
    cp = CreasePattern(X=[[0, 0, 0],
                          [1, 0, 0],
                          [1, 1, 0],
                          [0, 1, 0],
                          [2, 2, 1]],
                       L=[[0, 1], [1, 2], [3, 2], [0, 3], [0, 2], [1, 4], [2, 4], [3, 4]],
                       F=[[0, 1, 2], [2, 0, 3], [1, 2, 4], [2, 3, 4]])

    # structural mappings

    print 'nodes'
    print cp.X
    print 'lines'
    print cp.L
    print 'faces'
    print cp.F
    print 'faces counter-clockwise'
    print cp.F_N
    print 'node neighbors'
コード例 #6
0
                        ),

                dock = 'tab',
                resizable = True,
                width = 1.0,
                height = 1.0
                )

#===============================================================================
# Test Pattern
#===============================================================================

if __name__ == '__main__':
    # little example with all visual elements
    # ToDo: suface missing
    cp = CreasePattern()
    
    cp.nodes = [[0, 0, 0],
            [1, 0, 0],
            [1, 1, 0],
            [0, 1, 0],
            [0.2, 0.2, 0],
            [0.5, 0.5, 0.0]]
    cp.crease_lines = [[0, 1],
            [1, 2],
            [2, 3],
            [3, 0],
            [1, 3]]
    cp.facets = [[0, 1, 3],
            [1, 2, 3]]
    cp.grab_pts = [[4, 0]]
コード例 #7
0
ファイル: ex05_triangle.py プロジェクト: MatthiasSch/local
def triangle_cp_cnstr(n_steps = 10, dx = -1.99):

    cp = CreasePattern(n_steps = n_steps)

    cp.nodes = [[ 0, 0, 0 ],
                [ 1, 0, 0 ],
                [ 1, 1, 0]]

    cp.crease_lines = [[ 0, 1 ],
                       [ 1, 2 ],
                       [ 2, 0 ]]
    
    cp.facets = [[0, 1, 2 ]]

    cp.grab_pts = [[[0.667,0.333,0],0],
                   [[0.1,0.05,0],0]]
    
    
    cp.cnstr_lhs = [
                    [(0, 0, 1.0)],
                    [(0, 1, 1.0)],
                    [(0, 2, 1.0)],
                    [(1, 1, 1.0)],
                    [(1, 2, 1.0)],
                    [(2, 2, 1.0)],
                    ]

    cp.cnstr_rhs = [0.0, 0.0, 0.0, 0.0, 0.0, dx]

    X = np.zeros((cp.n_dofs,), dtype = float)
    X[1] = 0.01

    print 'L ', cp.grab_pts_L
    print 'initial lengths\n', cp.c_lengths
    print 'initial vectors\n', cp.c_vectors

    print 'initial R\n', cp.get_R(X)
    print 'initial dR\n', cp.get_dR(X)

    X = cp.solve(X)

    print '========== results =============='
    print 'solution X\n', X
    print 'final positions\n', cp.get_new_nodes(X)
    print 'final vectors\n', cp.get_new_vectors(X)
    print 'final lengths\n', cp.get_new_lengths(X)

    return cp
コード例 #8
0
def rhombcp():

    cp = CreasePattern()

    cp.nodes = [[ 0, 0, 0 ],
                [ 2, 0, 0 ],
                [ 4, 0, 0 ],
                [ 0, 1, 0 ],
                [ 1, 1, 0 ],
                [ 3, 1, 0 ],
                [ 4, 1, 0]]

    cp.crease_lines = [[ 0, 1 ],
                       [ 1, 2 ],
                       [ 0, 3 ],
                       [ 2, 6 ],
                       [ 0, 4 ],
                       [ 1, 4 ],
                       [ 3, 4 ],
                       [ 5, 4 ],
                       [ 1, 5 ],
                       [ 2, 5 ],
                       [ 6, 5 ],
                        ]

    cp.constraints = [[3, 2],
                      [3, 1],
                      [4, 1],
                      [4, 2],
                      [5, 1],
                      [5, 2],
                      [6, 0],
                      [6, 1],
                      [6, 2],
                      [0, 2]]

    # lift node 0 in z-axes
    cp.constraint_values = np.zeros((10,), dtype = float)
    cp.constraint_values[3] = 0.4
    cp.constraint_values[5] = 0.4
    cp.constraint_values[8] = 0.0
    cp.constraint_values[9] = 0.0

    X = np.zeros((cp.n_dofs,), dtype = float)
    X[3] = 0.1
    X[5] = 0.1

    print 'initial lengths\n', cp.c_lengths
    print 'initial vectors\n', cp.c_vectors

    print 'initial R\n', cp.get_R(X)
    print 'initial dR\n', cp.get_dR(X)

    print 'constrained dofs\n', cp.cnstr_dofs
    print 'free dofs\n', cp.free_dofs

    # Newton-Raphson iteration
    MAX_ITER = 150
    TOLERANCE = 1e-10
    n_steps = 3
    cv = np.copy(cp.constraint_values)

    for k in range(n_steps):
        print 'step', k
        #cp.set_next_node(X)
        cp.constraint_values = (k + 1.) / float(n_steps) * cv
        i = 0
        while i in range(MAX_ITER):
            dR = cp.get_dR(X)[:, cp.free_dofs ]
            print 'dR', dR.shape
            R = cp.get_R(X)
            if np.linalg.norm(R) < TOLERANCE:
                print '==== converged in ', i, 'iterations ===='
                cp.set_next_node(X)
                break
            dX = np.linalg.solve(dR, -R)
            X[ cp.free_dofs ] += dX
            i += 1
        else:
            raise ValueError
            break


    print '========== results =============='
    print 'solution X\n', X
    print 'final positions\n', cp.get_new_nodes(X)
    print 'final vectors\n', cp.get_new_vectors(X)
    print 'final lengths\n', cp.get_new_lengths(X)

    # initialise View
    my_model = CreasePatternView(data = cp)

    my_model.configure_traits()
コード例 #9
0
                             ),
                      
                       
                        ),
                      
                dock = 'tab',
                resizable = True,
                id = 'creaspatternview',
                width = 1.0,
                height = 1.0
                )

if __name__ == '__main__':

    # initialise CreasePattern
    cp = CreasePattern()

    cp.nodes = [[ 0, 0, 0 ],
                [ 1, 0, 0 ],
                [ 1, 1, 0 ]]

    cp.crease_lines = [[ 0, 1 ], [1, 2]] # , [2, 0]]

    X = np.zeros( ( cp.n_dofs, ), dtype = float )

    cp.set_next_node( X )

    # initialise View
    my_model = CreasePatternView( data = cp )

    my_model.configure_traits()
コード例 #10
0
ファイル: run.py プロジェクト: mwalczyk/kinematic-origami
import matplotlib
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.widgets import Slider
from pprint import pprint
import time

from crease_pattern import CreasePattern
import matrix_utils as mu
import plot_utils as pu
from solver import Solver

if __name__ == "__main__":
    # Initialize the crease pattern and solver
    increments = 50
    crease_pattern = CreasePattern('patterns/waterbomb.json', 30.0)
    solver = Solver(num_increments=increments)

    # Hide toolbars (with "save" button, etc.) and set the GUI theme
    matplotlib.rcParams['toolbar'] = 'None'
    matplotlib.style.use('ggplot')

    # Create a 3D plot for displaying various folded configurations of the model
    solve = True
    print_fold_angles = False
    export_keyframes = True
    show_grid_in_xyz = False
    show_crease_pattern_plot = False
    size = 60

    fig_3d = plt.figure(figsize=(8, 8))