Exemple #1
0
def un_cubo(io, name, cname, roca_size=0.05, density=1, trans=None, tob=None):
    # Definition of a cube as a convex shape

    vertices = numpy.array([[1, 1, 1], [1, -1, 1], [-1, 1, 1], [-1, -1, 1],
                            [1, 1, -1], [1, -1, -1], [-1, 1, -1], [-1, -1, -1]
                            ]) * roca_size

    ch = ConvexHull(vertices)
    cm = ch.centroid()

    # correction of vertices such that 0 is the centroid
    vertices = numpy.array(vertices)[:] - cm[:]

    ch = ConvexHull(vertices)
    cm = ch.centroid()

    # Definition of a polyhedron as a convex shape
    io.add_convex_shape(cname, vertices)

    # computation of inertia and volume
    inertia, volume = ch.inertia(ch.centroid())

    io.add_object(
        name,
        [Contactor(cname)],
        translation=trans,
        #velocity=veloci,
        mass=volume * density,
        time_of_birth=tob,
        inertia=inertia * density)
def one_brick(io,
              name,
              cname,
              vertices,
              size,
              density=1,
              trans=None,
              velo=None,
              tob=None):

    estimated_size = max(
        numpy.array(vertices).max(axis=0) - numpy.array(vertices).min(axis=0))
    #print(estimated_size)
    # scale = size / max(numpy.array(vertices).max(axis=0)
    #                         - numpy.array(vertices).min(axis=0))
    scale = 1.0
    ch = ConvexHull(vertices)
    cm_ori = ch.centroid()
    #print('cm_ori', cm_ori)
    if (numpy.linalg.norm(cm_ori) <= 1e-2):
        input()
    # correction of vertices such that 0 is the centroid
    vertices = (numpy.array(vertices)[:] - cm_ori[:]) * scale

    ch = ConvexHull(vertices)
    cm = ch.centroid()
    #print('cm', cm)
    # Definition of a polyhedron as a convex shape
    io.add_convex_shape(cname, vertices, insideMargin=0.001 * size)

    # computation of inertia and volume
    inertia, volume = ch.inertia(ch.centroid())

    # print('geometric inertia:', inertia)
    # print('volume:', volume)
    # print('mass:', volume*density)
    # print('inertia:', inertia*density)

    # io.add_object(name,
    #              [Contactor(cname, relative_translation = cm_ori)],
    #              translation=-cm_ori,
    #              velocity=velo,
    #              mass=volume*density,
    #              time_of_birth=tob,
    #              inertia=inertia*density)
    io.add_object(
        name, [Contactor(
            cname,
            relative_orientation=[1.0, 0.0, 0.0, 0.0],
        )],
        translation=cm_ori,
        orientation=[1.0, 0.0, 0.0, 0.0],
        velocity=velo,
        mass=volume * density,
        time_of_birth=tob,
        inertia=inertia * density)
def one_rock(io, name, cname, rock_size=0.05, density=1, trans=None, velo=None, tob=None):
    # Definition of an irregular polyhedron as a convex shape

    rd = [math.pi/2 * random.gauss(0.5,0.2) for _ in range(16)]
    rd = [1.143194140731269, 0.6247636994959747, 0.4198206059540749, 1.1116480956118107, 0.8965451614785596, 0.8819019228647785, 0.2592675582459427, 0.22899315888913663, 0.23837569282753324, 0.6585606791241505, 1.0084563758002816, 0.9096785924063177, 0.8633716705085941, 1.1215975890657788, 1.1983269522076825, 0.5443688021200721]

    # print('rd', rd)
    # input()
    def vert(id1, id2, a, b, c):
        return (a*math.cos(rd[id1])*math.cos(rd[id2]),
                b*math.sin(rd[id1])*math.cos(rd[id2]),
                c*math.sin(rd[id2]))

    vertices = [ vert( 0,  1,   1,  1,  1),
                 vert( 2,  3,   1, -1,  1),
                 vert( 4,  5,  -1,  1,  1),
                 vert( 6,  7,  -1, -1,  1),
                 vert( 8,  9,   1,  1, -1),
                 vert(10, 11,   1, -1, -1),
                 vert(12, 13,  -1,  1, -1),
                 vert(14, 15,  -1, -1, -1) ]

    scale = rock_size / max(numpy.array(vertices).max(axis=0)
                            - numpy.array(vertices).min(axis=0))

    ch = ConvexHull(vertices)
    cm = ch.centroid()

    # correction of vertices such that 0 is the centroid
    vertices = (numpy.array(vertices)[:] - cm[:]) * scale

    ch = ConvexHull(vertices)
    cm = ch.centroid()

    # Definition of a polyhedron as a convex shape
    io.add_convex_shape(cname, vertices, insideMargin=0.1*rock_size)

    # computation of inertia and volume
    inertia,volume=ch.inertia(ch.centroid())

    # print('geometric inertia:', inertia)
    # print('volume:', volume)
    # print('mass:', volume*density)
    # print('inertia:', inertia*density)


    io.add_object(name,
                 [Contactor(cname)],
                 translation=trans,
                 velocity=velo,
                 mass=volume*density,
                 time_of_birth=tob,
                 inertia=inertia*density)
