Ejemplo n.º 1
0
def drawCameraFrame():  # create frame and draw its contents
    global  cam_box, cent_plane,  cam_lab, cam_tri, range_lab, linelen, fwd_line
    global fwd_arrow, mouse_line, mouse_arrow, mouse_lab, fov, range_x, cam_dist, cam_frame
    global ray
    cam_frame = vs.frame( pos = vs.vector(0,2,2,),  axis = (0,0,1))
               # NB: contents are rel to this frame.  start with camera looking "forward"
               # origin is at simulated scene.center
    fov = vs.pi/3.0  # 60 deg 
    range_x = 6  # simulates scene.range.x  
    cam_dist = range_x / vs.tan(fov/2.0)  # distance between camera and center. 
    ray = vs.vector(-20.0, 2.5, 3.0).norm()  # (unit) direction of ray vector (arbitrary)
                                         #  REL TO CAMERA FRAME
    cam_box = vs.box(frame=cam_frame, length=1.5, height=1, width=1.0, color=clr.blue,
                                                   pos=(cam_dist,0,0)) # camera-box
    cent_plane = vs.box(frame=cam_frame, length=0.01, height=range_x*1.3, width=range_x*2,
                                                    pos=(0,0,0), opacity=0.5 )  # central plane
    cam_lab = vs.label(frame=cam_frame, text= 'U', pos= (cam_dist,0,0), height= 9, xoffset= 6)
    cam_tri = vs.faces( frame=cam_frame, pos=[(0,0,0), (0,0,-range_x), (cam_dist,0,0)])
    cam_tri.make_normals()
    cam_tri.make_twosided()
    range_lab = vs.label(frame=cam_frame, text= 'R', pos= (0, 0, -range_x), height= 9, xoffset= 6)
    linelen = scene_size + vs.mag( cam_frame.axis.norm()*cam_dist + cam_frame.pos)
                                                                   # len of lines from camera
    fwd_line = drawLine( vs.vector(cam_dist,0,0), linelen, vs.vector(-1,0,0))
    fwd_arrow = vs.arrow(frame=cam_frame, axis=(-2,0,0), pos=(cam_dist, 0, 0), shaftwidth=0.08,
                                                                            color=clr.yellow)
    vs.label(frame=cam_frame, text='C', pos=(0,0,0), height=9, xoffset=6, color=clr.yellow)
    mouse_line = drawLine ( vs.vector(cam_dist,0,0), linelen, ray ) 
    mouse_arrow = vs.arrow(frame=cam_frame, axis=ray*2, pos=(cam_dist,0,0), shaftwidth=0.08,
                                                                                   color=clr.red)
    mouse_lab = vs.label(frame=cam_frame, text= 'M', height= 9, xoffset= 10, color=clr.red, 
                                pos=  -ray*(cam_dist/vs.dot(ray,(1,0,0))) + (cam_dist,0,0))
Ejemplo n.º 2
0
def draw_axes():
    global x_axis,y_axis,z_axis,axis_ball

    if x_axis:
        x_axis.visible=False
        x_axis=None
    if y_axis:
        y_axis.visible=False
        y_axis=None
    if z_axis:
        z_axis.visible=False
        z_axis=None
    if axis_ball:
        axis_ball.visible=False
        axis_ball=None


    if not axis_enabled:
        return
    use_x=min_x!=max_x
    use_y=min_y!=max_y
    use_z=min_z!=max_z

    zero_coord=(min_x / (min_x - max_x),min_y / (min_y - max_y),min_z / (min_z - max_z))

    if use_x:
        x_axis = visual.arrow(pos=zero_coord, axis=(.3,0,0), shaftwidth=0.01, color=visual.color.red)
    if use_y:
        y_axis = visual.arrow(pos=zero_coord, axis=(0,.3,0), shaftwidth=0.01, color=visual.color.green)
    if use_z:
        z_axis = visual.arrow(pos=zero_coord, axis=(0,0,.3), shaftwidth=0.01, color=visual.color.blue)
    axis_ball = visual.sphere(pos=zero_coord, radius=.02, color=visual.color.yellow)
Ejemplo n.º 3
0
    def __init__(self):
        # For converting
        self.rt_mx = np.matrix([[1, 0, 0], [0, 0, 1], [0, -1, 0]])

        self.x = visual.arrow(color=(1, 0, 0))
        self.y = visual.arrow(color=(0, 1, 0))
        self.z = visual.arrow(color=(0, 0, 1))
Ejemplo n.º 4
0
    def init_visual(self, only_wiiobj=False):
        visual_pos = ((0, 0, 0), (7,7,0), (14,14,0))
        if not only_wiiobj:
            #vpython
            visual.scene.width=self.param["width"] * 3
            visual.scene.height=self.param["height"]
            visual.scene.title = "3D WiiMote Simulation"
            visual.scene.forward = visual.vector(1,0,0) # not to error ?
            visual.scene.up = visual.vector(0,0,1)
            visual.scene.forward = visual.vector(-1,1,-1)
            visual.scene.center = (7,7,0)
            visual.scene.scale = (0.07, 0.07, 0.07)
            visual.scene.autoscale = 0
            visual.scene.x = 0
            visual.scene.y = 30
            
            self.visual["axis"] = [(visual.arrow(pos=visual_pos[i], color=visual.color.red, axis=(3,0,0), headwidth=1, shaftwidth=0.5, fixedwidth=1),
                                    visual.arrow(pos=visual_pos[i], color=visual.color.green, axis=(0,3,0), headwidth=1, shaftwidth=0.5, fixedwidth=1),
                                    visual.arrow(pos=visual_pos[i], color=visual.color.blue, axis=(0,0,3), headwidth=1, shaftwidth=0.5, fixedwidth=1))
                                   for i in xrange(3)]
            self.visual["text"] = [visual.label(text="accel", pos=(1, -1, -4), color=visual.color.white),
                                   visual.label(text="gyro", pos=(8, 6, -4), color=visual.color.white),
                                   visual.label(text="accel + gyro", pos=(15, 13, -4), color=visual.color.white),]
        self.visual["wiiobj"] = [visual.box(pos=visual_pos[i], length=2, height=6, width=1, color=visual.color.white, axis=(1,0,0)) #x=length, y=height, z=width
                                 for i in xrange(3)]

        return
Ejemplo n.º 5
0
    def Create3DModel(self, ShowInfo=True, opacity=0.9):  #False):#True):

        make_trail = True  #False#True
        self.Frame = frame(pos=self.pos,
                           make_trail=make_trail,
                           trail_type="points",
                           interval=1,
                           retain=300)  #100)

        for i in range(3):
            if i == 0: l = 15.0 / 2.
            else: l = 9.96 / 2.
            axis = np.identity(3)[i] * l  # self.CS.matrix[:,i]*l
            arrow(axis=axis,
                  color=np.identity(3)[i],
                  opacity=opacity,
                  frame=self.Frame)  #,make_trail=True)

        self.rps_vector = arrow(axis=[0, 0, -1 * 10**(-10)],
                                color=[1, 0, 0],
                                opacity=opacity,
                                frame=self.Frame)
        self.acc_vector = arrow(axis=[0, 0, -1 * 10**(-10)],
                                color=[1, 1, 0],
                                opacity=opacity,
                                frame=self.Frame)

        self.ShowInfo = ShowInfo
        if self.ShowInfo:
            self.InfoLabel = label(text="F16",
                                   frame=self.Frame,
                                   xoffset=int(1920 * 0.1),
                                   yoffset=int(1080 * 0.1))
Ejemplo n.º 6
0
    def init_visual(self, only_wiiobj=False):
        if not only_wiiobj:
            # vpython
            visual.scene.width = self.param["width"]
            visual.scene.height = self.param["height"]
            visual.scene.title = "3D WiiMote Simulation"
            visual.scene.forward = visual.vector(1, 0, 0)  # not to error ?
            visual.scene.up = visual.vector(0, 0, 1)
            visual.scene.forward = visual.vector(-1, 1, -1)
            visual.scene.autoscale = 0
            visual.scene.x = 0
            visual.scene.y = 30

            self.visual["axis"][0] = visual.arrow(
                color=visual.color.red, axis=(3, 0, 0), headwidth=1, shaftwidth=0.5, fixedwidth=1
            )
            self.visual["axis"][1] = visual.arrow(
                color=visual.color.green, axis=(0, 3, 0), headwidth=1, shaftwidth=0.5, fixedwidth=1
            )
            self.visual["axis"][2] = visual.arrow(
                color=visual.color.blue, axis=(0, 0, 3), headwidth=1, shaftwidth=0.5, fixedwidth=1
            )
        self.visual["wiiobj"] = visual.box(
            pos=(0, 0, 0), length=2, height=6, width=1, color=visual.color.white, axis=(2, 0, 0)
        )

        return
Ejemplo n.º 7
0
 def addPhoton(self, photon):
     """Draws a smallSphere with direction arrow and polariation (if data is avaliable)."""
     if not VISUAL_INSTALLED:
         return
     self.addSmallSphere(photon.position)
     visual.arrow(pos=photon.position, axis=photon.direction * 0.0005, shaftwidth=0.0003, color=visual.color.magenta, opacity=0.8)
     if photon.polarisation != None:
         visual.arrow(pos=photon.position, axis=photon.polarisation * 0.0005, shaftwidth=0.0003, color=visual.color.white, opacity=0.4 )
Ejemplo n.º 8
0
 def addPhoton(self, photon):
     """Draws a smallSphere with direction arrow and polariation (if data is avaliable)."""
     if not VISUAL_INSTALLED:
         return
     self.addSmallSphere(photon.position)
     visual.arrow(pos=photon.position, axis=photon.direction * 0.0005, shaftwidth=0.0003, color=visual.color.magenta, opacity=0.8)
     if photon.polarisation != None:
         visual.arrow(pos=photon.position, axis=photon.polarisation * 0.0005, shaftwidth=0.0003, color=visual.color.white, opacity=0.4 )
Ejemplo n.º 9
0
def show_arrow():
    if not SHOW_VISUAL:
        return

    arrow(pos=(0, 60, -1),
          axis=(5, 0, 0),
          length=100,
          shaftwidth=2,
          color=color.magenta)
Ejemplo n.º 10
0
def draw_efield(V, scale):      # draw electric field
    Ex, Ey = np.gradient(-V)
    Emag = np.sqrt(Ex*Ex + Ey*Ey)
    for i in range(2, M-1, 2):
        for j in range(2, N-1, 2):
            vp.arrow(pos=(i,j), axis=(Ex[i,j], Ey[i,j]), 
                     length=Emag[i,j]*scale)
        vp.rate(100)
    return Ex, Ey
Ejemplo n.º 11
0
    def __init__(self):
        # For converting
        self.rt_mx = np.matrix([[1, 0, 0],
                                [0, 0, 1],
                                [0, -1, 0]])

        self.x = visual.arrow(color=(1,0,0))
        self.y = visual.arrow(color=(0,1,0))
        self.z = visual.arrow(color=(0,0,1))
def plot3D():
    axis_length=10.0
    vs.xaxis=vs.arrow(pos=(-5,-5,0),axis=(axis_length,0,0),shaftwidth=0.05)
    vs.yaxis=vs.arrow(pos=(-5, -5, 0), axis=(0, axis_length, 0), shaftwidth=0.05)
    balls=[]
    for (i,j) in zip(N,t):
        balls.append(vs.sphere(pos=(((j/time)*axis_length*0.9-4.9,(i/N_O)*axis_length*0.9-4.9,0)),radius=0.2,color=vs.color.red))
    vs.xlabel = vs.label(text = "time", pos = (5, -5, 0))
    vs.ylabel = vs.label(text = "Number of people", pos = (-5,5,0))
    def plot3D(self):
		axis_length = 10.0
		xaxis = vs.arrow(pos = (-5, -5, 0), axis = (axis_length, 0, 0), shaftwidth = 0.01)
		yaxis = vs.arrow(pos = (-5, -5, 0), axis = (0, axis_length, 0), shaftwidth = 0.01)
		balls = []
		for (i, j) in zip(self.x, self.T):
			balls.append(vs.sphere(pos = ((j / self.time) * axis_length * 0.9- 4.9, (i / self.v) * axis_length * 0.9 - 4.9, 0), radius = 0.2, color = vs.color.red))
		xlabel = vs.label(text = "Time/s", pos = (5, -5, 0))
		ylabel = vs.label(text = "Displacement/m", pos = (-5, 5, 0))
Ejemplo n.º 14
0
def draw_efield(V, scale):  # draw electric field
    Ex, Ey = np.gradient(-V)
    Emag = np.sqrt(Ex * Ex + Ey * Ey)
    for i in range(2, M - 1, 2):
        for j in range(2, N - 1, 2):
            vp.arrow(pos=(i, j),
                     axis=(Ex[i, j], Ey[i, j]),
                     length=Emag[i, j] * scale)
        vp.rate(100)
    return Ex, Ey
 def plot3D(self):
     axis_length = 10.0
     xaxis = vs.arrow(pos = (-5, -5, 0), axis = (axis_length, 0, 0), shaftwidth = 0.01)
     yaxis = vs.arrow(pos = (-5, -5, 0), axis = (0, axis_length, 0), shaftwidth = 0.01)
     balls = []
     for (i, j) in zip(self.n_uranium, self.T):
         balls.append(vs.sphere(pos = ((j / self.time) * axis_length * 0.9- 4.9, (i / self.N) * axis_length * 0.9 - 4.9, 0), radius = 0.2, color = vs.color.red))
     xlabel = vs.label(text = "time", pos = (5, -5, 0))
     ylabel = vs.label(text = "Number of Nuclei", pos = (-5, 5, 0))
     while 1:
         pass
Ejemplo n.º 16
0
def animate_motion(x, k):
    # Animate using Visual-Python
    CO = zeros((n, 3))
    B2 = zeros((n, 3))
    C1 = zeros((n, 3))
    C3 = zeros((n, 3))
    CN = zeros((n, 3))

    for i, state in enumerate(x[:,:5]):
        CO[i], B2[i], C1[i], C3[i] = rd.anim(state, r)
        # Make the out of plane axis shorter since this is what control the height
        # of the cone
        B2[i] *= 0.001
        C1[i] *= r
        C3[i] *= r
        CN[i, 0] = state[3]
        CN[i, 1] = state[4]

    from visual import display, rate, arrow, curve, cone, box
    black = (0,0,0)
    red = (1, 0, 0)
    green = (0, 1, 0)
    blue = (0, 0, 1)
    white = (1, 1, 1)
    NO = (0,0,0)
    scene = display(title='Rolling disc @ %0.2f realtime'%k, width=800,
            height=800, up=(0,0,-1), uniform=1, background=white, forward=(1,0,0))
    # Inertial reference frame arrows
    N = [arrow(pos=NO,axis=(.001,0,0),color=red),
         arrow(pos=NO,axis=(0,.001,0),color=green),
         arrow(pos=NO,axis=(0,0,.001),color=blue)]
    # Two cones are used to look like a thin disc
    body1 = cone(pos=CO[0], axis=B2[0], radius=r, color=blue)
    body2 = cone(pos=CO[0], axis=-B2[0], radius=r, color=blue)
    # Body fixed coordinates in plane of disc, can't really be seen through cones
    c1 = arrow(pos=CO[0],axis=C1[0],length=r,color=red)
    c3 = arrow(pos=CO[0],axis=C3[0],length=r,color=green)
    trail = curve()
    trail.append(pos=CN[0], color=black)
    i = 1
    while i<n:
        rate(k/ts)
        body1.pos = CO[i]
        body1.axis = B2[i]
        body2.pos = CO[i]
        body2.axis = -B2[i]
        c1.pos = body1.pos
        c3.pos = body1.pos
        c1.axis = C1[i]
        c3.axis = C3[i]
        c1.up = C3[i]
        c3.up = C1[i]
        trail.append(pos=CN[i])
        i += 1
Ejemplo n.º 17
0
 def __init__ ( self, Size = 1 ) :
   XC = ( 1, 0, 0 )
   YC = ( 0, 1, 0 )
   ZC = ( 0, 0, 1 )
   L = Size
   SW = 0.01 * L
   X = visual.arrow ( axis = ( L, 0, 0 ), color = XC, shaftwidth = SW, fixedwidth = True )
   Y = visual.arrow ( axis = ( 0, L, 0 ), color = YC, shaftwidth = SW, fixedwidth = True )
   Z = visual.arrow ( axis = ( 0, 0, L ), color = ZC, shaftwidth = SW, fixedwidth = True )
   label ( pos = ( L, 0, 0 ), text = 'X', color = XC )
   label ( pos = ( 0, L, 0 ), text = 'Y', color = YC )
   label ( pos = ( 0, 0, L ), text = 'Z', color = ZC )
Ejemplo n.º 18
0
    def hexagonal(self, CAratio=1.6):
        hexagonal = visual.frame()

        base1 = visual.box(frame=hexagonal,
                           pos=(0, -CAratio / 2.0, 0),
                           size=(math.sqrt(3), 0.01, 1),
                           color=(1, 0.7, 0.2))
        base1 = base1.__copy__()
        base1.rotate(angle=math.pi * 60 / 180,
                     axis=(0, 1, 0),
                     origin=(0, 0, 0))
        base1 = base1.__copy__()
        base1.rotate(angle=math.pi * 60 / 180,
                     axis=(0, 1, 0),
                     origin=(0, 0, 0))

        base2 = visual.box(frame=hexagonal,
                           pos=(0, CAratio / 2.0, 0),
                           size=(math.sqrt(3), 0.01, 1),
                           color=(1, 0.7, 0.2))
        base2 = base2.__copy__()
        base2.rotate(angle=math.pi * 60 / 180,
                     axis=(0, 1, 0),
                     origin=(0, 0, 0))
        base2 = base2.__copy__()
        base2.rotate(angle=math.pi * 60 / 180,
                     axis=(0, 1, 0),
                     origin=(0, 0, 0))

        face = visual.box(frame=hexagonal,
                          pos=(math.sqrt(3) / 2.0, 0, 0),
                          size=(0.01, CAratio, 1),
                          color=(1, 0.7, 0.2))
        for _i in range(6):
            face = face.__copy__()
            face.rotate(angle=math.pi * 60 / 180,
                        axis=(0, 1, 0),
                        origin=(0, 0, 0))

        visual.arrow(frame=hexagonal,
                     pos=(0, CAratio / 2, 0),
                     axis=(0, 0.5, 0),
                     shaftwidth=0.1,
                     color=(1, 0, 0))

        visual.arrow(frame=hexagonal,
                     pos=(CAratio / 2, 0, 0),
                     axis=(0.5, 0, 0),
                     shaftwidth=0.1,
                     color=(0, 1, 0))

        return hexagonal
Ejemplo n.º 19
0
 def __init__(self, size=None):
     visual.frame.__init__(self)
     if not size:
         size = AxesXYZ.d_size
     self.x_axis = visual.arrow(axis=(size, 0.0, 0.0))
     self.x_axis.color = visual.color.red
     self.x_axis.frame = self
     self.y_axis = visual.arrow(axis=(0.0, size, 0.0))
     self.y_axis.color = visual.color.green
     self.y_axis.frame = self
     self.z_axis = visual.arrow(axis=(0.0, 0.0, size))
     self.z_axis.color = visual.color.blue
     self.z_axis.frame = self
     self.visible(AxesXYZ.d_visible)
     AxesXYZ.members.append(self)
Ejemplo n.º 20
0
def vector_field(r,vec,vmin,vmax,colourtype,lengthtype,scale):
	field = []
	#work out limits of phi if not provided
	if(vmin==vmax==0):
		vmin,vmax = difn.vector_min_max(vec)
		#if they're the same because all passed field values are identical
		if(vmin==vmax):
			vmin = 0
	v_unit = difn.unit_vectors(vec)	
	for i in range(len(r)):
		modv = np.sqrt(np.dot(vec[i],vec[i]))
		val = (modv-vmin)/(vmax-vmin)
		if colourtype == 'fadetoblack':
			colour = (val,val,val)
		elif colourtype == 'rainbow':
			colour = col_rainbow(val)
			opacity = 1.0
		else:
			colour = (1,1,1) #default to white if nothing is specified
		if lengthtype.__class__.__name__ == 'float' or lengthtype.__class__.__name__ == 'int':
			length = np.float(lengthtype)
		elif lengthtype == 'proportional':
			length = modv/vmax #we never want the arrows to have zero length, so effectively set vmin=0 whatever happens
		else:
			length = 1
		if length != 0:
			scalefactor = 0.3
			field.append(v.arrow(pos=r[i]-0.5*length*scale*scalefactor*v_unit[i], axis=length*scale*scalefactor*v_unit[i], color=colour)) #length needs to be determined automatically
	return field
Ejemplo n.º 21
0
 def _displayDiff(self):
     """Display arrows for where particles have moved."""
     if self.S0 is None: return
     objs = self._atoms
     S = self.S
     S0 = self.S0
     # Delete all objects:
     for i in range(len(objs)):
         objs[-1].visible = 0
         del objs[-1]
     for i in range(S.N):
         startPos = S.atompos[i]
         endPos = S0.atompos[i]
         if startPos not in self._limit:
             continue
         if startPos == endPos:
             objs.append(visual.sphere(pos=S.coords(startPos), radius=.15))
         else:
             startCoords = S.coords(startPos)
             endCoords   = S0.coords(endPos)
             dist = math.sqrt(sum((endCoords-startCoords)**2))
             if dist > S.L/2:
                 continue
             objs.append(
                 visual.arrow(pos=startCoords, axis=endCoords-startCoords,
                              shaftwidth=.1, headlength=1, fixedwidth=1
                              ))
Ejemplo n.º 22
0
def draw_crystal(r, attr, types):
	# draw atoms
	for i in range(len(r)):
		xyz,s = np.array(r[i]),np.array(attr[i])
		#choose colour depending on spin direction (make the col vector the unit vector)
		if (s[0]==0 and s[1]==0 and s[2]==0):
			col = np.array((0,0,0))
		else:
			col = s/np.sqrt(np.dot(s,s))
			#and if any are less than zero, add the complementary
			if col[0] < 0:
				col[1]-= col[0]
				col[2] -=col[0]
				col[0] = 0
			if col[1] < 0:
				col[0]-= col[1]
				col[2] -=col[1]
				col[1] = 0
			if col[2] < 0:
				col[0]-= col[2]
				col[1] -=col[2]
				col[2] = 0
		spingro = 0.2 #because mu_B is 10^-24, so we need to make it about ~10^-10 to display
		print xyz,s
		pointer = v.arrow(pos=xyz-s*spingro/2, axis=s*spingro, color=col)
		#draw spheres on the atom sites
		colour,size = atom_colours(types[i])
		pointer = v.sphere(pos=xyz, color=colour, radius=0.1*size)
Ejemplo n.º 23
0
 def plot3D(self):
     axis_length = 10.0
     xaxis = vs.arrow(pos=(-5, -5, 0),
                      axis=(axis_length, 0, 0),
                      shaftwidth=0.01)
     yaxis = vs.arrow(pos=(-5, -5, 0),
                      axis=(0, axis_length, 0),
                      shaftwidth=0.01)
     balls = []
     for (i, j) in zip(self.x, self.T):
         balls.append(
             vs.sphere(pos=((j / self.time) * axis_length * 0.9 - 4.9,
                            (i / self.v) * axis_length * 0.9 - 4.9, 0),
                       radius=0.2,
                       color=vs.color.red))
     xlabel = vs.label(text="Time/s", pos=(5, -5, 0))
     ylabel = vs.label(text="Displacement/m", pos=(-5, 5, 0))
Ejemplo n.º 24
0
def plot3D():
    axis_length = 10.0
    vs.xaxis = vs.arrow(pos=(-5, -5, 0),
                        axis=(axis_length, 0, 0),
                        shaftwidth=0.05)
    vs.yaxis = vs.arrow(pos=(-5, -5, 0),
                        axis=(0, axis_length, 0),
                        shaftwidth=0.05)
    balls = []
    for (i, j) in zip(N, t):
        balls.append(
            vs.sphere(pos=(((j / time) * axis_length * 0.9 - 4.9,
                            (i / N_O) * axis_length * 0.9 - 4.9, 0)),
                      radius=0.2,
                      color=vs.color.red))
    vs.xlabel = vs.label(text="time", pos=(5, -5, 0))
    vs.ylabel = vs.label(text="Number of people", pos=(-5, 5, 0))
Ejemplo n.º 25
0
 def __init__(self, xdir, ydir, zdir, scale, pos=(0, 0, 0), width=0.05):
     """
     TODO: Remove magic constants.
     """
     self.scale = scale
     #self.obj = visual.box(pos=self.pos, length=0.1, width=0.05, height=0.05,
     #               color=visual.color.orange)
     self.x = visual.arrow(pos=pos,
                           shaftwidth=width,
                           color=visual.color.red)
     self.y = visual.arrow(pos=pos,
                           shaftwidth=width,
                           color=visual.color.green)
     self.z = visual.arrow(pos=pos,
                           shaftwidth=width,
                           color=visual.color.blue)
     self.update(xdir, ydir, zdir)
Ejemplo n.º 26
0
    def preliminary_scan(self):
        # During the first time-step we only collect all the positions:
        # we will create an arrow for every position encountered
        i = 0  # column number
        t_old = 0.0
        self.field_size = 0
        self.arrows = []
        field_sum = [0.0, 0.0, 0.0]
        max_x = 0.0
        max_y = 0.0
        max_z = 0.0

        while True:
            self.last_line = self.file.readline()
            col = self.read_line(self.last_line)
            t = float(col[0])
            if (i > 0) & (t != t_old):
                break

            i = i + 1
            t_old = t

            # Read the postition where the field is located
            p = self.adjust_pos([float(col[1]), float(col[2]), float(col[3])])

            if abs(p[0]) > max_x:
                max_x = abs(p[0])
            if abs(p[1]) > max_y:
                max_y = abs(p[1])
            if abs(p[2]) > max_z:
                max_z = abs(p[2])

            # Read the field
            field = self.adjust_vector([float(col[4]), float(col[5]), float(col[6])])
            field_sum[0] += field[0]
            field_sum[1] += field[1]
            field_sum[2] += field[2]

            if random.random() <= self.decimate:
                sph = visual.sphere(color=self.pnt_col, pos=p, radius=self.pnt_radius)
                arr = visual.arrow(color=self.arrow_col, pos=p, axis=field, shaftwidth=self.arrow_shaftwidth)
                on = True
            else:
                sph = None
                arr = None
                on = False

            self.arrows.append([on, p, arr, sph])
            self.field_size += 1

        self.max_abs_coords = [max_x, max_y, max_z]
        self.t_old = t

        # Now we calculate the mean magnetization
        self.field_mean[0] = field_sum[0] / self.field_size
        self.field_mean[1] = field_sum[1] / self.field_size
        self.field_mean[2] = field_sum[2] / self.field_size
        self.first_scan = True
Ejemplo n.º 27
0
    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)
Ejemplo n.º 28
0
def trunk(pad=None):
    pobj = pdict[pad.name]
    trcolor = (0.0, 0.9, 0.9)
    trobj = visual.arrow(pos=visual.vector(0, 0, 0),
                         axis=pobj.pos,
                         shaftwidth=ARROWWIDTH * 3,
                         fixedwidth=True,
                         color=trcolor)
    trobj.visible = True
 def showArrow():
     for key in self.net.neuron_to_neuron_weight:
         from_neuron=key[:key.find('_to_')]
         to_neuron=key[key.find('to_')+3:]
         if self.net.neuron_to_neuron_weight[key]!=None:
             delta_x=self.neuron_position[to_neuron][0]-self.neuron_position[from_neuron][0]
             delta_y=self.neuron_position[to_neuron][1]-self.neuron_position[from_neuron][1]                   
             delta_z=self.neuron_position[to_neuron][2]-self.neuron_position[from_neuron][2]                    
             pointer=visual.arrow(pos=self.neuron_position[from_neuron], axis=(delta_x,delta_y,delta_z), shaftwidth=0.1)
     
     for key in self.net.neuron_in_layer['in']:
         x=self.neuron_position[key][0]-3
         y=self.neuron_position[key][1]
         z=self.neuron_position[key][2]
         pointer=visual.arrow(pos=(x,y,z), axis=(3,0,0), shaftwidth=0.1)
         
     for key in self.net.neuron_in_layer['out']:
         pointer=visual.arrow(pos=self.neuron_position[key], axis=(3,0,0), shaftwidth=0.1)
Ejemplo n.º 30
0
def set_scene(R, r):  # create bodies, velocity arrows
    vp.display(title='Three-body motion', background=(1, 1, 1))
    body, vel = [], []  # bodies, vel arrows
    c = [(1, 0, 0), (0, 1, 0), (0, 0, 1), (0, 0, 0)]  # RGB colors
    for i in range(3):
        body.append(vp.sphere(pos=r[i], radius=R, color=c[i], make_trail=1))
        vel.append(vp.arrow(pos=body[i].pos, shaftwidth=R / 2, color=c[i]))
    line, com = vp.curve(color=c[3]), vp.sphere(pos=(0, 0), radius=R / 4.)
    return body, vel, line
Ejemplo n.º 31
0
def set_scene(R, r):        # create bodies, velocity arrows
    vp.display(title='Three-body motion', background=(1,1,1))
    body, vel = [], []      # bodies, vel arrows
    c = [(1,0,0), (0,1,0), (0,0,1), (0,0,0)]    # RGB colors
    for i in range(3):
        body.append(vp.sphere(pos=r[i],radius=R,color=c[i],make_trail=1))
        vel.append(vp.arrow(pos=body[i].pos,shaftwidth=R/2,color=c[i]))
    line, com = vp.curve(color=c[3]), vp.sphere(pos=(0,0), radius=R/4.)
    return body, vel, line
Ejemplo n.º 32
0
 def draw_axes(self):
     # scene.forward = (0, 0, -1) # Default view direction
     zero = (0, 0, 0)
     x_direction = (5, 0, 0)
     y_direction = (0, 5, 0)
     z_direction = (0, 0, 5)
     # Axis X
     pointerX = arrow(pos=zero, axis=x_direction,
                      shaftwidth=0.5, color=color.red)
     labelX = label(pos=x_direction, text='X')
     # Axis Y
     pointerY = arrow(pos=zero, axis=y_direction,
                      shaftwidth=0.5, color=color.blue)
     labelY = label(pos=y_direction, text='Y')
     # Axis Z
     pointerZ = arrow(pos=zero, axis=z_direction,
                      shaftwidth=0.5, color=color.yellow)
     labelZ = label(pos=z_direction, text='Z')
