ࡱ> []Z%` n&bjbjٕ Jin$, $     #######$%h((#"#  a#o#o#o#v  #o##o#o#o#  U4Y o###0 $o# )" )o# )o#o###o# $ $  Graphing in Vpython (With Credit to Bruce Sherwood and the Visual Documentation) In this section we describe features for plotting graphs with tick marks and labels. Here is a simple example of how to plot a graph: from visual.graph import * # import graphing features funct1 = gcurve(color=color.cyan) # a connected curve object for x in arange(0., 8.1, 0.1): # x goes from 0 to 8 funct1.plot(pos=(x,5.*cos(2.*x)*exp(-0.2*x))) # plot Importing fromvisual.graphmakes available all Visual objects plus the graph plotting module. The graph is autoscaled to display all the data in the window. Exercise: Now plot 3 complete cycles of a sine function with an amplitude of 2m and a wavelength of 2m centered about the origin. You can also plot points on a graph instead of a connected curve using a gvdots object. funct1 = gcurve(color=color.cyan) funct2 = gvdots(delta=0.05, color=color.blue) for x in arange(0., 8.1, 0.1): funct1.plot(pos=(x,5.*cos(2.*x)*exp(-0.2*x))) # curve funct2.plot(pos=(x,4.*cos(0.5*x)*exp(-0.1*x))) # dots In a plot operation you can specify a different color to override the original setting: mydots.plot(pos=(x1,y1), color=color.green) You can provide a list of points to be plotted, just as is the case with the ordinarycurveobject: points = [(1,2), (3,4), (-5,2), (-5,-3)] data = gdots(pos=points, color=color.blue) Creating multiple Graph Windows You can establish agdisplayto set the size, position, and title for the title bar of the graph window, specify titles for the x and y axes, and specify maximum values for each axis, before creatinggcurveor other kind of graph plotting object: graph1 = gdisplay(x=0, y=0, width=600, height=150, title='N vs. t', xtitle='t', ytitle='N', xmax=50., xmin=-20., ymax=5E3, ymin=-2E3, foreground=color.black, background=color.white) For example: from visual.graph import * # import graphing features graph1 = gdisplay() #Create Graph Display graph2 = gdisplay(y = 100) #Create 2nd Graph Display funct1 = gcurve(gdisplay = graph1,color=color.cyan) #Create a function funct2 = gdots(gdisplay = graph2, color=color.blue) for x in arange(0., 8.1, 0.1): funct1.plot(pos=(x,5.*cos(2.*x)*exp(-0.2*x))) # curve funct2.plot(pos=(x,4.*cos(0.5*x)*exp(-0.1*x))) # dots Exercise: Create graphs of the normal curve between the bounds of -5 and 5, and its first and second derivatives each in a separate window. Windows and Mouse Events Initially, there is one Visual display window namedscene. Display objects do not create windows on the screen unless they are used, so if you immediately create your own display object early in your program you will not need to worry about scene. If you simply begin creating objects such as sphere they will go into scene. display()Creates a display with the specified attributes, makes it the selected display, and returns it. For example, the following creates another Visual display window 600 by 200, with 'Graph of position' in the title bar, centered on (5,0,0) and with a background color of cyan filling the window. scene2 = display(title='Graph of position', width=600, height=200, center=(5,0,0), background=(0,1,1)) Some handy attributes of the display are: centerLocation at which the camera continually looks, even as the user rotates the position of the camera. If you changecenter, the camera moves to continue to look in the same "compass" direction toward the new center, unless you also changeforward(see next attribute). Default (0,0,0). autocenterscene.center is continuously updated to be the center of the smallest axis-aligned box containing the scene. This means that if your program moves the entire scene, the center of that scene will continue to be centered in the window. forward Vector pointing in the same direction as the camera looks (that is, from the current camera location, given by scene.mouse.camera, toward scene.center). The user rotation controls, when active, will change this vector continuously. Whenforwardis changed, the camera position changes to continue looking atcenter. Default (0,0,-1). rangeThe extent of the region of interest away fromcenteralong each axis. This is always 1.0/scale, so use eitherrangeorscaledepending on which makes the most sense in your program. Default (10,10,10) or set byautoscale. scaleA scaling factor which scales the region of interest into the sphere with unit radius. This is always 1.0/range, so use eitherrangeorscaledepending on which makes the most sense in your program. Default (0.1,0.1,0.1) or set by autoscale. Mouse Interactions This program displays a sphere (which automatically creates a window referred to asscene), then repeatedly waits for a mouse left click, prints the mouse position, and displays a small red sphere. A mouse left click is defined as pressing and releasing the left mouse button at nearly the same location. scene.range = 4 sphere() # display a white sphere for context while 1: if scene.mouse.clicked: #Is there a mouse click event mouseevent = scene.mouse.getclick() #Get the Mouse Event location = mouseevent.pos print location sphere(pos=location, radius=0.1, color=(1,0,0)) Try running this program. You will find that if you click inside the white sphere, nothing seems to happen. This is because the mouse click is in the x,y plane, so the little red sphere is buried inside the large white sphere. If you rotate the scene and then click, you'll see that the little red spheres go into the new plane parallel to the screen and passing throughdisplay.center. If you want all the red spheres to go into the xy plane, do this: location = mouseevent.project(normal=(0,0,1))#project into xy if location: # loc is None if no intersection with plane print location sphere(pos=location, radius=0.1, color=(1,0,0)) There are four kinds of mouse events: press, click, drag, and drop: A press event occurs when a mouse button is depressed. A click event occurs when all mouse buttons are released with no or very slight movement of the mouse. Note that a click event happens when the mouse button isreleased. A drag event occurs when the mouse is moved slightly after a press event, with mouse buttons still down. This can be used to signal the beginning of dragging an object.. A drop event occurs when the mouse buttons are released after a drag event. The mouseevent has the following attributes: posThe current 3D position of the mouse cursor;scene.mouse.pos. Visual always chooses a point in the plane parallel to the screen and passing throughdisplay.center. button= None (no buttons pressed), 'left', 'right', 'middle', or 'wheel' (scroll wheel pressed on some Windows mouses). Example:scene.mouse.button == 'left'is true if the left button is currently down. pickThe nearest object in the scene which falls under the cursor, or None. At present only spheres, boxes, cylinders, and convex can be picked. The picked object isscene.mouse.pick. pickposThe 3D point on the surface of the picked object which falls under the cursor, or None;scene.mouse.pickpos. cameraThe read-only current position of the camera as positioned by the user,scene.mouse.camera. For example,mag(scene.mouse.camera-scene.center)is the distance from the center of the scene to the current position of the camera. If you want to set the camera position and direction by program, usescene.forwardandscene.center. rayA unit vector pointing from camera in the direction of the mouse cursor. Exercise: Write a program to have the user click two points on the screen and place a ball at each of those points. Create a graph object that plots the position of those two points with the line connecting them. Q X b 6 X  q  * U u =>DEmAN˽곩곩˓곩곩ˌzph.h5;#hi|6h5B*OJQJ\ph h[LhhB* phhi|6h5>*B*phh0JB*phh0JB*phjhUmHnHuh5B*OJQJ\phhB*CJOJQJaJphhB*ph h5h,sh0J)Q  K  W X b 6 X  q 809D[$\$^8`0gd x9D[$\$gd80x9D[$\$^8`0gd$x9D[$\$a$gdgdn&  * U V v mAN.b80[$\$^8`0gdgd809D[$\$^8`0gd80x9D[$\$^8`0gd$x9D[$\$a$gdz{9$x9D[$\$a$gd80[$\$^8`0gd$x9D[$\$^`a$gdgd$9D[$\$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k!x1Tڮ,O+[^]Q;#ps1&iB Om/x8zȦImL+C&eCXJZ*%@A۬5X3:Kg@5d" ~P4XN*.BވC#8M V; V UhtC#&NԉjwqR |ko|ݼ^yͺfz65ojQEQw ,{΢#@#]OՍw/..4X a E V^[Aو1 G1r" - ZʿhB@DM@dU숍qqn"@`)BY!  hAd cG@, V|@@UAM% @h*H) @4X! @ VI4 @ +V>DCT @`ʇh @ 4X$ @XX  P$ Kه?~퍏? V\!@(w/..*0uB&@b \ZA P@wɓ'+P @@  ޖUcIENDB`@`@ NormalCJ_HaJmH sH tH R`R  Heading 1dd@&[$\$5CJ0KH$\aJ0N`"N  Heading 2dd@&[$\$5CJ$\aJ$DA@D Default Paragraph FontRi@R  Table Normal4 l4a (k@(No ListB^`B  Normal (Web)dd[$\$e` HTML Preformatted7 2( Px 4 #\'*.25@9CJOJQJ^JaJ6o6 normaldd[$\$8o"8 programdd[$\$*o1*  attributeBoAB apple-converted-spaceRoQR Heading 2 Char5CJ$\_HaJ$mH sH tH >ob>  attributesdd[$\$n<Q KWXb6Xq*UVvmAN.b  z { 9Jx6n3s>x('TEklp0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 KWXb6Xq*UvmA.b  z 9Jx6n3s>x(EklpJ000BJ000BJ000BJ000BJ000BJ000J00J00J000J000J000J000@0@0@0@0@0@0@0@0@0@0J000BJ000BJ000BJ000J000J000@0J0 1 J0 1J0 1@0@0J01@00@00@00@00@00@00@00@00@00J000@00@00@00@00@00@00@00@00@00@00@00@00@00@00@00@00@00@00J000BJ000BJ000J000J000@00H0G0000I%n& 9T!n&n&l,b$*ybi7-4<@(  J  # A"`B S  ?nHs'; T $.TZ%/&,?ELVagzq|16IS>Dv~'4?S_ 7<=EV`kq 7IR^9D "@Rpr+5mspFXgjk%27CpKN?Fahq}*.NR7=be  $ JQx} ',>En5=uwTWgkEHp333333333333333333333333333333333333333333333333333333333  JJ U V 55ccrruump@gn0@Unknowng: Times New RomanTimes New Roman5Symbol3& : ArialO1 CourierCourier NewMCentury Schoolbook?5 : Courier New"qh&&77Y24__2qHP ?2PGraphing in Vpython (With Credit to Bruce Sherwood and the Visual Documentation)mmasonmmasonOh+'0(8 HT t  TGraphing in Vpython (With Credit to Bruce Sherwood and the Visual Documentation)mmasonNormalmmason1Microsoft Office Word@Ik@xQY@JcY՜.+,0L hp  -Mt. San Antonio College7_' QGraphing in Vpython (With Credit to Bruce Sherwood and the Visual Documentation) Title  !"#$%&'()*+,-./012346789:;<=>?@ABCDEFGHIKLMNOPQSTUVWXY\Root Entry FphGY^1Table5 )WordDocumentJiSummaryInformation(JDocumentSummaryInformation8RCompObjq  FMicrosoft Office Word Document MSWordDocWord.Document.89q