def __init__(self, room_=1, beam_axis_=0, target_pos_=(0,0,0)): self.labScene = visual.display(title="7Be(d,n)8B Experiment", width=800, height=600, background=GetRGBcode(153,204,255)) axisx = visual.box(pos=(0,0,0), axis=(10.0,0,0), width=0.05, height=0.05, color=visual.color.red) axisy = visual.box(pos=(0,0,0), axis=(0,10.0,0), width=0.05, height=0.05, color=visual.color.blue) axisz = visual.box(pos=(0,0,0), axis=(0,0,10.0), width=0.05, height=0.05, color=visual.color.green) labelx = visual.label(pos=(5.0,0,0), text="Z-Axis") labely = visual.label(pos=(0,5.0,0), text="Y-Axis") labelz = visual.label(pos=(0,0,5.0), text="X-Axis") self.labScene.center = target_pos_ self.labScene.autoscale = False self.room = room_ self.beam_axis = beam_axis_ self.target_pos = target_pos_ self.Floors = [] self.Walls = [] self.Columns = [] self.Others = [] self.BuildRoom() if(self.room == 1 or self.room == 2): chamber_radius = 0.25 self.Beamline1 = visual.cylinder(pos=Translate(self.target_pos,GetCartesianCoords(chamber_radius, math.pi/2.0, DegToRad(180+self.beam_axis))), axis=ConvIM3(71.75,0,-71.75*math.tan(DegToRad(180-self.beam_axis))), radius=ConvIM(1.75), color=visual.color.blue) # East beamline self.Beamline2 = visual.cylinder(pos=Translate(self.target_pos,GetCartesianCoords(chamber_radius, math.pi/2.0, DegToRad(self.beam_axis))), axis=ConvIM3(-217.5,0,217.5*math.tan(DegToRad(180-self.beam_axis))), radius=ConvIM(1.75), color=visual.color.blue) # West beamline self.OneMeterChamber = visual.cylinder(pos=self.target_pos, axis=(0,chamber_radius*2,0), radius=chamber_radius, color=visual.color.blue) self.OneMeterChamber.pos[1] = -0.5
def addcar(self, pos, color=v.color.green, name="v"): # Creating car car = v.frame() car.start = pos car.pos = car.start car.vector = v.vector(0.05, 0, 0) car.color = color car.colorori = car.color body = v.box(frame = car, pos = (0,0,0), size = (2.4*self.thk, 0.6*self.thk, 1.4*self.thk), color = car.colorori) wheel1 = v.cylinder(frame=car, pos=(0.8*self.thk,-0.2*self.thk,0.8*self.thk), axis=(0,0,-1.6*self.thk), radius=0.25*self.thk, color=(0.6,0.6,0.6)) wheel2 = v.cylinder(frame=car, pos=(-0.8*self.thk,-0.2*self.thk,0.8*self.thk), axis=(0,0,-1.6*self.thk), radius=0.25*self.thk, color=(0.6,0.6,0.6)) head = v.convex(frame=car, color=car.colorori) head.append(pos=v.vector(0.6, 0.3, -0.7)*self.thk) head.append(pos=v.vector(0.6, 0.3, 0.7)*self.thk) head.append(pos=v.vector(-1.2, 0.3, -0.7)*self.thk) head.append(pos=v.vector(-1.2, 0.3, 0.7)*self.thk) head.append(pos=v.vector(0.4, 0.7, -0.6)*self.thk) head.append(pos=v.vector(0.4, 0.7, 0.6)*self.thk) head.append(pos=v.vector(-0.8, 0.7, -0.6)*self.thk) head.append(pos=v.vector(-0.8, 0.7, 0.6)*self.thk) # Creating Label car.vlabel = v.label(justify='center', pos=car.pos, xoffset=3*self.thk, yoffset=39*self.thk, space=3*self.thk, text=name,height=15, line=0,border=3) self.cars[name] = car self.labels[name] = car.vlabel
def setMap(self, board): # clean the board for stone in self.stones: stone.visible = False self.stones = [] for x in range(19): for y in range(19): if board[y + 1][x + 1] == 1: stone = visual.cylinder(pos = (x, y, 0), axis = (0, 0, .1), radius = .4, color = visual.color.black, frame = self) elif board[y + 1][x + 1] == 2: stone = visual.cylinder(pos = (x, y, 0), axis = (0, 0, .1), radius = .4, color = visual.color.white, frame = self) else: # 0 if(x + 1, y + 1) not in self.star: stone = visual.cylinder(pos = (x, y, 0), axis = (0, 0, 0), radius = 0, color = visual.color.black, frame = self) else: stone = visual.cylinder(pos = (x, y, 0), axis = (0, 0, .01), radius = .2, color = (.5, .5, .5), frame = self) self.stones.append(stone)
def setMap(self, board): # clean the board for stone in self.stones: stone.visible = False self.stones = [] for x in range(19): for y in range(19): if board[y + 1][x + 1] == 1: stone = visual.cylinder(pos=(x, y, 0), axis=(0, 0, .1), radius=.4, color=visual.color.black, frame=self) elif board[y + 1][x + 1] == 2: stone = visual.cylinder(pos=(x, y, 0), axis=(0, 0, .1), radius=.4, color=visual.color.white, frame=self) else: # 0 if (x + 1, y + 1) not in self.star: stone = visual.cylinder(pos=(x, y, 0), axis=(0, 0, 0), radius=0, color=visual.color.black, frame=self) else: stone = visual.cylinder(pos=(x, y, 0), axis=(0, 0, .01), radius=.2, color=(.5, .5, .5), frame=self) self.stones.append(stone)
def draw(self): import visual visual.scene.background = (0.6, 0.6, 0.6) """visual.cylinder(pos=(0, 0, 0), axis=(1000, 0, 0), radius=2, color=visual.color.red) visual.cylinder(pos=(0, 0, 0), axis=(0, 1000, 0), radius=2, color=visual.color.green) visual.cylinder(pos=(0, 0, 0), axis=(0, 0, 1000), radius=2, color=visual.color.blue)""" visual.cylinder(pos=(0, 0, -0.5 * self.cell_height), axis=(0, 0, self.cell_height), radius=self.cell_radius, color=visual.color.blue, opacity=0.25) #visual.sphere(pos=(0, 0, 0), radius=50, color=visual.color.green) for tube in self.__tubes: for i in range(len(tube) - 1): p1, p2 = [(p[2], p[1], p[0]) for p in tube[i:i + 2]] direction = [p2[i] - p1[i] for i in range(3)] visual.cylinder(pos=p1, axis=direction, radius=self.tube_radius, color=visual.color.red)
def addLine(self, start, stop, colour=None): if not Visualiser.VISUALISER_ON: return if colour == None: colour = visual.color.white axis = np.array(stop) - np.array(start) visual.cylinder(pos=start, axis=axis, radius=0.0001, color=geo.norm(colour))
def __init__ ( self, Object, h, maze = 20, color = (1,0,1) ) : R = 1 alfa = XZ_Angle ( Object.axis ) + pi/2 Vtot = Object.pos + Object.axis Vhaaks = rotate ( Object.axis, angle = pi/2, axis= Y_AXIS ) print 'Grid pars', alfa, Vtot, Vhaaks # Z-axis crossing Zxx = Vtot.z + Vtot.x * sin( alfa ) / cos ( alfa ) # X-axis crossing = PP.pos.z + PP.pos.x * cos( alfa ) / sin ( alfa ) ##Xxx = PP.pos.x + PP.pos.z * cos( alfa ) / sin( alfa ) # Calculate total length L = Zxx / sin ( alfa ) # Lines parallel to the XZ-plane M = int ( h / maze ) PA = L * norm ( Vhaaks ) Px = 0 Pz = Zxx for i in range ( M+1 ) : visual.cylinder ( pos = ( Px, i*maze, Pz ), axis = PA, radius = R, color = color ) # Lines perpendicular to the XZ-plane N = int ( L / maze ) dPz = - L * sin ( alfa ) / N dPx = L * cos ( alfa )/ N for i in range ( N+1 ) : visual.cylinder ( pos = ( Px + i*dPx, 0, Pz + i*dPz ), axis = h*Y_AXIS, radius = R, color = color )
def __init__(self, pos=(12,-16,8), axis=(0,5,1), radius=6, length=20): """ Construct it with a preset or given geometry. """ # calibration (see: calibrate(value)) self.zero = 0 self.correction = 0 # a cylinders length MUST NEVER be '0' in pvisual ... # and in our case not below the zero point: empty is empty.. if length <= 0: length = 0.001 # color and material glass_color = (0,1,1) liquid_color = (0,0.8,1) glass_opacity = 0.5 liquid_opacity = 0.5 glass_material = materials.rough liquid_material = materials.rough # visualize the empty container self.glass = cylinder(pos=pos, axis=axis, radius=radius, length=length,\ color=glass_color, opacity=glass_opacity,\ material=glass_material) # visualize the liquid (just a little to start with) self.liquid = cylinder(pos=pos, axis=axis, radius=radius, length=.1,\ color=liquid_color, opacity=liquid_opacity,\ material=liquid_material) # add a label p = self.calc_label_pos(pos) self.label = label(pos=p, text='W: 0.0cm')
def __init__(self,num_of_disks,num_of_rods): self.max_disk_radius = 1.0 self.disk_thickness = 0.2 self.rod_height = self.disk_thickness * (num_of_disks + 1) self.disks = [visual.cylinder(radius=self.max_disk_radius*(i+2)/(num_of_disks+1), length=self.disk_thickness, axis=(0,0,1), color=(0.0,0.5,1.0), material=visual.materials.wood) \ for i in range(num_of_disks)] self.rods = [visual.cylinder(radius=self.max_disk_radius*1.0/(num_of_disks+1), material=visual.materials.plastic, color=(1.0,0.5,0.3), length=self.rod_height, axis=(0,0,1)) for i in range(num_of_rods)] for i in range(num_of_rods): self.rods[i].pos.x = self.max_disk_radius*2*(i-(num_of_rods-1)*0.5) for i in range(num_of_disks): self.set_disk_pos(disk=i,rod=0,z_order=num_of_disks-i-1) self.base = visual.box( pos=(0,0,-self.disk_thickness*0.5), length=(num_of_rods+0.5)*self.max_disk_radius*2, width=self.disk_thickness, height=self.max_disk_radius*2.5, color=(0.2,1.0,0.2), material=visual.materials.wood)
def addLine(self, start, stop, colour=None, opacity=1., material=None): if not VISUAL_INSTALLED: return if colour == None: colour = visual.color.white axis = np.array(stop) - np.array(start) visual.cylinder(pos=start, axis=axis, radius=0.0001, color=geo.norm(colour), opacity=opacity, material=material)
def draw(self): import visual visual.scene.background = (0.6, 0.6, 0.6) """visual.cylinder(pos=(0, 0, 0), axis=(1000, 0, 0), radius=2, color=visual.color.red) visual.cylinder(pos=(0, 0, 0), axis=(0, 1000, 0), radius=2, color=visual.color.green) visual.cylinder(pos=(0, 0, 0), axis=(0, 0, 1000), radius=2, color=visual.color.blue)""" visual.cylinder(pos=(0, 0, -0.5 * self.cell_height), axis=(0, 0, self.cell_height), radius=self.cell_radius, color=visual.color.blue, opacity=0.25) #visual.sphere(pos=(0, 0, 0), radius=50, color=visual.color.green) for tube in self.__tubes: for i in range(len(tube) - 1): p1, p2 = [ (p[2], p[1], p[0]) for p in tube[i:i+2] ] direction = [p2[i] - p1[i] for i in range(3)] visual.cylinder(pos=p1, axis=direction, radius=self.tube_radius, color=visual.color.red)
def visualizeKvectors(SsfList): scene = visual.scene #visual.scene = visual.display() #scene = visual.scene #scene.exit = 0 #scene.fov = .5 * scene.fov #scene.range = 7 #scene.width, scene.height = 800, 800 import saiga12.util avg = saiga12.util.Averager() for kmag in SsfList.kmags(): Ssf = SsfList.SsfDict[kmag] for i, (kvec, Sk) in enumerate( zip(Ssf.kvecsOrig, Ssf.SkArraysByKvec())): avg.add(Sk) #print kvec, Sk widthfactor = .2 col = (Sk-.25)*.25 #col = Sk col = min(1., max(.1, col)) col = (col, col, col) radius = max(.05, (Sk)*widthfactor) #visual.arrow(pos=(0,0,0), axis=kvec, # shaftwidth=Sk*widthfactor, # fixedwidth=1) visual.cylinder(pos=(0,0,0), axis=kvec, color=col, radius=radius) print "mean:", avg.mean return scene
def __init__(self, joint, num, length, height=LEGS_HEIGHT, width=LEGS_WIDTH): """ """ super(Coxa3D, self).__init__(joint, num, length, height, width, (0, 1, 0)) visual.cylinder(frame=self, pos=(0, -(height+5)/2, 0), radius=(height+1)/2, axis=(0, 1, 0), length=height+5, color=visual.color.cyan) visual.box(frame=self, pos=(length/2, 0, 0), length=length, height=height, width=width , color=visual.color.red)
def frame(self, sign): self.glass = curve( pos=[ (sign * self.time, -self.time * 1.1, 0), (sign * self.time * 0.05, -self.time * 0.1, 0), (sign * self.time * 0.05, self.time * 0.1, 0), (sign * self.time, self.time * 1.1, 0), (sign * self.time, self.time * 1.15, 0), ], radius=self.time * 0.025, ) self.base = cylinder( pos=(0, sign * self.time * 1.15, 0), axis=(0, 1, 0), length=self.time * 0.1, radius=self.time * 1.2, color=(0.66, 0.46, 0.13), ) self.pole = cylinder( pos=(sign * self.time, -self.time * 1.1, 0), axis=(0, 1, 0), length=self.time * 2.3, radius=self.time * 0.06, color=(0.66, 0.46, 0.13), )
def addLine(self, start, stop, colour=None, opacity=1., material=None): if not VISUAL_INSTALLED: return if colour is None: colour = visual.color.white axis = np.array(stop) - np.array(start) visual.cylinder(pos=start, axis=axis, radius=0.0001, color=geo.norm(colour), opacity=opacity, material=material)
def __init__(self, joint, num, length, height=LEGS_HEIGHT, width=LEGS_WIDTH): """ """ super(Tibia3D, self).__init__(joint, num, length, height, width, (0, 0, 1)) visual.cylinder(frame=self, pos=(0, 0, -(width+5)/2), radius=(height+1)/2, axis=(0, 0, 1), length=width+5, color=visual.color.cyan) visual.box(frame=self, pos=(length/2, 0, 0), length=length, height=height, width=width , color=visual.color.blue) self.rotate(angle=math.radians(180), axis=self._axis)
def addRay(self, ray, colour=None, opacity=1.): if not Visualiser.VISUALISER_ON: return if isinstance(ray, Ray): if colour == None: colour = visual.color.white pos = ray.position axis = ray.direction * 5 visual.cylinder(pos=pos, axis=axis, radius=0.0001, color=norm(colour), opacity=opacity)
def addRay(self, ray, colour=None, opacity=1., material=None): if not VISUAL_INSTALLED: return if isinstance(ray, geo.Ray): if colour == None: colour = visual.color.white pos = ray.position axis = ray.direction * 5 visual.cylinder(pos=pos, axis=axis, radius=0.0001, color=geo.norm(colour), opacity=opacity, material=material)
def addRay(self, ray, colour=None, opacity=1., material=None): if not VISUAL_INSTALLED: return if isinstance(ray, geo.Ray): if colour is None: colour = visual.color.white pos = ray.position axis = ray.direction * 5 visual.cylinder(pos=pos, axis=axis, radius=0.0001, color=geo.norm(colour), opacity=opacity, material=material)
def addRay(self, ray, colour=None): if not Visualiser.VISUALISER_ON: return if isinstance(ray, geo.Ray): if colour == None: colour = visual.color.white pos = ray.position axis = ray.direction * 5 visual.cylinder(pos=pos, axis=axis, radius=0.0001, color=geo.norm(colour))
def __init__(self, index, name, colors, mRNA, protein, P0, P1, P2): self.index = index self.name = name self.pos = (index, 0, 0) self.color = colors[index] self.mRNA_amt = mRNA self.protein_amt = protein self.P0_amt = P0 self.P1_amt = P1 self.P2_amt = P2 self.f = v.frame() j = (index + 1) % 3 self.P0 = v.cylinder(display=v.scene, frame=self.f, pos=(-0.1, -1, 0), axis=(0, 0, 1), radius=SCALE * math.sqrt(PROMOTER_FACTOR), length=self.P0_amt * math.sqrt(PROMOTER_FACTOR), color=colors[j]) self.P1 = v.cylinder(display=v.scene, frame=self.f, pos=(0.0, -1, 0), axis=(0, 0, 1), radius=SCALE * math.sqrt(PROMOTER_FACTOR), length=self.P1_amt * math.sqrt(PROMOTER_FACTOR), color=colors[j]) self.P2 = v.cylinder(display=v.scene, frame=self.f, pos=(0.1, -1, 0), axis=(0, 0, 1), radius=SCALE * math.sqrt(PROMOTER_FACTOR), length=self.P2_amt * math.sqrt(PROMOTER_FACTOR), color=colors[j]) self.m = v.cylinder(display=v.scene, frame=self.f, pos=(0, 0, 0), axis=(0, 0, 1), radius=SCALE * math.sqrt(RNA_FACTOR), length=self.mRNA_amt / RNA_FACTOR, color=self.color) self.p = v.cylinder(display=v.scene, frame=self.f, pos=(0, 1, 0), axis=(0, 0, 1), radius=SCALE * math.sqrt(PROTEIN_FACTOR), length=self.protein_amt / PROTEIN_FACTOR, color=self.color) self.lab = v.label(frame=self.f, text=self.name, pos=(0, -1.5, 0), height=100, color=self.color, box=0, font='helvetica') self.f.pos = self.pos self.f.axis = (1, 0, 0)
def addLine(self, start, stop, colour=None, opacity=1.): if not Visualiser.VISUALISER_ON: return if colour is None: colour = visual.color.white colour = visual.vec(*colour) axis = np.array(stop) - np.array(start) axis = visual.vec(*axis.tolist()) start = visual.vec(*tuple(start)) visual.cylinder(pos=start, axis=axis, radius=0.0001, color=norm(colour), opacity=opacity)
def unitcell_init(a,scale): radius = 0.01*scale #initialise variable to return components = [] #draw the cylinders (one for each vector at the origin, two of each other vector from the tip of each vector, one of each vector from the sum of each pair of vectors) for i in range(3): components.append(v.cylinder(pos=(0,0,0), axis=(a[i][0],a[i][1],a[i][2]), radius=radius)) components.append(v.cylinder(pos=(a[(i+1)%3][0],a[(i+1)%3][1],a[(i+1)%3][2]), axis=(a[i][0],a[i][1],a[i][2]), radius=radius)) components.append(v.cylinder(pos=(a[(i+2)%3][0],a[(i+2)%3][1],a[(i+2)%3][2]), axis=(a[i][0],a[i][1],a[i][2]), radius=radius)) components.append(v.cylinder(pos=(a[(i+1)%3][0]+a[(i+2)%3][0],a[(i+1)%3][1]+a[(i+2)%3][1],a[(i+1)%3][2]+a[(i+2)%3][2]), axis=(a[i][0],a[i][1],a[i][2]), radius=radius)) return components
def __init__(self, target=(0,0,0), R=1, theta=0, phi=0, bar_length=1, bar_width=1, bar_height=1, include_pmt=False, bar_color=visual.color.white): self.target = target self.R = R self.theta = theta self.phi = phi self.position = Translate(self.target, GetCartesianCoords(self.R, self.theta, self.phi)) self.body = visual.box(pos=self.position, axis=(0, bar_length, 0), width=bar_width, height=bar_height, color=bar_color, material=visual.materials.emissive) if(include_pmt): self.pmt1 = visual.cylinder(pos=(bar_length/2.0,0,0), axis=(bar_length/4.0,0,0), radius=bar_width/2.0) self.pmt2 = visual.cylinder(pos=(-bar_length/2.0,0,0), axis=(-bar_length/4.0,0,0), radius=bar_width/2.0) self.rotation = [0.0, 0.0, 0.0]
def __init__ ( self, N, M, maze, normal, d, color = (1,0,1) ) : w = N * maze h = M * maze A = ( w, 0, 0 ) for i in range ( M+1 ) : print 'grid',i visual.cylinder ( pos = ( 0, i*maze, d ), axis = A, radius = 3, color = color ) A = ( 0, h, 0 ) for i in range ( N+1 ) : print 'grid',i visual.cylinder ( pos = ( i*maze, 0, d ), axis = A, radius = 3, color = color )
def addCylinder(self, cylinder, colour=None): if not Visualiser.VISUALISER_ON: return if colour == None: colour = visual.color.blue #angle, direction, point = tf.rotation_from_matrix(cylinder.transform) #axis = direction * cylinder.length position = geo.transform_point([0,0,0], cylinder.transform) axis = geo.transform_direction([0,0,1], cylinder.transform) print cylinder.transform, "Cylinder:transform" print position, "Cylinder:position" print axis, "Cylinder:axis" print colour, "Cylinder:colour" print cylinder.radius, "Cylinder:radius" visual.cylinder(pos=position, axis=axis, color=colour, radius=cylinder.radius, opacity=0.5, length = cylinder.length)
def addCylinder(self, cylinder, colour=None, opacity=1., material=None): if not VISUAL_INSTALLED: return if colour is None: colour = visual.color.blue #angle, direction, point = tf.rotation_from_matrix(cylinder.transform) #axis = direction * cylinder.length position = geo.transform_point([0,0,0], cylinder.transform) axis = geo.transform_direction([0,0,1], cylinder.transform) print(cylinder.transform, "Cylinder:transform") print(position, "Cylinder:position") print(axis, "Cylinder:axis") print(colour, "Cylinder:colour") print(cylinder.radius, "Cylinder:radius") visual.cylinder(pos=position, axis=axis, color=colour, radius=cylinder.radius, opacity=opacity, length = cylinder.length, material=material)
def draw(self): """define and render the cylinder""" temp = (self.v1 - self.v0).xyz self.cyl = cylinder(pos=self.v0.xyz, axis=vector(*temp), radius=self.radius, color=self.color)
def __init__(self, net): self.sphereList = [] #list to hold the nodes (as vPython spheres) self.rodList = [] #list to hold the edges (as vPython cylinders) self.Net = net #NetworkCreation instance passed by reference print 'Start visualising' r = 1.0 #radius of circle that nodes are in delta_theta = (2.0 * math.pi) / len( self.Net.nodeList) #calculate angle between nodes theta = 0 #start 'counter' theta at zero for N in self.Net.nodeList: sph = v.sphere(pos=v.vector(r * math.cos(theta), r * math.sin(theta), 0), radius=0.015, color=v.color.green) #for each node create a sphere in a position on the circumference of the circle self.sphereList.append(sph) #add this sphere to the list theta += delta_theta #increment the angle by the calculated delta_theta for E in self.Net.edgeList: #for each edge... pos1 = self.sphereList[E[ 0]].pos #take positions of the corresponding nodes from the sphereList pos2 = self.sphereList[E[1]].pos rod = v.cylinder(pos=pos1, axis=pos2 - pos1, radius=0.0025, color=v.color.white) #create a vPython cylinder that stretches between the two nodes self.rodList.append(rod) #add this cylinder to list
def form_bonds(atoms, dis): bonds = [] for a in atoms: for b in atoms: if abs(a.position - b.position)<dis: bonds.append(visual.cylinder(pos=a.position,axis=(b.position-a.position),radius=0.05,color=(1,0.7,0.2),opacity=0.45)) return bonds
def __init__(self): self.sphereList = [] #sphere for each node self.rodList = [] #unused self.manageRodList = [ ] #rods connecting nodes to centre management node r = 1.0 #radius of circle that nodes are in delta_theta = (2.0 * math.pi) / G.NUMNODES #angle between nodes theta = 0 self.management = v.sphere( pos=v.vector(0, 0, 0), radius=0.1, colour=v.color.blue) #management node in centre self.label = v.label( pos=(1, 1, 0), text='0') #label for amount of disparities at that point in time self.label_cum = v.label(pos=(-1, 1, 0), text='0') #cumulative total number of above for i in range(0, G.NUMNODES): circ = v.sphere(pos=v.vector(r * math.cos(theta), r * math.sin(theta), 0), radius=0.1, color=v.color.green) self.sphereList.append(circ) print 'circle no. ', i, ' coords ', r * math.cos( theta), ' ', r * math.sin(theta) theta += delta_theta rod = v.cylinder(pos=(0, 0, 0), axis=(self.sphereList[i].pos), radius=0.005, color=v.color.white) self.manageRodList.append(rod)
def __init__(self, pos=(-20, 0, 10), axis=(0, 5, 1), radius=.5, length=0): """ Construct it with a preset or given geometry. """ # calibration (see: calibrate(value)) self.zero = None # a cylinders length MUST NEVER be '0' in pvisual ... if length == 0: length = 0.000001 # color and material self.hot_color = (1, 0, 0) ### for now say: below zero this liquid is expanding... self.cold_color = (0.4, 0.4, 1) opacity = 1 material = materials.rough # visualize the reservoir self.reservoir = sphere(pos=pos, radius=radius*4, color=self.hot_color,\ opacity=opacity, material=material) # visualize the expander self.expander = cylinder(pos=pos, axis=axis, radius=radius,\ length=length, color=self.hot_color,\ opacity=opacity, material=material) # add a label p = self.calc_label_pos(pos) self.label = label(pos=p, text=u'T: 0.0\xb0C')
def sand(self): self.top = cone(pos=(0, self.time * 1.1, 0), axis=(0, -1, 0), color=(1, 1, 0)) self.bottom = cone(pos=(0, -self.time * 1.1, 0), axis=(0, 1, 0), color=(0.5, 0.5, 0)) self.falling = cylinder( pos=(0, self.time * 0.125, 0), axis=(0, -1, 0), color=(0.5, 0.5, 0), radius=self.time * 0.035 ) self.countdown = sphere(pos=(0, self.time * 1.5, 0), radius=0)
def __init__(self): self.NodeList = [] self.EdgeList = [] r = 1.0 delta_theta = (2.0 * math.pi) / len(Net.Nodes) theta = 0 for N in Net.Nodes: node = [ N.ID, v.sphere(pos=v.vector(r * math.cos(theta), r * math.sin(theta), 0), radius=0.01, color=v.color.white) ] theta += delta_theta self.NodeList.append(node) self.NodeList = dict(self.NodeList) for ind in Net.ChansIndex: pos1 = self.NodeList[Net.ChansIndex[ind][0]].pos pos2 = self.NodeList[Net.ChansIndex[ind][1]].pos ID = ind rod = v.cylinder(pos=pos1, axis=(pos2 - pos1), radius=0.0025, color=v.color.green) edge = [ind, rod] self.EdgeList.append(edge) self.EdgeList = dict(self.EdgeList)
def _handle_dfs(self, bone, parent, frame, transform_stack): # Calculate new direction and position direction = (bone.xyz_data[frame, :] - parent.xyz_data[frame, :]).tolist() pos = parent.xyz_data[frame, :].tolist() # FIXME: Seems inefficient. xdir = np.asarray(transform_stack[-1][0, :]).tolist()[0] ydir = np.asarray(transform_stack[-1][1, :]).tolist()[0] zdir = np.asarray(transform_stack[-1][2, :]).tolist()[0] if bone.name in self.bone_data: # Retrieve and update objects cyl, s, ax = self.bone_data[bone.name] cyl.pos = pos cyl.axis = direction s.pos = bone.xyz_data[frame, :].tolist() ax.update(xdir, ydir, zdir, pos) else: # Create and save objects. cyl = visual.cylinder(pos=pos, axis=direction, radius=Pose.cyl_radius) s = visual.sphere(pos=bone.xyz_data[frame, :].tolist(), radius=Pose.sphere_radius) axes = Axes(xdir, ydir, zdir, 0.3, pos=pos, width=0.01) self.bone_data[bone.name] = (cyl, s, axes)
def addCylinder(self, cylinder, colour=None, opacity=1.): if not Visualiser.VISUALISER_ON: return if colour == None: colour = visual.color.blue #angle, direction, point = tf.rotation_from_matrix(cylinder.transform) #axis = direction * cylinder.length position = transform_point([0,0,0], cylinder.transform) axis = transform_direction([0,0,1], cylinder.transform) print(cylinder.transform, "Cylinder:transform") print(position, "Cylinder:position") print(axis, "Cylinder:axis") print(colour, "Cylinder:colour") print(cylinder.radius, "Cylinder:radius") pos = vec(*tuple(position)) visual.cylinder(pos=pos, axis=axis, color=colour, radius=cylinder.radius, opacity=opacity, length = cylinder.length)
def my_arrow(pos, axis, proportion=True, shaftwidth=0.1, headwidth=2, headlength=3, color=[1.0, 1.0, 1.0]): px, py, pz = pos x, y, z = axis sw = shaftwidth length = math.sqrt(x*x + y*y + z*z) if proportion: sw *= length hl = sw*headlength/length l = 1.0 - hl lx = l*x; ly = l*y; lz = l*z cylinder_axis = [lx, ly, lz] cone_pos = [px+lx, py+ly, pz+lz] cone_axis = [hl*x, hl*y, hl*z] cone_radius = sw*headwidth visual.cylinder(pos=pos, axis=cylinder_axis, radius=sw, color=color) visual.cone(pos=cone_pos, axis=cone_axis, radius=cone_radius, color=color)
def frame(self, sign): self.glass = curve(pos=[(sign * self.time, -self.time * 1.1, 0), (sign * self.time * 0.05, -self.time * 0.1, 0), (sign * self.time * 0.05, self.time * 0.1, 0), (sign * self.time, self.time * 1.1, 0), (sign * self.time, self.time * 1.15, 0)], radius=self.time * .025) self.base = cylinder(pos=(0, sign * self.time * 1.15, 0), axis=(0, 1, 0), length=self.time * 0.1, radius=self.time * 1.2, color=(.66, .46, .13)) self.pole = cylinder(pos=(sign * self.time, -self.time * 1.1, 0), axis=(0, 1, 0), length=self.time * 2.3, radius=self.time * 0.06, color=(.66, .46, .13))
def main(): # Init some 3D stuff scene = visual.display(width=settings.SCENE_WIDTH, height=settings.SCENE_HEIGHT) ground = visual.box(axis=(0, 1, 0), pos=(0, 0, 0), length=0.1, height=500, width=500, color=visual.color.gray(0.75), opacity=0.5) def addGait(gaitClass, gaitName): gait = gaitClass(gaitName, settings.GAIT_LEGS_GROUPS[gaitName], settings.GAIT_PARAMS[gaitName]) GaitManager().add(gait) addGait(GaitTripod, "tripod") addGait(GaitTetrapod, "tetrapod") addGait(GaitRiple, "riple") addGait(GaitWave, "metachronal") addGait(GaitWave, "wave") #GaitManager().select("riple") robot = Hexapod() # Init some more 3D stuff (opt.) CoordinatesSystem3D() for legIndex, footNeutralP in robot.feetNeutralP.items(): visual.sphere(pos=(footNeutralP[0], footNeutralP[2], -footNeutralP[1]), radius=5) visual.cylinder(pos=(footNeutralP[0], footNeutralP[2], -footNeutralP[1]), axis=(0, 0, -1), radius=1, length=50) visual.cylinder(pos=(footNeutralP[0], footNeutralP[2], -footNeutralP[1]), axis=(0, 0, 1), radius=1, length=50) if legIndex == 'RR': CoordinatesSystem3D(pos=(footNeutralP[0], footNeutralP[2], -footNeutralP[1])) GaitSequencer().start() try: gamepad = Gamepad(robot) gamepad.start() except OSError: Logger().exception("main()", debug=True) keyboard = Keyboard(robot) keyboard.start() robot.setBodyPosition(z=40) robot.mainLoop() remote.stop() remote.join() GaitSequencer().stop() GaitSequencer().join()
def draw_edges(self): self.rods = [] self.line_handle = [] if not self.connect==None: self.I, self.J = np.nonzero(self.connect) for i, j in zip(self.I, self.J): pos, axis = self.pos_axis(i, j) self.rods.append(visual.cylinder(pos=pos, axis=axis, radius=self.radius))
def addCylinder(self, cylinder, colour=None, opacity=1., material=None): if not VISUAL_INSTALLED: return if colour is None: colour = visual.color.blue # angle, direction, point = tf.rotation_from_matrix(cylinder.transform) # axis = direction * cylinder.length position = Geo.transform_point([0, 0, 0], cylinder.transform) axis = Geo.transform_direction([0, 0, 1], cylinder.transform) # print cylinder.transform, "Cylinder:transform" # print position, "Cylinder:position" # print axis, "Cylinder:axis" # print colour, "Cylinder:colour" # print cylinder.radius, "Cylinder:radius" visual.cylinder(pos=position, axis=axis, color=colour, radius=cylinder.radius, opacity=opacity, length=cylinder.length, material=material)
def my_arrow(pos, axis, proportion=True, shaftwidth=0.1, headwidth=2, headlength=3, color=[1.0, 1.0, 1.0]): px, py, pz = pos x, y, z = axis sw = shaftwidth length = math.sqrt(x * x + y * y + z * z) if proportion: sw *= length hl = sw * headlength / length l = 1.0 - hl lx = l * x ly = l * y lz = l * z cylinder_axis = [lx, ly, lz] cone_pos = [px + lx, py + ly, pz + lz] cone_axis = [hl * x, hl * y, hl * z] cone_radius = sw * headwidth visual.cylinder(pos=pos, axis=cylinder_axis, radius=sw, color=color) visual.cone(pos=cone_pos, axis=cone_axis, radius=cone_radius, color=color)
def show(self): gate = cylinder(pos=(left_lane_x, self.y, 1), axis=(1, 0, 0), radius=0.4, length=lane_width, color=color.yellow(0.02)) gate.visible = True self.g = gate self.visible = True
def draw_edges(self): self.rods = [] self.line_handle = [] if not self.connect == None: self.I, self.J = np.nonzero(self.connect) for i, j in zip(self.I, self.J): pos, axis = self.pos_axis(i, j) self.rods.append( visual.cylinder(pos=pos, axis=axis, radius=self.radius))
def DefineCylinder(self, Density, Radius, Length): """Define this element as an ode Cylinder.""" if self._hasGeom: self._geom = ode.GeomCylinder(None, Radius, Length) cyl = visual.cylinder(pos=(0, 0, -Length / 2.0), axis=(0, 0, Length), radius=Radius) DisplayElement.SetDisplayObject(self, cyl) self._mass = ode.Mass() self._mass.setCylinderTotal(Density, 3, Radius, Length) # 3 is z-axis -- same as geom return self
def Draw(r, init): Error = ((NetEnergy(r) - Energy0)/Energy0) if init == 1: #Initializes the display window global pend0, pend1, pend2, rod1, rod2, ErrDisplay, scene, pend, rod scene = display(width = 800, height = 800) pend = [sphere(pos=(0,0,0), radius = .1*(l_0[0] + l_0[1]))] rod = [cylinder(pos = (r[0,0,0],r[0,0,1],0), axis = (-r[0,0,0], r[0,0,1], 0), radius = .025*(l_0[0] + l_0[1]))] for i in range(shape(r)[0]): pend.append(sphere(pos = (r[i,0,0],r[i,0,1],0), radius = .1*(l_0[0] + l_0[1]))) for i in range(1, shape(r)[0]): rod.append(cylinder(pos = (r[i,0,0],r[i,0,1],0), axis = (r[i-1,0,0]-r[i,0,0], r[i-1,0,1]-r[i,0,1],0), radius = .025*(l_0[0] + l_0[1]))) ErrDisplay = label(pos = (0, l_0[0] + l_0[1] + 2,0), text = "Error Percent: %f " % Error) else: #Redraw for steps for i in range(shape(r)[0]): pend[i+1].pos = (r[i,0,0],r[i,0,1],0) rod[0].axis = (-r[0,0,0], -r[0,0,1],0); rod[0].pos = (r[0,0,0], r[0,0,1], 0) for i in range(1, shape(r)[0]): rod[i].pos = (r[i,0,0], r[i,0,1], 0) rod[i].axis = (r[i-1,0,0]-r[i,0,0], r[i-1,0,1]-r[i,0,1],0) ErrDisplay.text = "Error Percent: %f " % Error
def addCylinder(self, cylinder, colour=None): if not Visualiser.VISUALISER_ON: return if colour == None: colour = visual.color.blue #angle, direction, point = tf.rotation_from_matrix(cylinder.transform) #axis = direction * cylinder.length position = geo.transform_point([0, 0, 0], cylinder.transform) axis = geo.transform_direction([0, 0, 1], cylinder.transform) print cylinder.transform, "Cylinder:transform" print position, "Cylinder:position" print axis, "Cylinder:axis" print colour, "Cylinder:colour" print cylinder.radius, "Cylinder:radius" visual.cylinder(pos=position, axis=axis, color=colour, radius=cylinder.radius, opacity=0.5, length=cylinder.length)
def display(cylinders,Lx,Ly): scene = visual.display(center = [Ly/2.0,.14,Lx/2.0], forward = [0,-1,0], up = [1,0,0],background=(1,1,1)) surr = visual.curve(pos=[(0,0,0),(0,0,Lx),(Ly,0,Lx),(Ly,0,0),(0,0,0)], radius=.005*Lx,color=(0,0,0)) for cyl in cylinders: x = cyl.pos[0] y = cyl.pos[1] z = 0 rod = visual.cylinder(pos=(y,z,x), axis=(0,.001,0), radius = cyl.radius, color=(200,0,0))
def sand(self): self.top = cone(pos=(0, self.time * 1.1, 0), axis=(0, -1, 0), color=(1, 1, 0)) self.bottom = cone(pos=(0, -self.time * 1.1, 0), axis=(0, 1, 0), color=(.5, .5, 0)) self.falling = cylinder(pos=(0, self.time * 0.125, 0), axis=(0, -1, 0), color=(.5, .5, 0), radius=self.time * 0.035) self.countdown = sphere(pos=(0, self.time * 1.5, 0), radius=0)
def __init__(self, A, B, I, scene): Shape.__init__(self, scene) self.A = A self.B = B self.BA = self.B - self.A self.l = self.BA.mag self.l2 = self.BA.mag2 self.I = self.BA.norm() * I self.obj = cylinder(pos = self.A, axis = self.BA, radius = 0.1, display = scene, material = materials.silver)
def __init__(self, A, B, I, scene): Shape.__init__(self, scene) self.A = A self.B = B self.BA = self.B - self.A self.l = self.BA.mag self.l2 = self.BA.mag2 self.I = self.BA.norm() * I self.obj = cylinder(pos=self.A, axis=self.BA, radius=0.1, display=scene, material=materials.silver)
def f(alfa, v0): vel_fotogramas = 25 g = 9.81 v0x = v0 * np.cos(np.deg2rad(alfa)) v0z = v0 * np.sin(np.deg2rad(alfa)) t_total = 2 * v0z / g x_final = v0x * t_total suelo = vs.box(pos=(x_final / 2., -1, 0), size=(x_final, 1, 10), color=vs.color.green) canyon = vs.cylinder(pos=(0, 0, 0), axis=(2 * np.cos(np.deg2rad(alfa)), 2 * np.sin(np.deg2rad(alfa)), 0)) bola = vs.sphere(pos=(0, 0, 0)) bola.trail = vs.curve(color=bola.color) flecha = vs.arrow(pos=(0, 0, 0), axis=(v0x, v0z, 0), color=vs.color.yellow) labelx = vs.label(pos=bola.pos, text='posicion x = 0 m', xoffset=1, yoffset=80, space=bola.radius, font='sans', box=False, height=10) labely = vs.label(pos=bola.pos, text='posicion y = 0 m', xoffset=1, yoffset=40, space=bola.radius, font='sans', box=False, height=10) t = 0 while t <= t_total: bola.pos = (v0x * t, v0z * t - 0.5 * g * t**2, 0) flecha.pos = (v0x * t, v0z * t - 0.5 * g * t**2, 0) flecha.axis = (v0x, v0z - g * t, 0) bola.trail.append(pos=bola.pos) labelx.pos = bola.pos labelx.text = 'posicion x = %s m' % str(v0x * t) labely.pos = bola.pos labely.text = 'posicion y = %s m' % str(v0z * t - 0.5 * g * t**2) t = t + t_total / 100. vs.rate(vel_fotogramas) return x_final
def animation_vp(self, t0, tn, points): if (tn - t0) < 0: raise ValueError('tn must be greater than t0') if (tn < 0) or (tn < 0) or (points < 0): raise ValueError('tn, t0, and points must be greater than 0') t = np.linspace(t0, tn, num=points) beta = self.beta(t) a_x, a_y = self.rod_a_position(t) c_x, c_y = self.piston_position(t) crank = v.arrow(pos=(0, 0, 0), axis=(1, 0, 0), color=(1, 1, 1), length=m.a, make_trail=False) connectingRod = v.arrow(pos=(0, 0, 0), axis=(-1, 0, 0), color=(0, 0, 1), length=m.b, make_trail=False) piston = v.cylinder(pos=(c_x[0], c_y[0], 0), radius=5, color=(1, 0, 0), length=10, make_trail=True) ball = v.sphere(pos=(0, 0, 0), radius=3, color=(1, 1, 1)) theta0 = beta[1] for x_a, y_a, x_c, y_c, b in zip(a_x, a_y, c_x, c_y, beta): crank.axis = (x_a, y_a, 0) connectingRod.pos = (x_a, y_a, 0) ball.pos = (x_a, y_a, 0) # Change in angular position dtheta = theta0 - b theta0 = b connectingRod.rotate(angle=dtheta, axis=(0, 0, 1)) connectingRod.pos = (x_c, y_c, 0) piston.pos = (x_c, y_c, 0) time.sleep(0.1)
def __init__(self, pos=vp.vector(0, 0, 0), axis=vp.vector(0, 1.0, 0), value=None, width=0.15, min_val=0, max_val=100., color=(1, 0, 0)): pos = vp.vector(pos) # axis = vector(axis) if value == None: value = min_val self.min = min_val self.max = max_val self.value = value self.shaft = vp.cylinder(pos=pos, axis=axis, radius=width/4.0, color=GREY) self.start = pos self.axis = axis self.control = vp.sphere( pos=self.start+(self.min+value)/(self.max-self.min)*self.axis, radius=width/2., color=color) self.label = vp.label(pos=self.control.pos, text="%0.2f" % value, opacity=0, box=0, line=0)
def add_beam(self,name,i,j): ''' Visualization for the wiggling effect when adding a beam to the structure ''' scale = 1 change = 1 unit_axis = helpers.make_unit(helpers.make_vector(i,j)) # Create the beam self.beams[name] = visual.cylinder(pos=i,axis=unit_axis, radius=MATERIAL['outside_diameter'],color=(0,1,0)) # Extrude the beam from the robot while scale <= BEAM['length']: axis = helpers.scale(scale,unit_axis) self.beams[name].axis = axis scale += change time.sleep((change / 120) * self.inverse_speed)
def __init__(self,length): self.length = length from visual import sphere, cylinder,box,color self.cylinder = cylinder(radius=0.1) #self.cylinder.axis = self.x,self.y,self.z self.sphere = sphere(radius=0.5) self.sphere.color = color.red #self.sphere.pos = self.x,self.y,self.z #self.update_pos() self.box = box(lenght=2,width=2,height=0.1) self.box.pos = 0,0,-0.1/2 #self.pos = pos self.setpos([0,length,0])
def __init__(self): self.sphereList = [] #sphere for each node self.rodList = [] #unused self.manageRodList = [] #rods connecting nodes to centre management node r = 1.0 #radius of circle that nodes are in delta_theta = (2.0*math.pi) / G.NUMNODES #angle between nodes theta = 0 self.management = v.sphere(pos=v.vector(0,0,0), radius=0.1, colour=v.color.blue) #management node in centre self.label = v.label(pos=(1,1,0), text= '0') #label for amount of disparities at that point in time self.label_cum = v.label(pos=(-1,1,0), text= '0') #cumulative total number of above for i in range(0,G.NUMNODES): circ = v.sphere(pos=v.vector(r*math.cos(theta),r*math.sin(theta),0), radius=0.1, color=v.color.green) self.sphereList.append(circ) print 'circle no. ', i, ' coords ', r*math.cos(theta), ' ', r*math.sin(theta) theta += delta_theta rod = v.cylinder(pos=(0,0,0),axis=(self.sphereList[i].pos), radius=0.005, color=v.color.white) self.manageRodList.append(rod)