Wednesday, March 12, 2008

Forces and Vpython Graphs

Hi Folks,

I didn't assign anyone to do the blog this time which means I am stuck doing it myself!

We started looking at Newton's first law and explored a problem with a balloon inside a large clear plastic box. Groups predicted how the direction of motion of the balloon would compare to the acceleration of the box. There were fixed results, but after performing the experiment it was discovered that the balloon moves in the direction of the acceleration since the air in the box has some inertia.

I asked each group to list all the types of forces that they could define from physics 2A. We compiled a list of 8 or so different forces.

From there we reviewed freebody diagrams, looking at a problem where a box was supported by a cable and an applied force applied normal to the cable.

Here is a link to all the forces notes for this section: http://physics.mtsac.edu/4A/4A%20Text/Forces.doc

We went through the analysis of the problem and then worked through the pumpkin problem. Finally we looked at the Pre-Lab question of how the vertical displacement of a cord depended on the distance between the points of attachment and the applied masses.

Students spent some time taking data on the vertical displacement and looked at both the small angle region and the large angle region. In the small angle region L is much larger then y so the sin (O) = tan (O) = O. This approximation lets us right down a fairly simple expression for the displacement. In the absence of the small angle approximation more algebra is required.

After working through the lab we spent the last hour talking about using Vpython for graphing.

Here is the handout I showed in class:

Additional Features in Vpython:

Controlling One or More Visual Display Windows

Initially, there is one Visual display window named scene. 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))

Now we will start by adding a few additional features to your bouncing balls

program from last week. Open up your bouncing ball program from last week.

Some of the most useful commands for controlling the window in the display are as follows:

center Location at which the camera continually looks, even as the user rotates the position of the camera. If you change center, the camera moves to continue to look in the same "compass" direction toward the new center, unless you also change forward (see next attribute). Default (0,0,0).

If in the loop you set:

scene.center = ball.pos

The ball will always be in the center of the screen and the box will seem to move around it.

autocenter scene.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.

If in the loop you set:

scene.autocenter = 0

The scene will stop autoscaling.

Mouse Interactions

Mouse objects are obtained from the mouse attribute of a display object such as scene. For example, to obtain mouse input from the default window created by Visual, refer to scene.mouse.

Inside your loop, add the following code:

if scene.mouse.clicked:

mouseevent = scene.mouse.getclick()

sphere(pos=mouseevent.pos,color=color.red)

If the mouse is clicked, generate a mouse event and create a sphere at the position where the mouse was clicked. This will create a series of red spheres over yo

ur program.

A mouse object has a group of attributes corresponding to the current state of the mouse. It also has functions getevent() and getclick(), which return an object with similar attributes corresponding to the state of the mouse when the user last did something with the mouse buttons. If the user has not already done something with the mouse buttons, getevent() and getclick() will stop program execution until this happens.

The following are useful commands for use with the mouse.

pos The current 3D position of the mouse cursor; scene.mouse.pos. Visual always chooses a point in the plane parallel to the screen and passing through display.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.

pick The 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 is scene.mouse.pick.

Now we will see how to create graphs in Vpython:

Importing from visual.graph makes available all Visual objects plus the graph plotting module. The graph is autoscaled to display all the data in the window.

At the top of your program add the following lines:

From visual.graph import *

graph1 = gdisplay()

funct = gcurve()

This will setup a separate graph window and a function to graph your data.

Inside your loop add the code:

funct.plot(pos=(t,ball.pos.x))

This will plot your ball’s x position as a function of time on the graph you just created.

A connected curve (gcurve) is just one of several kinds of graph plotting objects. Other options are disconnected dots (gdots), vertical bars (gvbars), horizon

tal bars (ghbars), and binned data displayed as vertical bars (ghistogram)

For homework I assigned some mastering physics problems from chapter 4 and 5. (You might read these chapters if you want additional review) At this point we are only working on static situations.

I also asked you to write up a pre-lab on our first dynamics lab. (The cart pulled by a mass)

Finally, I need to see pictures of your cars! Here is a fine picture from Carlos S.

No comments: