Exemple #1
0
    def __init__(self, simulate_object_num, space_size, wall_depth):

        self.simulate_object_num = simulate_object_num
        self.space_size = space_size
        self.wall_depth = wall_depth
        self.simulate_object_list = []

        for _ in range(simulate_object_num):
            self.simulate_object_list.append(
                Object_With_Bounding(
                    _vector(0, 0, 0),
                    [_vector(0, -1, -1), _vector(0, -1, 1), _vector(0, 1, -1), _vector(0, 1, 1), _vector(0, 0, 1)],
                    pyramid(pos=(0, 0, 0), size=(2, 2, 2)),
                )
            )

        self.CreateSpaces(space_size, wall_depth, 0.1)
        self.Rand_Pos_and_Velocity(10)
Exemple #2
0
    def Rand_Pos_and_Velocity(self, rand_section):

        for i in range(self.simulate_object_num):
            self.simulate_object_list[i].object_show.velocity = vector(
                random.uniform(-rand_section, rand_section),
                random.uniform(-rand_section, rand_section),
                random.uniform(-rand_section, rand_section),
            )

            self.simulate_object_list[i].Move(
                _vector(
                    self.simulate_object_list[i].object_show.velocity[0],
                    self.simulate_object_list[i].object_show.velocity[1],
                    self.simulate_object_list[i].object_show.velocity[2],
                )
            )
Exemple #3
0
    def Run(self):
        dt = 0.03
        index = 0
        import time

        checktime = []
        runtime = []
        while True:
            rate(1 / dt)
            index = index + 1

            if index > 100:
                return

            start = time.time()
            for i in range(self.simulate_object_num):

                for j in range(i + 1, self.simulate_object_num):
                    if self.simulate_object_list[i].Is_Joint(self.simulate_object_list[j]) == True:
                        pass
                        # return
                time1 = time.time()
                self.simulate_object_list[i].Move(
                    _vector(
                        self.simulate_object_list[i].object_show.velocity[0],
                        self.simulate_object_list[i].object_show.velocity[1],
                        self.simulate_object_list[i].object_show.velocity[2],
                    )
                )
                self.Slove_rebound(i)

            end = time.time()
            checktime.append(end - start)
            runtime.append(time1 - start)
            import numpy as np

            logging.info(">>total time(%d):" + str(np.mean(runtime)), index)
            logging.info(">>check time(%d):" + str(np.mean(checktime)), index)
                                                            math.cos(math.radians(angle)) * self.vertex_pointList[i].vector_data_list[2]
        self.object_show.rotate(angle=math.radians(angle), axis=(0,1,0), origin=self.object_show.pos)
                                                            
    def Rotate_Z(self,angle):
        '''
        @para: 1、angle:旋转的角度 
        @function: 旋转变换绕Z轴
        '''
        for i in range( len(self.vertex_pointList) ):
            
            # x' = x*cos(angle)-y*sin(angle)
            self.vertex_pointList[i].vector_data_list[0] =  math.cos(math.radians(angle)) * self.vertex_pointList[i].vector_data_list[0]- \
                                                            math.sin(math.radians(angle)) * self.vertex_pointList[i].vector_data_list[1]
            # y' = x*sin(angle)+y*cos(angle)
            self.vertex_pointList[i].vector_data_list[1] = -math.sin(math.radians(angle)) * self.vertex_pointList[i].vector_data_list[0]+ \
                                                            math.cos(math.radians(angle)) * self.vertex_pointList[i].vector_data_list[1]
    
        self.object_show.rotate(angle=math.radians(angle), axis=(0,0,1), origin=self.object_show.pos)
if __name__ == '__main__':  
    m = Object_With_Bounding(_vector(0,0,0),[_vector(1,2,1),_vector(2,1,5),_vector(4,1,1),_vector(4,4,1)])
    m.Rotate_Z(90)
    m.Update_Bounding()
    for e in m.k_Dops.k_dops_bounding_box:
        print e.min(),e.max()
    
    for vertexe in m.vertex_pointList:
        print vertexe.vector_data_list
 
    pass