Ejemplo n.º 33
0
    def InitVisuals():

        from visual import display, points, box
        window = display(title="F16 Simulation",
                         width=Resolution[0],
                         height=Resolution[1])
        window.up = np.identity(3)[2]
        window.forward = -np.ones(3)
        window.center = pos

        if FPV:
            window.range = 15 * 3  #2

        if stereo is not None:
            window.stereo = stereo

        D = 2500  #5000#2500

        #--- CS ---
        for i in range(3):
            arrow(axis=np.identity(3)[i] * 1000,
                  color=np.identity(3)[i],
                  opacity=0.75)

        #--- Point Cloud ---
        if 1:
            Points = []
            d = 500  #100
            n = int(D / d)
            for i in range(-n, n + 1):
                for j in range(-n, n + 1):
                    for k in range(0, n + 1):
                        p = np.array([i, j, k]).astype(float) * d
                        Points.append(tuple(p))  #+=list(p)
            points(pos=Points)

        if 1:
            box(width=D * 2,
                height=D * 2,
                depth=10,
                axis=-np.identity(3)[2],
                color=[0.6, 0.3, 0.15])

        return window
 def plot3D(self):
     axis_length = 10.0
     xaxis = vs.arrow(pos=(-5, -5, 0),
                      axis=(axis_length, 0, 0),
                      shaftwidth=0.01)
     yaxis = vs.arrow(pos=(-5, -5, 0),
                      axis=(0, axis_length, 0),
                      shaftwidth=0.01)
     balls = []
     for (i, j) in zip(self.N, self.t):
         balls.append(
             vs.sphere(pos=((j / self.time) * axis_length * 0.9 - 4.9,
                            (i / self.N) * axis_length * 0.9 - 4.9, 0),
                       radius=0.2,
                       color=vs.color.red))
     xlabel = vs.label(text="time[s]", pos=(5, -5, 0))
     ylabel = vs.label(text="Population", pos=(-5, 5, 0))
     while 1:
         pass
Ejemplo n.º 35
0
  def preliminary_scan(self):
    # During the first time-step we only collect all the positions:
    # we will create an arrow for every position encountered
    i = 0 # column number
    t_old = 0.0
    self.field_size = 0
    self.arrows = []
    field_sum = [0.0, 0.0, 0.0]
    max_x = 0.0
    max_y = 0.0
    max_z = 0.0

    while True:
      self.last_line = self.file.readline()
      col = self.read_line(self.last_line)
      t = float(col[0])
      if (i > 0) & (t != t_old): break;

      i = i + 1
      t_old = t

      # Read the postition where the field is located
      p = self.adjust_pos([float(col[1]), float(col[2]), float(col[3])])

      if abs(p[0]) > max_x: max_x = abs(p[0])
      if abs(p[1]) > max_y: max_y = abs(p[1])
      if abs(p[2]) > max_z: max_z = abs(p[2])

      # Read the field
      field = self.adjust_vector([float(col[4]), float(col[5]), float(col[6])])
      field_sum[0] += field[0]
      field_sum[1] += field[1]
      field_sum[2] += field[2]

      if ( random.random() <= self.decimate ):
        sph = visual.sphere(color=self.pnt_col, pos=p, radius=self.pnt_radius)
        arr = visual.arrow(color=self.arrow_col, pos=p, axis=field,
         shaftwidth=self.arrow_shaftwidth)
        on = True
      else:
        sph = None
        arr = None
        on = False

      self.arrows.append( [on, p, arr, sph] )
      self.field_size += 1

    self.max_abs_coords = [max_x, max_y, max_z]
    self.t_old = t

    # Now we calculate the mean magnetization
    self.field_mean[0] = field_sum[0] / self.field_size
    self.field_mean[1] = field_sum[1] / self.field_size
    self.field_mean[2] = field_sum[2] / self.field_size
    self.first_scan = True
Ejemplo n.º 36
0
    def hexagonal(self, CAratio=1.6):
        hexagonal = visual.frame()

        base1 = visual.box(frame=hexagonal
                           , pos=(0, -CAratio / 2.0, 0)
                           , size=(math.sqrt(3), 0.01, 1)
                           , color=(1, 0.7, 0.2))
        base1 = base1.__copy__()
        base1.rotate(angle=math.pi * 60 / 180, axis=(0, 1, 0), origin=(0, 0, 0))
        base1 = base1.__copy__()
        base1.rotate(angle=math.pi * 60 / 180, axis=(0, 1, 0), origin=(0, 0, 0))

        base2 = visual.box(frame=hexagonal
                           , pos=(0, CAratio / 2.0, 0)
                           , size=(math.sqrt(3), 0.01, 1)
                           , color=(1, 0.7, 0.2))
        base2 = base2.__copy__()
        base2.rotate(angle=math.pi * 60 / 180, axis=(0, 1, 0), origin=(0, 0, 0))
        base2 = base2.__copy__()
        base2.rotate(angle=math.pi * 60 / 180, axis=(0, 1, 0), origin=(0, 0, 0))

        face = visual.box(frame=hexagonal
                          , pos=(math.sqrt(3) / 2.0, 0, 0)
                          , size=(0.01, CAratio, 1)
                          , color=(1, 0.7, 0.2))
        for _i in range(6):
            face = face.__copy__()
            face.rotate(angle=math.pi * 60 / 180, axis=(0, 1, 0), origin=(0, 0, 0))

        visual.arrow(frame=hexagonal
                     , pos=(0, CAratio / 2, 0)
                     , axis=(0, 0.5, 0)
                     , shaftwidth=0.1
                     , color=(1, 0, 0))

        visual.arrow(frame=hexagonal
                     , pos=(CAratio / 2, 0, 0)
                     , axis=(0.5, 0, 0)
                     , shaftwidth=0.1
                     , color=(0, 1, 0))

        return hexagonal
def displayGraph(edges, color):
    arrows = []
    #print edges
    for p1, p2 in edges:
        arrow = vis.arrow(pos=p1.coordinates, axis=(p2.coordinates - p1.coordinates), color=color, shaftwidth=.0025)
        #curve = vis.curve(color=color)
        #print 'visual object coordinates: ', p1.coordinates
        #time.sleep(4)
        #curve.append([float(p1[0].coordinates), float(p1[1].coordinates), float(p1[2].coordinates)])
        #curve.append([float(p2[0].coordinates), float(p2[1].coordinates), float(p2[2].coordinates)])
        arrows.append(arrow)
    return arrows
Ejemplo n.º 38
0
def set_scene(r):     # r = init position of planet
    # draw scene, mercury, sun, info box, Runge-Lenz vector
    scene = vp.display(title='Precession of Mercury', 
                       center=(.1*0,0), background=(.2,.5,1))
    planet= vp.sphere(pos=r, color=(.9,.6,.4), make_trail=True,
                      radius=0.05, material=vp.materials.diffuse)
    sun   = vp.sphere(pos=(0,0), color=vp.color.yellow,
                      radius=0.02, material=vp.materials.emissive)
    sunlight = vp.local_light(pos=(0,0), color=vp.color.yellow)
    info = vp.label(pos=(.3,-.4), text='Angle') # angle info
    RLvec = vp.arrow(pos=(0,0), axis=(-1,0,0), length = 0.25)
    return planet, info, RLvec
Ejemplo n.º 39
0
def set_scene(R):        # draw scene, ball, trails, spin, info box
    scene = vp.display(background=(.2,.5,1), forward=(-1,-.1,-.1),
                       center=(.5*R,1,0), ambient=.4, fullscreen=1)
    floor = vp.box(pos=(R/2,0,0), length=1.1*R, height=.1, width=8, 
                   color=vp.color.orange, opacity=0.7)  # transparent 
    zone = vp.curve(pos=[(R,0,1),(R,1,1),(R,1,-1),(R,0,-1)], radius=.02)
    ball = vp.sphere(pos=(0,0,0), radius=.2, material=vp.materials.rough)
    trail = vp.curve(pos=(0,0,0), radius=0.04)
    ideal = vp.curve(pos=(0,0,0), radius=0.04, color=vp.color.green)
    spin = vp.arrow(axis=omega,pos=(0,0,0),length=1)   # omega dir
    info = vp.label(pos=(1.1*R,2,-2),text='Any key=repeat')
    return scene, ball, trail, ideal, spin
Ejemplo n.º 40
0
def PlotSpheres3(f):
  data = json.loads(open(f, "r").read())

  scene = vs.display(title='3D representation',
    x=0, y=0, width=1920, height=1080,
    autocenter=True,background=(0,0,0))

  vs.box(pos=(
    (data["SystemSize"][1][0]+data["SystemSize"][0][0])*0.5,
    (data["SystemSize"][1][1]+data["SystemSize"][0][1])*0.5,
    (data["SystemSize"][1][2]+data["SystemSize"][0][2])*0.5
  ),
  length=data["SystemSize"][1][0]-data["SystemSize"][0][0],
  height=data["SystemSize"][1][1]-data["SystemSize"][0][1],
  width= data["SystemSize"][1][2]-data["SystemSize"][0][2],
  opacity=0.2,
  color=vs.color.red)

  spheres = [vs.sphere(radius=data["SphereSize"],pos=(data["Data"][0][i], data["Data"][1][i], data["Data"][2][i])) for i in range(data["SpheresNumber"])]

  vs.arrow(pos=data["SystemSize"][0], axis=(1,0,0), shaftwidth=0.1, color=vs.color.red)
  vs.arrow(pos=data["SystemSize"][0], axis=(0,1,0), shaftwidth=0.1, color=vs.color.green)
  vs.arrow(pos=data["SystemSize"][0], axis=(0,0,1), shaftwidth=0.1, color=vs.color.blue)

  while True:
    vs.rate(60)
Ejemplo n.º 41
0
def draw_camera_frame():
    """Create frame and draw its contents."""
    global  CAM_BOX, CENT_PLANE, CAM_LAB, CAN_TRI, RANGE_LAB, LINELEN, FWD_LINE
    global FWR_ARROW, MOUSE_LINE, MOUSE_ARROW, MOUSE_LAB, FOV, RANGE_X, CAM_DIST, CAM_FRAME
    global RAY
    CAM_FRAME = vs.frame(pos=vs.vector(0, 2, 2, ), axis=(0, 0, 1))
               # NB: contents are rel to this frame.  start with camera looking "forward"
               # origin is at simulated scene.center
    FOV = vs.pi/3.0  # 60 deg
    RANGE_X = 6  # simulates scene.range.x
    CAM_DIST = RANGE_X / vs.tan(FOV/2.0)  # distance between camera and center.
    RAY = vs.vector(-20.0, 2.5, 3.0).norm()  # (unit) direction of ray vector (arbitrary)
                                         #  REL TO CAMERA FRAME
    CAM_BOX = vs.box(frame=CAM_FRAME, length=1.5, height=1, width=1.0,
                     color=CLR.blue, pos=(CAM_DIST, 0, 0)) # camera-box
    CENT_PLANE = vs.box(frame=CAM_FRAME, length=0.01, height=RANGE_X*1.3,
                        width=RANGE_X*2, pos=(0, 0, 0), opacity=0.5)  # central plane
    CAM_LAB = vs.label(frame=CAM_FRAME, text='U', pos=(CAM_DIST, 0, 0),
                       height=9, xoffset=6)
    CAN_TRI = vs.faces(frame=CAM_FRAME, pos=[
        (0, 0, 0), (0, 0, -RANGE_X), (CAM_DIST, 0, 0)])
    CAN_TRI.make_normals()
    CAN_TRI.make_twosided()
    RANGE_LAB = vs.label(frame=CAM_FRAME, text='R', pos=(0, 0, -RANGE_X),
                         height=9, xoffset=6)
    LINELEN = SCENE_SIZE + vs.mag(
        CAM_FRAME.axis.norm()*CAM_DIST + CAM_FRAME.pos)  # len of lines from camera

    FWD_LINE = draw_line(vs.vector(CAM_DIST, 0, 0), LINELEN, vs.vector(-1, 0, 0))
    FWR_ARROW = vs.arrow(frame=CAM_FRAME, axis=(-2, 0, 0), pos=(CAM_DIST, 0, 0),
                         shaftwidth=0.08, color=CLR.yellow)
    vs.label(frame=CAM_FRAME, text='C', pos=(0, 0, 0), height=9, xoffset=6,
             color=CLR.yellow)
    MOUSE_LINE = draw_line(vs.vector(CAM_DIST, 0, 0), LINELEN, RAY)
    MOUSE_ARROW = vs.arrow(frame=CAM_FRAME, axis=RAY*2, pos=(CAM_DIST, 0, 0),
                           shaftwidth=0.08, color=CLR.red)
    MOUSE_LAB = vs.label(
        frame=CAM_FRAME, text='M', height=9, xoffset=10,
        color=CLR.red,
        pos=-RAY*(CAM_DIST/vs.dot(RAY, (1, 0, 0))) + (CAM_DIST, 0, 0))
Ejemplo n.º 42
0
    def cubic(self, latticeparameters=(1, 1, 1)):
        cube = visual.frame()

        visual.box(frame=cube,
                   pos=(0, 0, 0),
                   size=latticeparameters,
                   color=(1, 0.7, 0.2))

        visual.arrow(frame=cube,
                     pos=(latticeparameters[0] / 2, 0, 0),
                     axis=(1, 0, 0),
                     shaftwidth=0.1,
                     color=(1, 0, 0))

        visual.arrow(frame=cube,
                     pos=(0, latticeparameters[0] / 2, 0),
                     axis=(0, 1, 0),
                     shaftwidth=0.1,
                     color=(0, 1, 0))

        visual.arrow(frame=cube,
                     pos=(0, 0, latticeparameters[0] / 2),
                     axis=(0, 0, 1),
                     shaftwidth=0.1,
                     color=(0, 0, 1))

        return cube
Ejemplo n.º 43
0
    def cubic(self, latticeparameters=(1, 1, 1)):
        cube = visual.frame()

        visual.box(frame=cube
                   , pos=(0, 0, 0)
                   , size=latticeparameters
                   , color=(1, 0.7, 0.2))

        visual.arrow(frame=cube
                     , pos=(latticeparameters[0] / 2, 0, 0)
                     , axis=(1, 0, 0)
                     , shaftwidth=0.1
                     , color=(1, 0, 0))

        visual.arrow(frame=cube
                     , pos=(0, latticeparameters[0] / 2, 0)
                     , axis=(0, 1, 0)
                     , shaftwidth=0.1
                     , color=(0, 1, 0))

        visual.arrow(frame=cube
                     , pos=(0, 0, latticeparameters[0] / 2)
                     , axis=(0, 0, 1)
                     , shaftwidth=0.1
                     , color=(0, 0, 1))

        return cube
Ejemplo n.º 44
0
    def __init__(self,frame_obj,visible=True,visible_label=True,scale=1.0):
        x_red   = visual.color.darkerred #(1,0.2,0.2)
        y_green = visual.color.darkergreen #(0.2,1,0.2)
        z_blue  = visual.color.darkerblue #(0.2,0.2,1)
        label_color = visual.color.fainttext #(0.7,0.7,0.7)

        self.__scale = scale
        al = self.__scale      # arrow length
        sw = self.__scale*0.01 # shaftwidth
        hw = self.__scale*0.03 # headwidth
        hl = self.__scale*0.05 # headlength

        self.__frame_obj = frame_obj
        self.__frame_axis_obj = visual.frame(frame=self.__frame_obj,pos=(0,0,0),visible=visible)        
        self.__frame_axis_label_obj = visual.frame(frame=self.__frame_axis_obj,pos=(0,0,0),visible=visible_label)
        self.__x_axis_obj = visual.arrow(frame=self.__frame_axis_obj,pos=(0,0,0),axis=(al,0,0),shaftwidth=sw,headwidth=hw,headlength=hl,color=x_red)
        self.__x_axis_label_obj = visual.label(frame=self.__frame_axis_label_obj,pos=(al,0,0),xoffset=1,font='sans',text="x",box=False,opacity=0,border=0,line=0,height=10*scale,color=label_color)
        self.__y_axis_obj = visual.arrow(frame=self.__frame_axis_obj,pos=(0,0,0), axis=(0,al,0),shaftwidth=sw,headwidth=hw,headlength=hl,color=y_green)
        self.__y_axis_label_obj = visual.label(frame=self.__frame_axis_label_obj,pos=(0,al,0),xoffset=1,font='sans',text="y",box=False,opacity=0,border=0,line=0,height=10*scale,color=label_color)
        self.__z_axis_obj = visual.arrow(frame=self.__frame_axis_obj,pos=(0,0,0), axis=(0,0,al),
                shaftwidth=sw,headwidth=hw,headlength=hl,color=z_blue)
        self.__z_axis_label_obj = visual.label(frame=self.__frame_axis_label_obj,pos=(0,0,al),xoffset=1,font='sans',text="z",box=False,opacity=0,border=0,line=0,height=10*scale,color=label_color)
