def variants_on_top(self, position, variants): b = [] rr = (self.cylinder_diameter / 5.) variant_cylinder_diameter = self.cylinder_diameter * 0.635 # This variable shows the cylinder where the centers of variant circles are located. for l in range(len(variants)): if variants[l] == 1: posnew = vector( position.x + variant_cylinder_diameter * np.cos(l * (np.pi / ( (len(variants)) / 2.0))), position.y + variant_cylinder_diameter * np.sin(l * (np.pi / ( (len(variants)) / 2.0))), position.z) b.append( cylinder(pos=posnew, axis=vector(0, 0, rr - rr / 5.), color=self.circle_color_periphery[l], radius=rr + rr / 10, opacity=.7)) elif variants[l] == 2: posnew = vector( position.x + variant_cylinder_diameter * np.cos(l * (np.pi / ( (len(variants)) / 2.0))), position.y + variant_cylinder_diameter * np.sin(l * (np.pi / ( (len(variants)) / 2.0))), position.z) b.append( cylinder(pos=posnew, axis=vector(0, 0, rr - rr / 5.), color=self.circle_color_periphery[l] / 3.0, radius=rr + rr / 10, opacity=.7)) # ,height=rr-.5) return b
def create_skeleton(particles): flag = [[Seam() for y in range(NUM_COLUMNS)] for x in range(NUM_ROWS)] for r in range(NUM_ROWS): for c in range(NUM_COLUMNS): seam = flag[r][c] if r + 1 < NUM_ROWS and c + 1 < NUM_COLUMNS: seam.horiz = vp.cylinder(pos=particles[r][c].pos, axis=particles[r + 1][c].pos - particles[r][c].pos, radius=SEAM_RADIUS) seam.vertic = vp.cylinder(pos=particles[r][c].pos, axis=particles[r][c + 1].pos - particles[r][c].pos, radius=SEAM_RADIUS) elif r + 1 < NUM_ROWS: seam.horiz = vp.cylinder(pos=particles[r][c].pos, axis=particles[r + 1][c].pos - particles[r][c].pos, radius=SEAM_RADIUS) elif c + 1 < NUM_COLUMNS: seam.vertic = vp.cylinder(pos=particles[r][c].pos, axis=particles[r][c + 1].pos - particles[r][c].pos, radius=SEAM_RADIUS) return flag
def make_robot(): chassis_width = 155 # left side to right chassis_thickness = 3 # plastic thickness chassis_length = 200 # front to back wheel_thickness = 26 wheel_diameter = 70 axle_x = 30 # wheel axle from axle_z = -20 rear_castor_position = vp.vector(-80, -6, -30) rear_castor_radius = 14 rear_caster_thickness = 12 base = vp.box(length=chassis_length, height=chassis_thickness, width=chassis_width) # rotate to match body - so Z is height and Y is width base.rotate(angle=vp.radians(90), axis=vp.vector(1, 0, 0)) wheel_dist = chassis_width / 2 wheel_l = vp.cylinder(radius=wheel_diameter / 2, length=wheel_thickness, pos=vp.vector(axle_x, -wheel_dist, axle_z), axis=vp.vector(0, -1, 0)) wheel_r = vp.cylinder(radius=wheel_diameter / 2, length=wheel_thickness, pos=vp.vector(axle_x, wheel_dist, axle_z), axis=vp.vector(0, 1, 0)) rear_castor = vp.cylinder(radius=rear_castor_radius, length=rear_caster_thickness, pos=rear_castor_position, axis=vp.vector(0, 1, 0)) return vp.compound([base, wheel_l, wheel_r, rear_castor])
def __init__(self, theta, alpha, frequency): self.frequency = frequency vp.scene.width, vp.scene.height = 1000, 600 vp.scene.range = 0.25 vp.scene.title = "QubeServo2-USB rotary pendulum" # Dimensions of the rotary pendulum parts base_w, base_h, base_d = 0.102, 0.101, 0.102 # width, height, & len of base rotor_d, rotor_h = 0.0202, 0.01 # height, diameter of the rotor platform rotary_top_l, rotary_top_d = 0.032, 0.012 # height, diameter of the rotary top self.arm_l, arm_d = 0.085, 0.00325 # height, diameter of the arm self.pen_l, self.pen_d = 0.129, 0.00475 # height, diameter of the pendulum # Origin of parts arm_origin = vp.vec(0, 0, 0) self.rotary_top_origin = vp.vec(0, 0, -rotary_top_l / 2) rotor_origin = arm_origin - vp.vec(0, rotor_h + rotary_top_d / 2 - 0.0035, 0) base_origin = rotor_origin - vp.vec(0, base_h / 2, 0) # Create the part objects base = vp.box( pos=base_origin, size=vp.vec(base_w, base_h, base_d), color=vp.vec(0.45, 0.45, 0.45), ) rotor = vp.cylinder( pos=rotor_origin, axis=vp.vec(0, 1, 0), size=vp.vec(rotor_h, rotor_d, rotor_d), color=vp.color.yellow, ) self._rotary_top = vp.cylinder( pos=self.rotary_top_origin, axis=vp.vec(0, 0, 1), size=vp.vec(rotary_top_l, rotary_top_d, rotary_top_d), color=vp.color.red, ) self._arm = vp.cylinder( pos=arm_origin, axis=vp.vec(0, 0, 1), size=vp.vec(self.arm_l, arm_d, arm_d), color=vp.vec(0.7, 0.7, 0.7), ) self._pendulum = vp.cylinder( pos=self.pendulum_origin(theta), axis=vp.vec(0, 1, 0), size=vp.vec(self.pen_l, self.pen_d, self.pen_d), color=vp.color.red, ) # Rotate parts to their init orientations self._rotary_top.rotate(angle=theta, axis=vp.vec(0, 1, 0), origin=arm_origin) self._arm.rotate(angle=theta, axis=vp.vec(0, 1, 0), origin=arm_origin) self._pendulum.rotate( angle=alpha, axis=self.pendulum_axis(theta), origin=self.pendulum_origin(theta), ) self.theta, self.alpha = theta, alpha
def init_sketch(self): # draw sketch cylinder(pos=self.heart_pos, axis=self.up, color=color.white, radius=self.sketch_rad) cylinder(pos=self.heart_pos, axis=self.shoulder_pos - self.heart_pos, color=color.white, radius=self.sketch_rad)
def __init__(self, f, xmin, xmax, ymin, ymax, zmin, zmax): # The x axis is labeled y, the z axis is labeled x, and the y axis is labeled z. # This is done to mimic fairly standard practive for plotting # the z value of a function of x and y. self.f = f if not xmin: self.xmin = 0 else: self.xmin = xmin if not xmax: self.xmax = 1 else: self.xmax = xmax if not ymin: self.ymin = 0 else: self.ymin = ymin if not ymax: self.ymax = 1 else: self.ymax = ymax if not zmin: self.zmin = 0 else: self.zmin = zmin if not zmax: self.zmax = 1 else: self.zmax = zmax R = L/100 d = L-2 xaxis = vp.cylinder(pos=vp.vector(0, 0, 0), axis=vp.vector( 0, 0, d), radius=R, color=vp.color.yellow) yaxis = vp.cylinder(pos=vp.vector(0, 0, 0), axis=vp.vector( d, 0, 0), radius=R, color=vp.color.yellow) zaxis = vp.cylinder(pos=vp.vector(0, 0, 0), axis=vp.vector( 0, d, 0), radius=R, color=vp.color.yellow) k = 1.02 h = 0.05*L vp.text(pos=xaxis.pos+k*xaxis.axis, text='x', height=h, align='center', billboard=True, emissive=True) vp.text(pos=yaxis.pos+k*yaxis.axis, text='y', height=h, align='center', billboard=True, emissive=True) vp.text(pos=zaxis.pos+k*zaxis.axis, text='z', height=h, align='center', billboard=True, emissive=True) self.vertices = [] for x in range(L): for y in range(L): val = self.evaluate(x, y) self.vertices.append(self.make_vertex(x, y, val)) self.make_quads() self.make_normals()
def __init__(self, radius=10.0, bodies=[]): self.radius = radius self.bodies = bodies self.base = vis.cylinder(pos=vec(0, 0, -2), axis=vec(0, 0, 1), radius=self.radius, color=vis.color.gray(0.6)) self.top_plate = vis.box(pos=vec(0, .5, -1), length=20, height=.25, width=1, color=vis.color.red) self.bottom_plate = vis.box(pos=vec(0, -.5, -1), length=20, height=.25, width=1, color=vis.color.blue) self.polarity = "up" self.e_field = vec(0, E_mag, 0) self.e_indicator = vis.arrow(pos=vec(-11, 0, 0), axis=vec(0, 2, 0), color=vis.color.yellow) self.b_field = vec(0, 0, -B_mag) # 1 mT in -z direction self.time_label = vis.label(pixel_pos=vec(0, 0, 0), xoffset=100, yoffset=-1 * (scene.height - 30), align="left", box=True, line=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 rod(axis): """ Creates the pendulum rod. """ return cylinder(pos=vector(0, 0, 0), axis=axis, radius=0.02, color=color.red)
def create_scene(): scene = canvas(range=5) wire = cylinder(pos=vector(-10, -0.5, 0), axis=vector(20, 0, 0), radius=0.02, color=color.white) return scene
def init_upper_arm(self): # cal axis 0, 1, 2 axis_0 = self.upper_arm_axis.norm() axis_2 = self.upper_arm_subaxis.norm() axis_1 = axis_0.cross(axis_2).norm() # draw upper_arm self.upper_arm = cylinder(pos=self.shoulder_pos, axis=axis_0 * self.upper_arm_len, radius=self.upper_arm_rad, color=color.cyan, opacity=0.5) # draw xyz self.upper_arm_x = arrow(pos=self.shoulder_pos, axis=axis_0 * self.note_len, color=color.red, radius=self.sketch_rad) self.upper_arm_y = arrow(pos=self.shoulder_pos, axis=axis_1 * self.note_len, color=color.green, radius=self.sketch_rad) self.upper_arm_z = arrow(pos=self.shoulder_pos, axis=axis_2 * self.note_len, color=color.blue, radius=self.sketch_rad) # cal joint_pos self.joint_pos = self.shoulder_pos + axis_0 * self.upper_arm_len
def display_polymere_in_3D(list_pos, N, radius=0.01): """For a list of position display a rod, with vpython""" list_rod = [] sphere = v.sphere(pos=v.vector(0, 0, 0), radius=0.3, opacity=0.8) # position of first monomere for i in range(1, N + 1): rod = v.cylinder( pos=v.vector(list_pos[i - 1][0], list_pos[i - 1][1], list_pos[i - 1][2]), axis=v.vector(list_pos[i][0], list_pos[i][1], list_pos[i][2]) - v.vector(list_pos[i - 1][0], list_pos[i - 1][1], list_pos[i - 1][2]), color=v.color.red, radius=radius, opacity=0.8) list_rod.append(rod) sphere = v.sphere(pos=v.vector(list_pos[-1][0], list_pos[-1][1], list_pos[-1][2]), radius=0.3, opacity=0.8, color=v.color.green) return list_rod
def _init_anim(self): import vpython as vp l_pole = float(self.domain_param['l_pole']) r_pole = 0.05 th, _ = self.state # Init render objects on first call self._anim['canvas'] = vp.canvas(width=1000, height=600, title="Pendulum") # Joint self._anim['joint'] = vp.sphere( pos=vp.vec(0, 0, r_pole), radius=r_pole, color=vp.color.white, ) # Pole self._anim['pole'] = vp.cylinder(pos=vp.vec(0, 0, r_pole), axis=vp.vec(2 * l_pole * vp.sin(th), -2 * l_pole * vp.cos(th), 0), radius=r_pole, length=2 * l_pole, color=vp.color.blue, canvas=self._anim['canvas'])
def init_small_arm(self): # cal axis 0, 1 axis_0 = self.upper_arm_axis.norm() axis_2 = self.upper_arm_subaxis.norm() axis_1 = axis_0.cross(axis_2).norm() # draw small_arm self.small_arm = cylinder(pos=self.joint_pos, axis=axis_0 * self.small_arm_len, radius=self.small_arm_rad, color=color.cyan, opacity=0.5) self.small_arm.rotate(axis=axis_1, angle=radians(self.small_arm_flex)) # draw xyz self.small_arm_x = arrow(pos=self.joint_pos, axis=axis_0 * self.note_len, color=color.red, radius=self.sketch_rad) self.small_arm_x.rotate(axis=axis_1, angle=radians(self.small_arm_flex)) self.small_arm_y = arrow(pos=self.joint_pos, axis=axis_1 * self.note_len, color=color.green, radius=self.sketch_rad) self.small_arm_z = arrow(pos=self.joint_pos, axis=axis_2 * self.note_len, color=color.blue, radius=self.sketch_rad) self.small_arm_z.rotate(axis=axis_1, angle=radians(self.small_arm_flex))
def __init__(self, pos, ori, rad, thi, I, no_of_seg, turns=1): self.pos = pos self.ori = ori self.rad = rad self.thi = thi self.I = I self.no_of_seg = no_of_seg self.turns = turns self.ring = vp.ring(pos=self.pos, axis=self.ori, radius=self.rad, thickness=self.thi) element_length = (2 * np.pi * self.rad) / self.no_of_seg segments = [0] * (self.no_of_seg) for i in range(self.no_of_seg): theta = i * (2 * np.pi / self.no_of_seg) y = self.rad * np.cos(theta) z = self.rad * np.sin(theta) segments[i] = vp.cylinder( pos=vp.vec(self.pos.x, self.pos.y + y, self.pos.z + z), axis=element_length * vp.vec(0, -vp.sin(theta), vp.cos(theta)), radius=self.thi) segments[i].visible = False self.segments = segments print('done')
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 drawListBranch(tree, opacity = 0.5): SchindlerList = [] for br in tree: SchindlerList.append(cylinder(pos = br.pos, axis = vector(*br.drct*br.length), radius = br.radius, opacity = opacity))
def draw_robot(self): # retornar el centro de masa if self.robot_type == 0: caja = box(pos=self.initialPosition, size=self.size, color=self.color) rueda_trasera = cylinder( pos=caja.pos - vector(caja.size.x / 4, caja.size.y, caja.size.z / 4), axis=vector(0, 4, 0), radius=0.5, color=self.color) rueda_delantera = cylinder( pos=caja.pos + vector(caja.size.x / 4, -caja.size.y, -caja.size.z / 4), axis=vector(0, 4, 0), radius=0.5, color=self.color) robot = compound([caja, rueda_trasera, rueda_delantera]) elif self.robot_type == 1: cuerpo = cylinder(pos=self.initialPosition, radius=3, color=color.blue, axis=vector(0, 0, 1), opacity=1) rueda_1 = cylinder(pos=cuerpo.pos + vector(0, cuerpo.radius / 2, 0), radius=cuerpo.radius / 4, color=color.red, axis=vector(0, 1, 0), opacity=1) rueda_2 = cylinder( pos=cuerpo.pos - vector(0, cuerpo.radius / 2 + cuerpo.radius / 3, 0), radius=cuerpo.radius / 4, color=color.cyan, axis=vector(0, 1, 0), opacity=1) estabilizador = sphere( pos=cuerpo.pos + vector(cuerpo.radius / 2 + cuerpo.radius / 9, 0, 0), radius=cuerpo.radius / 4, color=color.green, axis=vector(0, 1, 0), opacity=1) robot = compound([cuerpo, rueda_1, rueda_2, estabilizador]) return robot
def __init__(self, geom, ident=None, onCanvas=v.scene): self.src = v.cylinder(display=onCanvas) (radius, height) = self.geom.getParams() self.src.radius = radius self.src.axis = (0, 0, height) Vpy_Object.__init__(self, geom, ident)
def _init_anim(self): import vpython as vp # Convert to float for VPython Lr = float(self.domain_param['Lr']) Lp = float(self.domain_param['Lp']) # Init render objects on first call self._anim['canvas'] = vp.canvas(width=800, height=600, title="Quanser Qube") scene_range = 0.2 arm_radius = 0.003 pole_radius = 0.0045 self._anim['canvas'].background = vp.color.white self._anim['canvas'].lights = [] vp.distant_light(direction=vp.vec(0.2, 0.2, 0.5), color=vp.color.white) self._anim['canvas'].up = vp.vec(0, 0, 1) self._anim['canvas'].range = scene_range self._anim['canvas'].center = vp.vec(0.04, 0, 0) self._anim['canvas'].forward = vp.vec(-2, 1.2, -1) vp.box(pos=vp.vec(0, 0, -0.07), length=0.09, width=0.1, height=0.09, color=vp.color.gray(0.5)) vp.cylinder(axis=vp.vec(0, 0, -1), radius=0.005, length=0.03, color=vp.color.gray(0.5)) # Joints self._anim['joint1'] = vp.sphere(radius=0.005, color=vp.color.white) self._anim['joint2'] = vp.sphere(radius=pole_radius, color=vp.color.white) # Arm self._anim['arm'] = vp.cylinder(radius=arm_radius, length=Lr, color=vp.color.blue) # Pole self._anim['pole'] = vp.cylinder(radius=pole_radius, length=Lp, color=vp.color.red) # Curve self._anim['curve'] = vp.curve(color=vp.color.white, radius=0.0005, retain=2000)
def draw_wire(): theta_min, theta_max = 0, 360 * DEG dtheta = (theta_max - theta_min) / 500 theta = theta_min while theta < theta_max: x0, y0 = wire_x(theta), wire_y(theta) x1, y1 = wire_x(theta + dtheta), wire_y(theta + dtheta) head = vpython.vector(x0, y0, 0) tail = vpython.vector(x1, y1, 0) vpython.cylinder( pos=tail, axis=(head - tail), radius=0.02 * WHEEL_RADIUS, texture=vpython.textures.metal, ) theta += dtheta return
def _init_anim(self): import vpython as vp l_pole = float(self.domain_param['l_pole']) l_rail = float(self.domain_param['l_rail']) # Only for animation l_cart, h_cart = 0.08, 0.08 r_pole, r_rail = 0.01, 0.005 # Get positions x, th, _, _ = self.state self._anim['canvas'] = vp.canvas(width=1000, height=600, title="Quanser Cartpole") # Rail self._anim['rail'] = vp.cylinder( pos=vp.vec(-l_rail / 2, -h_cart / 2 - r_rail, 0), # a VPython's cylinder origin is at the bottom radius=r_rail, length=l_rail, color=vp.color.white, canvas=self._anim['canvas']) # Cart self._anim['cart'] = vp.box(pos=vp.vec(x, 0, 0), length=l_cart, height=h_cart, width=h_cart / 2, color=vp.color.green, canvas=self._anim['canvas']) self._anim['joint'] = vp.sphere( pos=vp.vec(x, 0, r_pole + h_cart / 4), radius=r_pole, color=vp.color.white, ) # Pole self._anim['pole'] = vp.cylinder(pos=vp.vec(x, 0, r_pole + h_cart / 4), axis=vp.vec(2 * l_pole * vp.sin(th), -2 * l_pole * vp.cos(th), 0), radius=r_pole, length=2 * l_pole, color=vp.color.blue, canvas=self._anim['canvas'])
def __init__(self, mass, length, y_location, init_theta): ''' Create object ''' self.mass = mass self.length = length self.y_location = y_location # Moment of inertia self.inertia = 1/12. * self.mass * self.length**2 # Initialize angular position theta self.theta = init_theta * vp.pi/180 # convert to radians # Initialize angular velocity omega self.omega = init_omega # Initialize vpython objects self.rod = vp.cylinder(pos=vp.vector(self.length/2.*vp.cos(self.theta),self.y_location,-self.length/2.*vp.sin(self.theta)), axis=vp.vector(-self.length*vp.cos(self.theta),0,self.length*vp.sin(self.theta)), radius=.25,color=vp.color.red) self.string = vp.cylinder(pos=vp.vector(0,-10,0),axis=vp.vector(0,y_step*num_rods+10.,0),radius=.1,color=vp.color.white)
def middle_variant_on_top(self, position): c = [] rr = self.cylinder_diameter / 5. c.append( cylinder(pos=position, axis=vector(0, 0, rr - .1), color=self.circle_color_middle, radius=rr + rr / 10, opacity=.7)) return c
def make_capsule(R, L): parts = [] sph1 = sphere(pos=vec(R, 0, 0), radius=R, color=color.cyan, opacity=0.3) cyl = cylinder(pos=vec(R, 0, 0), axis=vec(L - 2 * R, 0, 0), radius=R, color=color.cyan, opacity=0.3) sph2 = sphere(pos=sph1.pos+cyl.axis, radius=R, color=color.cyan, opacity=0.3) parts.append(sph1) parts.append(cyl) parts.append(sph2) obj = compound(parts) return obj
def _recursiveInitGraphicsVPython(self): if not self.isRoot: # for now, ground does not need a graphics representation # create Ellipse object in OPENGL self.cylinder = cylinder(pos=vector(*(self.A_IB @ self.B_r_IB)), color=color.orange, axis=vector(self.length, 0, 0), radius=self.radius_o) # recursive call to other objects in the tree for childJoint in self.childJoints: childJoint.sucBody._recursiveInitGraphicsVPython()
def mouseclick(evt): global startbar, starttick if startbar: startbar.visible = 0 startbar = vpython.cylinder(pos=giant.pos, axis=(dwarf.pos - giant.pos), radius=3e9) if endbar: endbar.visible = 0 starttick = 50
def draw(lattice): lattice.logger.info("Hook6: Display water molecules with VPython.") lattice.logger.info(" Total number of atoms: {0}".format(len(lattice.atoms))) cellmat = lattice.repcell.mat offset = (cellmat[0] + cellmat[1] + cellmat[2]) / 2 # prepare the reverse dict waters = defaultdict(dict) for atom in lattice.atoms: resno, resname, atomname, position, order = atom if "O" in atomname: waters[order]["O"] = position - offset elif "H" in atomname: if "H0" not in waters[order]: waters[order]["H0"] = position - offset else: waters[order]["H1"] = position - offset for order, water in waters.items(): O = water["O"] H0 = water["H0"] H1 = water["H1"] lattice.vpobjects['w'].add(vp.simple_sphere(radius=0.03, pos=vp.vector(*O), color=vp.vector(1,0,0))) lattice.vpobjects['w'].add(vp.simple_sphere(radius=0.02, pos=vp.vector(*H0), color=vp.vector(0,1,1))) lattice.vpobjects['w'].add(vp.simple_sphere(radius=0.02, pos=vp.vector(*H1), color=vp.vector(0,1,1))) lattice.vpobjects['w'].add(vp.cylinder(radius=0.015, pos=vp.vector(*O), axis=vp.vector(*(H0-O)))) lattice.vpobjects['w'].add(vp.cylinder(radius=0.015, pos=vp.vector(*O), axis=vp.vector(*(H1-O)))) lattice.vpobjects['l'].add(vp.label(pos=vp.vector(*O), xoffset=30, text="{0}".format(order), visible=False)) for i,j in lattice.spacegraph.edges(data=False): if i in waters and j in waters: # edge may connect to the dopant O = waters[j]["O"] H0 = waters[i]["H0"] H1 = waters[i]["H1"] d0 = H0 - O d1 = H1 - O rr0 = np.dot(d0,d0) rr1 = np.dot(d1,d1) if rr0 < rr1 and rr0 < 0.27**2: lattice.vpobjects['a'].add(vp.arrow(shaftwidth=0.015, pos=vp.vector(*H0), axis=vp.vector(*(O-H0)), color=vp.vector(1,1,0))) if rr1 < rr0 and rr1 < 0.245**2: lattice.vpobjects['a'].add(vp.arrow(shaftwidth=0.015, pos=vp.vector(*H1), axis=vp.vector(*(O-H1)), color=vp.vector(1,1,0))) lattice.logger.info(" Tips: use keys to draw/hide layers. [3 4 5 6 7 8 a w l]") lattice.logger.info(" Tips: Type ctrl-C twice at the terminal to stop.") lattice.logger.info("Hook6: end.")
def __init__(self, R_fio, L, R_esfera, z_inicial, color): self.R_fio = R_fio self.L = L self.R_esfera = R_esfera self.x = L * sin(theta) self.y = -L * cos(theta) self.z = z_inicial self.esfera = sphere(radius=self.R_esfera, color=color, pos=vector(self.x, self.y, self.z)) self.fio = cylinder(radius=self.R_fio, axis=self.esfera.pos)
def draw_edges(vor, color=vpy.vec(.2,.2,.2), radius=0.25): """ inputs: ------- vor - (scipy.spatial.Voronoi) - a voronoi object color - (vpython.vector) - a vpython color vector radius - (float) > 0 - radius (= half thickness) of the connecting lines (cylinders) """ points_3d = vor.ridge_vertices # if len(points_3d[0]) == 2: # points = [] # for point in points_3d: # point.append(0) # print(points_3d) for points in points_3d: n = len(points) for i in range(n-1): A = vpy.vec(*vor.vertices[points[i]]) B = vpy.vec(*vor.vertices[points[(i+1)%n]]) if not -1 in points[i:i+2]: vpy.cylinder(pos=A, axis=B-A, color=color, radius=radius)
def create_cylinder(self, x, y, MIC, mut_list, prom): disks = [] a = [] disks = [ self.disk_height for i in range(int(MIC // self.disk_height)) ] + [ MIC % self.disk_height for i in range(1) if MIC % self.disk_height != 0 ] # while MIC != 0: # if MIC > self.disk_height: # disks.append(self.disk_height) # MIC -= self.disk_height # else: # disks.append(MIC) # MIC -= MIC j = .15 for i in range(len(disks)): a.append( cylinder(pos=vector(x, y, sum(disks[:i])), axis=vector(0, 0, disks[i]), radius=self.cylinder_diameter, color=color.gray(j))) # ,material=materials.unshaded j += .1 kk = vector(255.0 / 255.0, 248.0 / 255.0, 220.0 / 255.0) a.append( cylinder(pos=vector(x, y, MIC + .1), axis=vector(0, 0, .1), radius=self.cylinder_diameter * .95, color=kk)) posn = vector(x, y, MIC) b = self.variants_on_top(posn, mut_list) if prom == 1: c = self.middle_variant_on_top(posn) return a + b + c else: return a + b