Exemple #4
0
def una_roca(io, name, cname, roca_size=0.05, density=1, trans=None, tob=None):
    # Definition of an irregular polyhedron as a convex shape

    rd = [math.pi / 2 * random.gauss(0.5, 0.2) for _ in range(16)]

    def vert(id1, id2, a, b, c):
        return (a * math.cos(rd[id1]) * math.cos(rd[id2]),
                b * math.sin(rd[id1]) * math.cos(rd[id2]),
                c * math.sin(rd[id2]))

    vertices = [
        vert(0, 1, 1, 1, 1),
        vert(2, 3, 1, -1, 1),
        vert(4, 5, -1, 1, 1),
        vert(6, 7, -1, -1, 1),
        vert(8, 9, 1, 1, -1),
        vert(10, 11, 1, -1, -1),
        vert(12, 13, -1, 1, -1),
        vert(14, 15, -1, -1, -1)
    ]

    scale = roca_size / max(
        numpy.array(vertices).max(axis=0) - numpy.array(vertices).min(axis=0))

    ch = ConvexHull(vertices)
    cm = ch.centroid()

    # correction of vertices such that 0 is the centroid
    vertices = (numpy.array(vertices)[:] - cm[:]) * scale

    ch = ConvexHull(vertices)
    cm = ch.centroid()

    # Definition of a polyhedron as a convex shape
    io.add_convex_shape(cname, vertices, insideMargin=0.1 * roca_size)

    # computation of inertia and volume
    inertia, volume = ch.inertia(ch.centroid())

    # print('geometric inertia:', inertia)
    # print('volume:', volume)
    # print('mass:', volume*density)
    # print('inertia:', inertia*density)

    io.add_object(
        name,
        [Contactor(cname)],
        translation=trans,
        #velocity=veloci,
        mass=volume * density,
        time_of_birth=tob,
        inertia=inertia * density)
Exemple #5
0
    io.add_primitive_shape('Ground',
                           'Box', (10, 10, 1),
                           insideMargin=0.01,
                           outsideMargin=0.0)

    # Definition of a non smooth law. As no group ids are specified it
    # is between contactors of group id 0.
    io.add_Newton_impact_friction_nsl('contact',
                                      mu=0.01,
                                      e=0.7,
                                      collision_group1=1,
                                      collision_group2=2)

    # computation of inertia and volume
    ch = ConvexHull(pts)
    inertia, volume = ch.inertia(ch.centroid())

    # The tetra object made with an unique Contactor : the tetrahedron
    # shape.  As a mass is given, it is a dynamic system involved in
    # contact detection and in the simulation.  With no group id
    # specified the Contactor belongs to group 0
    io.add_object('tetra', [Contactor('Tetra', collision_group=1)],
                  translation=[0, 0, 4],
                  velocity=[0, 0, 0, 0, 0, 0],
                  mass=1,
                  inertia=inertia)

    # the ground object made with the ground shape. As the mass is
    # not given, it is a static object only involved in contact
    # detection.
    io.add_object('ground', [Contactor('Ground', collision_group=2)],
            ])
            all_pts += list(pts)
            io.add_convex_shape('Chainlink%02d' % (i * num_parts + j), pts)

    # connector: using the 16 points closest to center, create two
    # hulls for upper and lower part
    all_pts = np.array(all_pts)
    connect = all_pts[np.argsort((all_pts[:, 1] - 0)**2)[:16]]
    io.add_convex_shape('Chainlink%02d' % (num_parts * 2 + 0),
                        connect[connect[:, 2] > 0])
    io.add_convex_shape('Chainlink%02d' % (num_parts * 2 + 1),
                        connect[connect[:, 2] < 0])

    # computation of inertia and volume of all points
    ch = ConvexHull(all_pts)
    link_inertia, volume = ch.inertia(ch.centroid())

    # computation of inertia and volume of all points including
    # extrema of the ball
    ball_pos = np.array([0, ball_radius + length * 2 / 3, 0])
    ch = ConvexHull(
        np.vstack((all_pts, [
            ball_pos + [0, ball_radius, 0], ball_pos + [0, 0, ball_radius],
            ball_pos + [0, 0, -ball_radius], ball_pos + [ball_radius, 0, 0],
            ball_pos + [-ball_radius, 0, 0]
        ])))
    ball_inertia, volume = ch.inertia(ch.centroid())

    # ball at the end of the chain
    io.add_primitive_shape('Ball', 'Sphere', [ball_radius])
Exemple #7
0
                         (polyhedron_size_rand, polyhedron_size_rand, 0.0),
                         (0.0,0.0, 10.0*polyhedron_size_rand)]
   print('polyhedron_vertices', polyhedron_vertices)
   ch = ConvexHull(polyhedron_vertices)
   cm = ch.centroid()
   print('cm', cm)
   
   # correction of vertices such that o is the centroid
   polyhedron_vertices = numpy.array(polyhedron_vertices)[:]-cm[:]
   print('corrected polyhedron_vertices', polyhedron_vertices)
   ch = ConvexHull(polyhedron_vertices)
   cm = ch.centroid()
   print('cm', cm)
   
   # computation of inertia and volume
   inertia,volume=ch.inertia(cm)
   print ('inertia,volume',inertia,volume)
   mass = volume*density
   inertia = inertia*density
   print ('inertia,mass',inertia,mass)
   
   # Definition of a polyhedron as a convex shape
   io.add_convex_shape('PolyhedronCS'+str(n)+'_'+str(i)+'_'+str(j), polyhedron_vertices)
   
   trans=[box_width/5.0+i*x_shift*polyhedron_size, x_shift*(j+2)*polyhedron_size, box_height+polyhedron_size*x_shift*n]
   #trans= [0,0,0]
   io.add_object('polyhedron'+str(n)+'_'+str(i)+'_'+str(j), [Contactor('PolyhedronCS'+str(n)+'_'+str(i)+'_'+str(j))],
                 translation=trans, orientation = orientation_polyhedron,
                 velocity=[0, 0, 0, 0, 0, 0],
                 mass=mass,inertia=inertia)