def build_demo_game_engine_old(): robot = RobotConfiguration() boxes = [ robot.add_box( physics.Box( extents=[0.5, 0.5, 0.5], state=physics.State( position=[1.1 * (i - 4.5), 0.5, math.sin(i) * 0.5], ), mass=1, )) for i in xrange(10) ] for b in boxes: robot.add_inner_ear(b) # Add a muscle connecting each box to the box two down the line. for b1, b2 in zip(boxes, boxes[2:]): robot.add_muscle(b1, b2, 2.2) engine = GameEngine(robot, max_time=100) # Connect each box to the next. for b1, b2 in zip(boxes, boxes[1:]): engine.world.physics_world_pointer.add_constraint( b1.pointer, b2.pointer, physics.simulation.Vec(+1.1 / 2.0, 0, 0), physics.simulation.Vec(-1.1 / 2.0, 0, 0), ) return engine
def start_anim(self, colourList, lineConfigList, objConfigList, gui): for i in range(0, 3): Obj = Object(gui.mass_list[i] * phys.MASS_SCALING, phys.State(gui.xy[2 * i], \ gui.xy[2 * i + 1], gui.vel_list[2 * i], gui.vel_list[2 * i+1], i+1)) self.objectList.append(Obj) traceLine, = self.ax.plot([], [], lineConfigList[i], lw=1) self.traceLineList.append(traceLine) particleDiameter = Obj.get_radius( ) * 2 * phys.PLOT_DPI * phys.PLOT_SIZE / phys.GRID_SIZE particleLine, = self.ax.plot([], [], objConfigList[i], ms=particleDiameter) self.particleList.append(particleLine) from time import time t0 = time() self.animate(0) t1 = time() interval = (10**5) * self.dt - (t1 - t0) animFig = plt.figure(num=1, figsize=(phys.PLOT_SIZE, phys.PLOT_SIZE)) animFig.set_size_inches(phys.PLOT_SIZE, phys.PLOT_SIZE, forward=True) ani = animation.FuncAnimation(animFig, self.animate, frames=ANIMATION_FRAMES, \ interval=interval, blit=True, init_func=self.init) plt.show() return ani
def new(x, y, z): b = physics.Box( extents=[0.5, 0.5, 0.5], state=physics.State(position=[x - 2 * S, 0.5 + y, z], ), mass=1, ) world.add_box(b) robot.add_box(b) boxes.append(b) return b
def iterate(self): if self.rt == 1: self.iter_list = np.zeros( (self.num_pts, self.err_pts * np.power(2, (self.num_pts - 1)))) for i in range(0, self.num_pts): self.dt.append(self.dt_start) self.dt_start = self.dt_start / 2 for p in range(0, self.num_pts): objectList = [] for i in range(0, 3): Obj = Object(self.mass_list[i] * phys.MASS_SCALING, \ phys.State(self.xy[2 * i], self.xy[2 * i + 1], self.vel_list[2 * i], self.vel_list[2 * i+1], i+1)) objectList.append(Obj) # Only saves the data for Object 1's x-velocity for j in range(0, self.err_pts * np.power(2, p)): self.iter_list[p, j] = objectList[0].state.get_vel()[1] for k in range(0, len(objectList)): objectList[k].state = phys.iterate( objectList[k].get_state(), self.dt[p], self.method) phys.G_OBJECTS.clear() else: self.iter_list = np.zeros((self.num_pts, self.err_pts)) for i in range(0, self.num_pts): dt.append(self.dt_start) self.dt_start = self.dt_start / self.stepsize for p in range(0, self.num_pts): objectList = [] for i in range(0, 3): Obj = Object(self.mass_list[i] * phys.MASS_SCALING, \ phys.State(self.xy[2 * i], self.xy[2 * i + 1], self.vel_list[2 * i], self.vel_list[2 * i+1], i+1)) objectList.append(Obj) for j in range(0, self.err_pts): self.iter_list[p, j] = objectList[0].state.get_vel()[1] for k in range(0, len(objectList)): objectList[k].state = phys.iterate( objectList[k].get_state(), self.dt[p], self.method) phys.G_OBJECTS.clear() self.iter_flag = 1
def iterate_methods(self): for p in range(0, 3): objectList = [] for i in range(0, 3): Obj = Object(self.mass_list[i] * phys.MASS_SCALING, \ phys.State(self.xy[2 * i], self.xy[2 * i + 1], self.vel_list[2 * i], self.vel_list[2 * i+1], i+1)) objectList.append(Obj) for j in range(0, self.err_pts): self.methods_list[p, j] = objectList[0].state.get_vel()[1] for k in range(0, len(objectList)): objectList[k].state = phys.iterate( objectList[k].get_state(), self.dt_start1, p) phys.G_OBJECTS.clear() self.meth_flag = 1
def __init__(self, initial_pos, atmosphere): # setup physical properties radius = .05 # meters mass = 0.8384 # kg (rocks are 1600kg/m**3) area = math.pi * radius**2 moment = 2 / 5 * mass * radius**2 state = physics.State(position=initial_pos) flight.FlyingObject.__init__(self, mass, moment, state, atmosphere) # setup aerodynamic properties drag_curve = drag.Parasitic(drag.Parasitic.ShapeCoefficients.SPHERE) surface = flight.Surface("rock", atmosphere=atmosphere, drag_curve=drag_curve, area=area) self._surfaces = [surface]
def __init__(self, initial_pos, initial_vel, atmosphere): # setup physical properties radius = 3.66 / 2 # meters # ignore the side boosters for now - and use fins with a drag and lift # curve area = math.pi * radius**2 # I'm not sure about these numbers. Not sure why thrust is ~20x weight # fully loaded. For now set throttle to 5 or 6% to get realistic # acceleration mass = 1420000 / 9.8 # kg thrust = 22241102 # N length = 70 # m # cylinder # 1/12 * mass * length^2 + 1/4 * mass * radius^2 moment = 1 / 12 * mass * length**2 + 1 / 4 * mass * radius**2 state = physics.State(position=initial_pos, velocity=initial_vel, orientation=Angle(90)) Airplane.__init__(self, state, mass, moment, atmosphere) # setup aerodynamic properties drag_curve = drag.Parasitic(.35) surface = flight.Surface("rocket", atmosphere=atmosphere, drag_curve=drag_curve, area=area) stab_lift_curve = lift.LiftingLine(3.62) stab_drag_curve = drag.LiftingLine(3.62, efficiency_factor=0.6) stab = Surface("stabilizer", Vector2D(-33, 0), 0, Angle(0), 136, stab_lift_curve, stab_drag_curve, atmosphere) self._surfaces = [surface, stab] engine = Engine("1d merlin", Vector2D(-21, 0), Angle(0), 0, thrust) engine.set_throttle(100) self._engines = [engine]