def draw_cone(point_dict, radius=None, PUZZLE_COM=vpy.vec(0,0,0)): """ draw a vpython cone for the given point information inputs: ------- point_dict - (dict) - dictionary specifying coordinates, color and size of the point with keys 'coords', 'vpy_color' (and 'size') respectively radius - (float) - alternative method to specify the radius of the drawn sphere returns: -------- None outputs: -------- draws a vpython cone for the given point """ if radius == None: radius = point_dict["size"]/50 if not isinstance(point_dict["coords"], vpy.vector): dict_to_vpy(point_dict) vpy.cone(pos=point_dict["coords"], color=point_dict["vpy_color"], radius=radius, axis=PUZZLE_COM-point_dict["coords"])
def __init__(self, v, v_label, v_label_pos, v_color, v_pos): self.v = v # Vector self.v_label = v_label # Label for the vector self.v_color = v_color # Vector colour # Position of vector i.e. where its tail is. self.v_pos = v_pos # Axis of the cone; same as the vector's self.cone_axis = 0.1 * vp.norm(self.v) self.rod_radius = 0.02 # Absolute radius of the rod self.cone_radius = 0.06 # Absolute radius of the rod # Reduce the size of the rod by the axial size of the cone self.rod = vp.cylinder(pos=v_pos, axis=self.v - self.cone_axis, radius=self.rod_radius, color=v_color) # Place the base of the cone at the end of rod # which has been reduced by the cone's axial length self.cone = vp.cone(pos=self.v - self.cone_axis + v_pos, axis=self.cone_axis, radius=self.cone_radius, color=v_color) # Note where the tip of the cone is, # which will define the starting point of # of the axis line self.cone_tip = self.v + v_pos + 0.1 * vp.norm(self.v) self.axis_text = vp.label(text=v_label, pos=v_pos + v_label_pos * (self.cone_tip - v_pos), color=v_color, xoffset=3, yoffset=3, box=False)
def __init__(self, v, arrow_label, arrow_color, arrow_pos): if arrow_label == 'x': vec_u = Arrow.vec_i elif arrow_label == 'y': vec_u = Arrow.vec_j elif arrow_label == 'z': vec_u = Arrow.vec_k else: vec_u = vp.vector(v.x * Arrow.vec_i.x, v.y * Arrow.vec_j.y, v.z * Arrow.vec_k.z) self.rod_radius = vp.mag(vec_u) * 0.01 scaled_arrow_pos = vp.vector(arrow_pos.x * Arrow.vec_i.x, arrow_pos.y * Arrow.vec_i.y, arrow_pos.z * Arrow.vec_i.z) self.rod = vp.cylinder(pos=scaled_arrow_pos, axis=vec_u, radius=self.rod_radius, color=arrow_color) self.cone = vp.cone(pos=vec_u, axis=0.1 * vec_u, radius=vp.mag(vec_u) * 0.03, color=arrow_color) if arrow_label in 'xyz': self.axis_text = vp.text(text=arrow_label, pos=self.cone.pos + 0.1 * vec_u, color=arrow_color)
def presynDraw(self, _scene): for idx, coord in enumerate(self.activeCoords): v0 = list2vec(coord[0]) v1 = list2vec(coord[1]) self.coordMin = np.minimum(self.coordMin, coord[0][0:3]) self.coordMin = np.minimum(self.coordMin, coord[1][0:3]) self.coordMax = np.maximum(self.coordMax, coord[0][0:3]) self.coordMax = np.maximum(self.coordMax, coord[1][0:3]) radius = self.diaScale * self.activeDia[idx] / 2.0 opacity = self.opacity[idx] cone = vp.cone(canvas=_scene, pos=v0, axis=v0 - v1, radius=radius, opacity=opacity) self.segments.append(cone)
def get_random_shape(): """ :return: a created random shape """ shape_type = random.choice(SHAPE_TYPES) if shape_type == SHAPE_TYPES[0]: return vpython.box(size=config.SHAPE_SIZE, axis=config.SHAPE_AXIS) elif shape_type == SHAPE_TYPES[1]: return vpython.cone(size=config.SHAPE_SIZE, axis=config.SHAPE_AXIS) elif shape_type == SHAPE_TYPES[2]: return vpython.cylinder(size=config.SHAPE_SIZE, axis=config.SHAPE_AXIS) elif shape_type == SHAPE_TYPES[3]: return vpython.pyramid(size=config.SHAPE_SIZE, axis=config.SHAPE_AXIS) elif shape_type == SHAPE_TYPES[4]: return vpython.sphere(size=config.SHAPE_SIZE, axis=config.SHAPE_AXIS) else: raise ValueError(errors_messages.ERROR_SHAPE)
def _create_obj(self, entity: Entity, origin: Entity, texture_path: Optional[str]) -> vpython.sphere: ship = vpython.cone(pos=vpython.vector(5, 0, 0), axis=vpython.vector(5, 0, 0), radius=3) entrance = vpython.extrusion( path=[vpython.vec(0, 0, 0), vpython.vec(4, 0, 0)], shape=[ vpython.shapes.circle(radius=3), vpython.shapes.rectangle(pos=[0, 0], width=0.5, height=0.5) ], pos=vpython.vec(3, 0, 0)) docking_arm = vpython.extrusion( path=[ vpython.vec(0, 0, 0), vpython.vec(1.5, 0, 0), vpython.vec(1.5, 0.5, 0) ], shape=[vpython.shapes.circle(radius=0.03)]) obj = vpython.compound([ship, entrance, docking_arm], make_trail=True, texture=vpython.textures.metal, bumpmap=vpython.bumpmaps.gravel) obj.pos = entity.screen_pos(origin) obj.axis = calc.angle_to_vpy(entity.heading) obj.length = entity.r * 2 obj.height = entity.r * 2 obj.width = entity.r * 2 # A compound object doesn't actually have a radius, but we need to # monkey-patch this for when we recentre the camera, to determine the # relevant_range of the space station obj.radius = entity.r return obj
def __init__(self, connection=None, autoId=True): self.scene = {} self.hits = [] self.x = 0.5 self.y = 0.5 self.z = 0.5 self.yaw = 0 self.pitch = 0 self.follow = False self.events = EventCommand(self) self.player = PlayerCommand(self) self.entity = EntityCommand(self.player) self.me = cone(pos=(self.x - 0.5, self.y, self.z - 0.5), axis=(1, 0, 0), radius=0.5, color=color.red, visible=False) scene.bind('keydown', self.keyInput)
def __init__(self, axis_label, axis_color, arrow_pos): if axis_label == 'x': vec_u = Arrow.vec_i elif axis_label == 'y': vec_u = Arrow.vec_j elif axis_label == 'z': vec_u = Arrow.vec_k self.rod_radius = vp.mag(vec_u) * 0.01 self.rod = vp.cylinder(pos=arrow_pos, axis=vec_u, radius=self.rod_radius, color=axis_color) self.cone = vp.cone(pos=vec_u, axis=0.1 * vec_u, radius=vp.mag(vec_u) * 0.03, color=axis_color) if axis_label in 'xyz': self.axis_text = vp.text(text=axis_label, pos=self.cone.pos + 0.1 * vec_u, color=axis_color)
def launch(sample_rate, position, orientation, COM, COP, thrust, gravity, lift, drag): for step in range(len(position)): position[step][2] = -position[step][2] force_scale = 0.01 l = 2 rad = 0.09 steps = len(position) # Initialization of enviorment render = vp.canvas(height=600, width=1200, background=vp.vector(0.8, 0.8, 0.8), forward=vp.vector(1, 0, 0), up=vp.vector(0, 0, 1)) render.select() render.caption = "Loading..." render.visible = False # Initialization of body and cone body = vp.cylinder(pos=vp.vector(-l, 0, 0), axis=vp.vector(l*0.8, 0, 0), radius=rad) cone = vp.cone(pos=vp.vector(-l*0.2, 0, 0), axis=vp.vector(l*0.2, 0, 0), radius=rad) # Initialization of fins a_fins = vp.box(pos=vp.vector(-l + (l*0.05), 0, 0), size=vp.vector(l*0.1, rad*4, rad*0.25)) b_fins = vp.box(pos=vp.vector(-l + (l*0.05), 0, 0), size=vp.vector(l*0.1, rad*0.25, rad*4)) inv_box = vp.box(pos=vp.vector(l/2, 0, 0), size=vp.vector(l, 10e-10, 10e-10), visible=False) # Initialization of rocket rocket = vp.compound([body, cone, a_fins, b_fins, inv_box], pos=vp.vector(0, 0, 1), axis=vp.vector(1, 0, 0), up=vp.vector(0, 0, 1), color=vp.vector(1,1,1), opacity=0.5) COM_sphere = vp.sphere(radius = 0.04, color=vp.vector(0, 0, 0)) COP_sphere = vp.sphere(radius = 0.04, color=vp.vector(0, 0, 0)) thrust_pointer = vp.arrow(shaftwidth = 0.1, color=vp.vector(1, 1, 0)) gravity_pointer = vp.arrow(shaftwidth = 0.1, color=vp.vector(0, 1, 1)) lift_pointer = vp.arrow(shaftwidth = 0.1, color=vp.vector(1, 0, 1)) drag_pointer = vp.arrow(shaftwidth = 0.1, color=vp.vector(0, 0, 1)) a = 4 c = 0.3 b = a - c sqr_out = [[-a, a],[a, a],[a, -a],[-a, -a], [-a, a]] sqr_in1 = [[-b, b - 3*c],[b, b - 3*c],[b, -b],[-b, -b], [-b, b - 3*c]] sqr_in2 = [[-b, b],[b, b], [b, b - 2*c],[-b, b - 2*c], [-b, b]] ref_box = vp.extrusion(path=[vp.vector(-c/2, 0, 0), vp.vector(c/2, 0, 0)], shape=[sqr_out, sqr_in1, sqr_in2], color=vp.vector(0.5, 0.5, 0.5)) render.camera.follow(rocket) render.autoscale = False launch_pad = vp.box(pos=vp.vector(position[0][0], position[0][1], -1), size=vp.vector(16, 16, 2), color=vp.vector(0.2, 0.2, 0.2)) launch_pad = vp.box(pos=vp.vector(position[-1][0], position[-1][1], -1), size=vp.vector(16, 16, 2), color=vp.vector(0.2, 0.2, 0.2)) rocket.normal = vp.cross(rocket.up, rocket.axis) #vp.attach_arrow(rocket, 'up', color=vp.color.green) #vp.attach_arrow(rocket, 'axis', color=vp.color.blue) #vp.attach_arrow(rocket, 'normal', color=vp.color.red) roll = 0 vp.attach_trail(rocket, radius=rad/3, color=vp.color.red) sqr_out = [[-a, a],[a, a],[a, -a],[-a, -a], [-a, a]] sqr_in1 = [[-b, b - 3*c],[b, b - 3*c],[b, -b],[-b, -b], [-b, b - 3*c]] sqr_in2 = [[-b, b],[b, b], [b, b - 2*c],[-b, b - 2*c], [-b, b]] for step in range(2, steps): if not step % 5: a = 4 c = 0.3 b = a - c ref = vp.extrusion(path=[vp.vector(0, 0, 0), vp.vector(c, 0, 0)], shape=[sqr_out, sqr_in1, sqr_in2], axis=vp.vector(1, 0, 0), up=vp.vector(0, 1, 0), pos=vp.vector(position[step][0], position[step][1], position[step][2])) ref.up = vp.vector(0, 0, 1) ref.rotate(angle=orientation[step][0], axis=vp.cross(ref.axis, ref.up)) ref.rotate(angle=orientation[step][1], axis=ref.up) ref.rotate(angle=orientation[step][2], axis=ref.axis) render.caption = "Running" render.visible = True for step in range(steps): x = position[step][0] y = position[step][1] z = position[step][2] rocket.normal = vp.cross(rocket.axis, rocket.up) pitch, yaw, roll = orientation[step][0], orientation[step][1], orientation[step][2] COM_x = x + COM[step] * np.cos(yaw) * np.cos(pitch) COM_y = y + COM[step] * np.sin(yaw) * np.cos(pitch) COM_z = z + COM[step] * np.sin(pitch) COP_x = x + COP[step] * np.cos(yaw) * np.cos(pitch) COP_y = y + COP[step] * np.sin(yaw) * np.cos(pitch) COP_z = z + COP[step] * np.sin(pitch) thrust_x = x + (-l) * np.cos(yaw) * np.cos(pitch) thrust_y = y + (-l) * np.sin(yaw) * np.cos(pitch) thrust_z = z + (-l) * np.sin(pitch) thrust_mag = np.linalg.norm(thrust[step]) * force_scale thrust_ax_x = thrust_mag * np.cos(yaw) * np.cos(pitch) thrust_ax_y = thrust_mag * np.sin(yaw) * np.cos(pitch) thrust_ax_z = thrust_mag * np.sin(pitch) lift_mag = lift[step][0] * force_scale lift_ax_x = 0 lift_ax_y = 0 lift_ax_z = lift_mag drag_mag = np.linalg.norm(drag[step]) * force_scale print(lift_mag) drag_ax_x = drag_mag drag_ax_y = 0 drag_ax_z = 0 gravity_mag = np.linalg.norm(gravity[step]) * force_scale thrust_pointer.pos = vp.vector(thrust_x, thrust_y, thrust_z) thrust_pointer.axis = vp.vector(thrust_ax_x, thrust_ax_y, thrust_ax_z) gravity_pointer.pos = vp.vector(COM_x, COM_y, COM_z) gravity_pointer.axis = vp.vector(0, 0, -gravity_mag) lift_pointer.pos = vp.vector(COP_x, COP_y, COP_z) lift_pointer.axis = vp.vector(lift_ax_x, lift_ax_y, lift_ax_z) drag_pointer.pos = vp.vector(COP_x, COP_y, COP_z) drag_pointer.axis = vp.vector(drag_ax_x,drag_ax_y, drag_ax_z) rocket.rotate(angle=pitch, axis=rocket.normal) rocket.rotate(angle=yaw, axis=rocket.up) rocket.rotate(angle=roll, axis=rocket.axis) COM_sphere.pos = vp.vector(COM_x, COM_y, COM_z) COP_sphere.pos = vp.vector(COP_x, COP_y, COP_z) rocket.pos = vp.vector(x, y, z) vp.sleep(1/sample_rate) if step + 1 != steps: rocket.rotate(angle=-roll, axis=rocket.axis) rocket.rotate(angle=-yaw, axis=rocket.up) rocket.rotate(angle=-pitch, axis=rocket.normal) render.caption = "Done"
vp.color.green, vp.color.yellow, vp.color.magenta, vp.color.orange, vp.color.purple, vp.color.white ] # The object parameters max_height = 8 min_height = 4 max_width = 6 min_width = 3 # Generate the objects but make them invisible for now all_objects = [] for i in range(max_obs): all_objects.append(vp.box(visible=False)) for i in range(max_obs): all_objects.append(vp.cone(visible=False)) for i in range(max_obs): all_objects.append(vp.sphere(visible=False)) # Set the width and height of the window scene = vp.scene scene.width = width scene.height = height # Set the color of the scene scene.background = vp.color.cyan # First draw the room floor = vp.box(pos=vp.vector(0, 0, 0), size=vp.vector(room_width, thickness, room_width), texture='WoodFloor.jpg')
from vpython import sphere, box, cylinder, cone, color, curve, rate from vpython import sqrt, atan, cos, sin, pi from vpython import vector as vec dirt = vec(1, 0.6, 0.4) ground = box(color=dirt) ground.axis = vec(1, 0, 1) ground.size = vec(0.305 * 120 / sqrt(2), 0.305 * 1, 0.305 * 120 / sqrt(2)) ground.pos = 0.305 * vec(0, -0.5, 0) mound = cone(color=dirt) mound.axis = 0.305 * vec(0, 10 / 12, 0) mound.radius = 0.305 * 9 pitcher = cylinder(color=color.red) pitcher.pos = 0.305 * vec(0, 10 / 12, 0) pitcher.axis = 0.305 * vec(0, 6, 0) plate = box(color=color.yellow) plate.size = vec(1, 0.1, 1) plate.pos = 0.305 * vec(60.5, 0, 0) strikezone = box(color=color.red) strikezone.size = vec(0.305 / 12, 0.305 * 2, 0.305 * 2) strikezone.pos = 0.305 * vec(60.5, 2.5, 0) def in_boundary(x, bound, pos): return x - bound / 2 < pos < x + bound / 2
from vpython import cone c = cone()
sleep(2) # flush input buffer, discarding all contents ser.reset_input_buffer() return ser except serial.SerialException: raise IOError("problem connecting to " + port) if __name__ == '__main__': portName = 'COM4' port = serial_connect(portName, 115200) vp.scene.range = 10 us = vp.box(length=5.0, height=0.1, width=2.0, color=vp.vector(0, 0, 1), pos=vp.vector(0, -4, 0)) t = vp.cylinder(radius=0.75, length=0.5, axis=vp.vector(0, 1, 0), pos=vp.vector(1, -4, 0)) r = vp.cylinder(radius=0.75, length=0.5, axis=vp.vector(0, 1, 0), pos=vp.vector(-1, -4, 0)) beam = vp.cone(radius=1, length=0.1, axis=vp.vector(0, -1, 0), pos=vp.vector(0, -2.4, 0), color=vp.vector(1, 0, 1), opacity=0.5) while True: while port.inWaiting() == 0: pass read_string = port.readline().decode("utf-8") data_array = read_string.split(',') distanceF = float(data_array[0]) print(distanceF) center = distanceF - 2.4 rad = distanceF*tan(pi / 6.0) if distanceF > 40: vp.scene.range = 40 us.pos.y = -39 t.pos.y = -39 r.pos.y = -39 center = center - 36
import math vec_o = vp.vector(0, 0, 0) vec_i = vp.vector(10, 0, 0) vec_j = vp.vector(0, 10, 0) vec_k = vp.vector(0, 0, 10) rod_radius = vp.mag(vec_i) * 0.01 # 0.01 x_rod = vp.cylinder(pos=vec_o, axis=vec_i, radius=rod_radius, color=vp.color.red) x_cone = vp.cone(pos=vec_i, axis=0.1 * vec_i, radius=vp.mag(vec_i) * 0.03, color=vp.color.red) x_axis_text = vp.text(text='x', pos=x_cone.pos + 0.1 * vec_i, color=vp.color.red) y_rod = vp.cylinder(pos=vec_o, axis=vec_j, radius=rod_radius, color=vp.color.cyan) y_cone = vp.cone(pos=vec_j, axis=vp.vector(0, vp.mag(vec_i) * 0.1, 0), radius=vp.mag(vec_j) * 0.03, color=vp.color.cyan)
from lyte import say, whereami, blurt from vpython import box, cone, color import makemyVPHTML if whereami(__name__).visible: box() cone(color=color.orange) say('say') print('print') blurt('blurt')
def _create_hab(self, entity: Entity, texture: str) -> \ vpython.compound: def vertex(x: float, y: float, z: float) -> vpython.vertex: return vpython.vertex(pos=vpython.vector(x, y, z)) # See the docstring of ThreeDeeObj._create_obj for why the dimensions # that define the shape of the habitat will not actually directly # translate to world-space. body = vpython.cylinder(pos=vpython.vec(0, 0, 0), axis=vpython.vec(-5, 0, 0), radius=10) head = vpython.cone(pos=vpython.vec(0, 0, 0), axis=vpython.vec(2, 0, 0), radius=10) wing = vpython.triangle(v0=vertex(0, 0, 0), v1=vertex(-5, 30, 0), v2=vertex(-5, -30, 0)) wing2 = vpython.triangle(v0=vertex(0, 0, 0), v1=vertex(-5, 0, 30), v2=vertex(-5, 0, -30)) hab = vpython.compound([body, head, wing, wing2], make_trail=True, texture=texture) hab.axis = calc.angle_to_vpy(entity.heading) hab.radius = entity.r / 2 hab.shininess = 0.1 hab.length = entity.r * 2 boosters: List[vpython.cylinder] = [] body_radius = entity.r / 8 for quadrant in range(0, 4): # Generate four SRB bodies. normal = vpython.rotate(vpython.vector(0, 1, 1).hat, angle=quadrant * vpython.radians(90), axis=vpython.vector(1, 0, 0)) boosters.append( vpython.cylinder(radius=self.BOOSTER_RADIUS, pos=(self.BOOSTER_RADIUS + body_radius) * normal)) boosters.append( vpython.cone( radius=self.BOOSTER_RADIUS, length=0.2, pos=((self.BOOSTER_RADIUS + body_radius) * normal + vpython.vec(1, 0, 0)))) # Append an invisible point to shift the boosters down the fuselage. # For an explanation of why that matters, read the # ThreeDeeObj._create_obj docstring (and if that doesn't make sense, # get in touch with Patrick M please hello hi I'm always free!) boosters.append(vpython.sphere(opacity=0, pos=vpython.vec(1.2, 0, 0))) booster_texture = texture.replace(f'{entity.name}.jpg', 'SRB.jpg') hab.boosters = vpython.compound(boosters, texture=booster_texture) hab.boosters.length = entity.r * 2 hab.boosters.axis = hab.axis parachute: List[vpython.standardAttributes] = [] string_length = entity.r * 0.5 parachute_texture = texture.replace(f'{entity.name}.jpg', 'Parachute.jpg') # Build the parachute fabric. parachute.append( vpython.extrusion( path=vpython.paths.circle(radius=0.5, up=vpython.vec(-1, 0, 0)), shape=vpython.shapes.arc(angle1=vpython.radians(5), angle2=vpython.radians(95), radius=1), pos=vpython.vec(string_length + self.PARACHUTE_RADIUS / 2, 0, 0))) parachute[0].height = self.PARACHUTE_RADIUS * 2 parachute[0].width = self.PARACHUTE_RADIUS * 2 parachute[0].length = self.PARACHUTE_RADIUS for quadrant in range(0, 4): # Generate parachute attachment lines. string = vpython.cylinder(axis=vpython.vec(string_length, self.PARACHUTE_RADIUS, 0), radius=0.2) string.rotate(angle=(quadrant * vpython.radians(90) - vpython.radians(45)), axis=vpython.vector(1, 0, 0)) parachute.append(string) parachute.append( vpython.sphere(opacity=0, pos=vpython.vec( -(string_length + self.PARACHUTE_RADIUS), 0, 0))) hab.parachute = vpython.compound(parachute, texture=parachute_texture) hab.parachute.visible = False return hab
size=vp.vector(.3, 2.5, 2.5), color=vp.color.red) vp.box(pos=vp.vector(.25, -1.4, 0), size=vp.vector(4.8, .3, 2.5), color=vp.color.red) vp.cylinder(pos=vp.vector(-2, 2, 1.25), radius=0.7, axis=vp.vector(0, 0, -2.5), color=vp.color.blue) ball = vp.sphere(pos=vp.vector(2, 1, 0), radius=0.5, color=vp.color.cyan) ptr = vp.arrow(pos=vp.vector(0, 0, 2), axis=vp.vector(2, 0, 0), color=vp.color.yellow) vp.cone(pos=vp.vector(-2, 0, 0), radius=1, length=3, color=vp.color.green, opacity=0.3) vp.ring(pos=vp.vector(.2, 0, 0), radius=.6, axis=vp.vector(1, 0, 0), thickness=0.12, color=vp.color.gray(0.4)) vp.ellipsoid(pos=vp.vector(-.3, 2, 0), color=vp.color.orange, size=vp.vector(.3, 1.5, 1.5)) vp.pyramid(pos=vp.vector(.3, 2, 0), color=vp.vector(0, 0.5, .25), size=vp.vector(0.8, 1.2, 1.2)) spring = vp.helix(pos=vp.vector(2, -1.25, 0), radius=0.3,
def processing(sats_data): import vpython as vp from math import sin,cos,pi def gravi_force(obj): difference = earth.pos - obj.pos acceleration = (const_g/(vp.mag(difference)**2))*vp.norm(difference) return acceleration def collision(obj): difference = obj.pos - earth.pos if vp.mag(difference) <= earth.radius: obj.visible = False obj.vel = vp.vec(0,0,0) earth_mass = 6*10**24 G = 6.7*10**-11 const_g = earth_mass*G earth_rad = 6371000 t=0 earth = vp.sphere(pos = vp.vec(0,0,0), radius = earth_rad, mass = earth_mass, color = vp.vec(0,1,0) ) sats = {} sats['fsat'] = vp.cone(pos = vp.vec(sats_data['fsat']['fsat_orb'],0,0), mass = sats_data['fsat']['fsat_mass'], #vel = vp.vec(0,0,0), vel = vp.vec(0,sats_data['fsat']['fsat_vel'],0), radius = 100, make_trail = True, retain = 500, color = vp.vec(1,0,0) ) sats['ssat'] = vp.cone(pos = vp.vec(-sats_data['ssat']['ssat_orb'],0,0), mass = sats_data['ssat']['ssat_mass'], #vel = vp.vec(0,0,0), vel = vp.vec(0,sats_data['ssat']['ssat_vel'],0), radius = 100, make_trail = True, retain = 500, color = vp.vec(0,0,1) ) sats['lsat'] = vp.cone(pos = vp.vec(0,earth_rad+10000,0), mass = sats_data['lsat']['lsat_mass'], acceleration = sats_data['lsat']['lsat_axel']*vp.vec(0,0.7,0.7), fuel = sats_data['lsat']['lsat_fuel'], vel = vp.vec(0,0,0), radius = 5000, make_trail = True, retain = 500, color = vp.vec(1,1,1) ) # vp.scene.follow(sats['lsat']) while True: vp.rate(24) for i in sats.values(): collision(i) i.pos += i.vel if 'fuel' in i.__dict__: if i.fuel != 0: i.fuel -= 1 i.vel += i.acceleration i.vel += gravi_force(i)
from vpython import cone,color,vector cone(axis=vector(5,3,0),radius=1)
def __init__(self, v, axis_label, axis_color, arrow_pos): # If we are drawing the axis-triad arrows # then set the vec_u 'unit vector' accordingley. # This ignores v in the argument list. if axis_label == 'x': self.vec_u = vec_i # Arrow.vec_i elif axis_label == 'y': self.vec_u = vec_j # Arrow.vec_j elif axis_label == 'z': self.vec_u = vec_k # Arrow.vec_k else: # Not drawing the axis triad # so just set tvec_u to the vector itself self.vec_u = v if axis_label in 'xyz': self.rod_radius = vp.mag(self.vec_u) * 0.01 self.cone_radius = vp.mag(self.vec_u) * 0.03 else: self.rod_radius = 0.02 self.cone_radius = 0.06 # Reduced Rod length = Rod length - Cone's axial length # Arrow length = Reduced Rod + Cone Axial Length # Use a fixed size of axis of the cone self.cone_axis = 0.1 * vp.norm(self.vec_u) # Reduce the size of the rod by the axial size of the cone self.rod = vp.cylinder(pos=arrow_pos, axis=self.vec_u - self.cone_axis, radius=self.rod_radius, color=axis_color) # Place the base of the cone at the end of rod # which has been reduced by the cone's axial length self.cone = vp.cone(pos=self.vec_u - self.cone_axis + arrow_pos, axis=self.cone_axis, radius=self.cone_radius, color=axis_color) # Note where the tip of the cone is, # which will define the starting point of # of the axis line self.cone_tip = self.vec_u + arrow_pos + 0.1 * vp.norm(self.vec_u) if axis_label in 'xyz': self.axis_text = vp.label(text=axis_label, pos=self.cone.pos + 0.1 * self.vec_u, color=axis_color, xoffset=3, yoffset=3, box=False) else: self.axis_text = vp.label(text=axis_label, pos=arrow_pos + 0.5 * self.vec_u, color=axis_color, xoffset=3, yoffset=3, box=False) self.axis_text.height = 0.6 * self.axis_text.height
texture={'file': 'grass_texture.jpg'}) # Sky vp.box(pos=vp.vector(dim_x_floor / 2, dim_z_floor / 2, dim_z_floor / 2 + 20 * 2), size=vp.vector(dim_x_floor, dim_z_floor, 1), texture={'file': 'sky_texture.jpg'}) rod = vp.cylinder(pos=vp.vector(dim_x_floor / 2, 0, dim_z_floor / 2), axis=vp.vector(0, 1, 0), radius=d / 2, color=vp.color.black, length=L - nosecone_length) nosecone = vp.cone(pos=vp.vector(dim_x_floor / 2, (L - nosecone_length), dim_z_floor / 2), axis=vp.vector(0, 1, 0), radius=d / 2, color=vp.color.black, length=nosecone_length) rocket = vp.compound([rod, nosecone]) motor = vp.cone(pos=vp.vector(dim_x_floor / 2, 0, dim_z_floor / 2), axis=vp.vector(0, -1, 0), radius=(d - 0.03) / 2, color=vp.color.red, length=0.15, make_trail=True) motor.trail_color = vp.color.red motor.rotate(u_initial_offset, axis=vp.vector(0, 0, -1)) Tmotor_pos = vp.arrow(pos=vp.vector(motor.pos.x - (d / 2 + 0.015),