Ejemplo n.º 45
0
 def createArrows(self):
     ''' Create arrow coordinates '''
     visual.arrow(pos=(0,0,0), axis=(1,0,0), radius=1, color=(0,0,1), length=3)
     visual.arrow(pos=(0,0,0), axis=(0,1,0), radius=1, color=(1,0,0), length=3)
     visual.arrow(pos=(0,0,0), axis=(0,0,1), radius=1, color=(0,1,0), length=3)
     
     visual.controls.label(pos = (3,0,0), text='x',box=False, opacity=0.0)
     visual.controls.label(pos = (0,3,0), text='y',box=False, opacity=0.0)
     visual.controls.label(pos = (0,0,3), text='z',box=False, opacity=0.0)
Ejemplo n.º 46
0
 def createArrows(self):
     ''' Create arrow coordinates '''
     visual.arrow(pos=(0,0,0), axis=(1,0,0), radius=1, color=(0,0,1), length=3)
     visual.arrow(pos=(0,0,0), axis=(0,1,0), radius=1, color=(1,0,0), length=3)
     visual.arrow(pos=(0,0,0), axis=(0,0,1), radius=1, color=(0,1,0), length=3)
     
     visual.controls.label(pos = (3,0,0), text='x',box=False, opacity=0.0)
     visual.controls.label(pos = (0,3,0), text='y',box=False, opacity=0.0)
     visual.controls.label(pos = (0,0,3), text='z',box=False, opacity=0.0)
Ejemplo n.º 47
0
def moves(fileNames):
    S = io_open(fileNames[0])
    V = viz.VizSystem(S)
    V.vizMakeBox()

    objs = []
    connMax = S.connMax
    frame_index = 0

    while True:
        print fileNames[frame_index][-20:],
        S = io_open(fileNames[frame_index])
        S.eddEnable()
        nMovesPerParticle = []

        for i in range(len(objs)):
            objs[-1].visible = 0
            del objs[-1]
        for i in range(S.N):
            nMovesPerParticle.append(0)
            pos = S.atompos[i]
            startCoords = S.coords(pos)
            for conni in range(connMax):
                if S.MLLr[pos * S.connMax + conni] == -1:
                    continue
                nMovesPerParticle[-1] += 1
                end = S.conn[pos, conni]
                endCoords = S.coords(end)

                axis = endCoords - startCoords
                if math.sqrt(numpy.sum(axis * axis)) > 5:
                    continue
                objs.append(visual.arrow(pos=startCoords, axis=axis, shaftwidth=0.1, headlength=1, fixedwidth=1))
        print "all: %.3f %.3f    mobile: %.3f %.3f " % (
            numpy.mean(nMovesPerParticle),
            numpy.std(nMovesPerParticle),
            numpy.mean([x for x in nMovesPerParticle if x > 0]),
            numpy.std([x for x in nMovesPerParticle if x > 0]),
        ),
        sys.stdout.flush()

        frame_index = getNewFrameIndex(frame_index, len(fileNames))
        if frame_index == None:
            break
    for i in range(len(objs)):
        objs[-1].visible = 0
        del objs[-1]
    visual.scene.visible = 0
    print
Ejemplo n.º 48
0
    def init_visual(self, only_wiiobj=False):
        if not only_wiiobj:
            #vpython
            visual.scene.width = self.param["width"]
            visual.scene.height = self.param["height"]
            visual.scene.title = "3D WiiMote Simulation"
            visual.scene.forward = visual.vector(1, 0, 0)  # not to error ?
            visual.scene.up = visual.vector(0, 0, 1)
            visual.scene.forward = visual.vector(-1, 1, -1)
            visual.scene.autoscale = 0
            visual.scene.x = 0
            visual.scene.y = 30

            self.visual["axis"][0] = visual.arrow(color=visual.color.red,
                                                  axis=(3, 0, 0),
                                                  headwidth=1,
                                                  shaftwidth=0.5,
                                                  fixedwidth=1)
            self.visual["axis"][1] = visual.arrow(color=visual.color.green,
                                                  axis=(0, 3, 0),
                                                  headwidth=1,
                                                  shaftwidth=0.5,
                                                  fixedwidth=1)
            self.visual["axis"][2] = visual.arrow(color=visual.color.blue,
                                                  axis=(0, 0, 3),
                                                  headwidth=1,
                                                  shaftwidth=0.5,
                                                  fixedwidth=1)
        self.visual["wiiobj"] = visual.box(pos=(0, 0, 0),
                                           length=2,
                                           height=6,
                                           width=1,
                                           color=visual.color.white,
                                           axis=(2, 0, 0))

        return
Ejemplo n.º 49
0
def update(pad=None, tname=None, fixed=False, color=None):
    pobj = pdict[pad.name]
    if fixed:
        ccolor = visual.color.orange
    else:
        ccolor = visual.color.white
    if (color is not None):
        ccolor = color
        if (color != (1.0, 1.0, 1.0)):
            #      wmult = 3   # only useful for plots showing lightning
            wmult = 1
        else:
            wmult = 1
    else:
        wmult = 1
    if (tname is not None) and (tname in pad.inputs):
        tpos = visual.vector(pad.inputs[tname][0].east,
                             pad.inputs[tname][0].north, 0.0)
        cobj = visual.arrow(pos=pobj.pos,
                            axis=(tpos - pobj.pos),
                            shaftwidth=ARROWWIDTH * wmult,
                            fixedwidth=True,
                            color=ccolor)
        pobj.cables[tname] = cobj
    else:
        for cable in pobj.cables.values():
            cable.visible = False
        pobj.cables = {}
        for tname, tdata in pad.inputs.items():
            tpos = visual.vector(tdata[0].east, tdata[0].north, 0.0)
            cobj = visual.arrow(pos=pobj.pos,
                                axis=(tpos - pobj.pos),
                                shaftwidth=ARROWWIDTH * wmult,
                                fixedwidth=True,
                                color=ccolor)
            pobj.cables[tname] = cobj
Ejemplo n.º 50
0
def drawFrameAxes(position, frame):
    visual.arrow(pos=position,
                 axis=frame[0],
                 shaftwidth=0.01,
                 color=visual.color.blue)
    visual.arrow(pos=position, axis=frame[1], shaftwidth=0.01)
    visual.arrow(pos=position,
                 axis=frame[2],
                 shaftwidth=0.01,
                 color=visual.color.red)
Ejemplo n.º 51
0
    def __init__(self, color=None, *args, **kwargs):
        """ Init CoordinatesSystem3D object
        """
        super(CoordinatesSystem3D, self).__init__(*args, **kwargs)

        if color is None:
            visual.sphere(frame=self, radius=3, color=visual.color.gray(0.5))
            visual.arrow(frame=self, axis=(1, 0,  0), length=30, color=visual.color.cyan)
            visual.arrow(frame=self, axis=(0, 0, -1), length=30, color=visual.color.magenta)
            visual.arrow(frame=self, axis=(0, 1,  0), length=30, color=visual.color.yellow)
Ejemplo n.º 52
0
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
Ejemplo n.º 53
0
def drawConn(V, S, pos, whichi=None):
    """Debug -- draw all connections on the visual, for some position

    Using visual object V, draw all connections from lattice site
    `pos` to all of it's neighbors.  If `whichi` is given, then only
    draw these connection numbers.
    """
    import visual
    start = S.coords(pos)
    for i, adjpos in enumerate(S.conn[pos]):
        if whichi is not None and i not in whichi:
            continue
        end = S.coords(adjpos)
        V._otherObjects.append(
            visual.arrow(pos=start, axis=end - start, shaftwidth=.1,
                         headlength=.5, fixedwidth=1
                         ))
Ejemplo n.º 54
0
def set_scene(r):  # r = init position of planet
    # draw scene, mercury, sun, info box, Runge-Lenz vector
    scene = vp.display(title='Precession of Mercury',
                       center=(.1 * 0, 0),
                       background=(.2, .5, 1))
    planet = vp.sphere(pos=r,
                       color=(.9, .6, .4),
                       make_trail=True,
                       radius=0.05,
                       material=vp.materials.diffuse)
    sun = vp.sphere(pos=(0, 0),
                    color=vp.color.yellow,
                    radius=0.02,
                    material=vp.materials.emissive)
    sunlight = vp.local_light(pos=(0, 0), color=vp.color.yellow)
    info = vp.label(pos=(.3, -.4), text='Angle')  # angle info
    RLvec = vp.arrow(pos=(0, 0), axis=(-1, 0, 0), length=0.25)
    return planet, info, RLvec
Ejemplo n.º 55
0
def set_scene(R):  # draw scene, ball, trails, spin, info box
    scene = vp.display(background=(.2, .5, 1),
                       forward=(-1, -.1, -.1),
                       center=(.5 * R, 1, 0),
                       ambient=.4,
                       fullscreen=1)
    floor = vp.box(pos=(R / 2, 0, 0),
                   length=1.1 * R,
                   height=.1,
                   width=8,
                   color=vp.color.orange,
                   opacity=0.7)  # transparent
    zone = vp.curve(pos=[(R, 0, 1), (R, 1, 1), (R, 1, -1), (R, 0, -1)],
                    radius=.02)
    ball = vp.sphere(pos=(0, 0, 0), radius=.2, material=vp.materials.rough)
    trail = vp.curve(pos=(0, 0, 0), radius=0.04)
    ideal = vp.curve(pos=(0, 0, 0), radius=0.04, color=vp.color.green)
    spin = vp.arrow(axis=omega, pos=(0, 0, 0), length=1)  # omega dir
    info = vp.label(pos=(1.1 * R, 2, -2), text='Any key=repeat')
    return scene, ball, trail, ideal, spin
Ejemplo n.º 56
0
    def __init__(self, windowTitle):
        # Main scene
        self.scene = visual.display(title=windowTitle)
        self.scene.range = (1.2, 1.2, 1.2)
        #self.scene.forward = (0,-1,-0.25)
        self.scene.forward = (1, 0, -0.25)
        self.scene.up = (0, 0, 1)

        # Second scene (Roll, Pitch, Yaw)
        self.scene2 = visual.display(title=windowTitle,
                                     x=0,
                                     y=0,
                                     width=500,
                                     height=200,
                                     center=(0, 0, 0),
                                     background=(0, 0, 0))
        self.scene2.range = (1, 1, 1)
        self.scene.width = 500
        self.scene.y = 200

        self.scene2.select()
        #Roll, Pitch, Yaw
        self.cil_roll = visual.cylinder(pos=(-0.4, 0, 0),
                                        axis=(0.2, 0, 0),
                                        radius=0.01,
                                        color=visual.color.red)
        self.cil_roll2 = visual.cylinder(pos=(-0.4, 0, 0),
                                         axis=(-0.2, 0, 0),
                                         radius=0.01,
                                         color=visual.color.red)
        self.cil_pitch = visual.cylinder(pos=(0.1, 0, 0),
                                         axis=(0.2, 0, 0),
                                         radius=0.01,
                                         color=visual.color.green)
        self.cil_pitch2 = visual.cylinder(pos=(0.1, 0, 0),
                                          axis=(-0.2, 0, 0),
                                          radius=0.01,
                                          color=visual.color.green)
        #cil_course = visual.cylinder(pos=(0.6,0,0),axis=(0.2,0,0),radius=0.01,color=visual.color.blue)
        #cil_course2 = visual.cylinder(pos=(0.6,0,0),axis=(-0.2,0,0),radius=0.01,color=visual.color.blue)
        self.arrow_course = visual.arrow(pos=(0.6, 0, 0),
                                         color=visual.color.cyan,
                                         axis=(-0.2, 0, 0),
                                         shaftwidth=0.02,
                                         fixedwidth=1)

        #Roll,Pitch,Yaw visual.labels
        visual.label(pos=(-0.4, 0.3, 0), text="Roll", box=0, opacity=0)
        visual.label(pos=(0.1, 0.3, 0), text="Pitch", box=0, opacity=0)
        visual.label(pos=(0.55, 0.3, 0), text="Yaw", box=0, opacity=0)

        visual.label(pos=(0.6, 0.22, 0),
                     text="N",
                     box=0,
                     opacity=0,
                     color=visual.color.yellow)
        visual.label(pos=(0.6, -0.22, 0),
                     text="S",
                     box=0,
                     opacity=0,
                     color=visual.color.yellow)
        visual.label(pos=(0.38, 0, 0),
                     text="W",
                     box=0,
                     opacity=0,
                     color=visual.color.yellow)
        visual.label(pos=(0.82, 0, 0),
                     text="E",
                     box=0,
                     opacity=0,
                     color=visual.color.yellow)
        visual.label(pos=(0.75, 0.15, 0),
                     height=7,
                     text="NE",
                     box=0,
                     color=visual.color.yellow)
        visual.label(pos=(0.45, 0.15, 0),
                     height=7,
                     text="NW",
                     box=0,
                     color=visual.color.yellow)
        visual.label(pos=(0.75, -0.15, 0),
                     height=7,
                     text="SE",
                     box=0,
                     color=visual.color.yellow)
        visual.label(pos=(0.45, -0.15, 0),
                     height=7,
                     text="SW",
                     box=0,
                     color=visual.color.yellow)

        self.L1 = visual.label(pos=(-0.4, 0.22, 0), text="-", box=0, opacity=0)
        self.L2 = visual.label(pos=(0.1, 0.22, 0), text="-", box=0, opacity=0)
        self.L3 = visual.label(pos=(0.7, 0.3, 0), text="-", box=0, opacity=0)

        # Main scene objects
        self.scene.select()
        # Reference axis (x,y,z)
        visual.arrow(color=visual.color.green,
                     axis=(1, 0, 0),
                     shaftwidth=0.02,
                     fixedwidth=1)
        visual.arrow(color=visual.color.green,
                     axis=(0, -1, 0),
                     shaftwidth=0.02,
                     fixedwidth=1)
        visual.arrow(color=visual.color.green,
                     axis=(0, 0, -1),
                     shaftwidth=0.02,
                     fixedwidth=1)
        # visual.labels
        visual.label(pos=(0, 0, 0.8), text=windowTitle, box=0, opacity=0)
        visual.label(pos=(1, 0, 0), text="X", box=0, opacity=0)
        visual.label(pos=(0, -1, 0), text="Y", box=0, opacity=0)
        visual.label(pos=(0, 0, -1), text="Z", box=0, opacity=0)
        # IMU object
        self.platform = visual.box(length=1,
                                   height=0.05,
                                   width=1,
                                   color=visual.color.red)
        self.p_line = visual.box(length=1,
                                 height=0.08,
                                 width=0.1,
                                 color=visual.color.yellow)
        self.plat_arrow = visual.arrow(color=visual.color.green,
                                       axis=(1, 0, 0),
                                       shaftwidth=0.06,
                                       fixedwidth=1)

        self.roll = 0
        self.pitch = 0
        self.yaw = 0
x_final = 6.75
## Empezamos con visual python (vpython)
## Creamos el 'suelo'
suelo = vs.box(pos=(x_final / 2., -1, 0),
               size=(x_final, 1, 10),
               color=vs.color.green)
## Creamos el 'canon'
canyon = vs.cylinder(pos=(0, 0, 0),
                     axis=(2 * np.cos(alfa), 2 * np.sin(alfa), 0),
                     size=(0, 0, 0, 0))
## Creamos el proyectil y una linea que dejara la estela del proyectil
bola = vs.sphere(pos=(0, 0, 0), radius=0.5, color=vs.color.magenta)
bola.trail = vs.curve(color=vs.color.cyan)
## Creamos el vector que indica la direccion del movimiento (vector velocidad)
flecha = vs.arrow(pos=(0, 0, 0),
                  axis=(v0x, v0z, 0),
                  color=vs.color.yellow,
                  size=(0))
## texto (ponemos etiquetas para informar de la posicion del proyectil)
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,