You are on page 1of 8

Physics 172Lab Lab #5 Moon Voyage

OBJECTIVES

Lab 5: Moon Voyage

In this program you will model the motion of a spacecraft traveling around the Earth. You will also explore the superposition law for gravitational forces. To do this you will iteratively (repeatedly): Calculate the gravitational force exerted on a spacecraft by the Earth (and Moon) Apply the momentum principle to the spacecraft to update the crafts momentum Apply the position update to the spacecraft to update the crafts position You will use your working program to explore the effect of the spacecraft's initial velocity on its trajectory. Remember, every program that models the motion of physical objects has two main parts: 5. Before the loop: The first part of the program tells the computer to: a. Create numerical values for constants we might need b. Create 3D objects c. Give them initial positions and momenta The while loop: The second part of the program, the loop, contains the statements that the computer reads to tell it how to increment the position of the objects over and over again, making them move on screen. These statements tell the computer: a. How to calculate the net force on the objects (the subject of this lab activity) b. How to calculate the new momentum of each object, using the net force and the momentum principle c. How to find the new positions of the objects, using the momenta

6.

In your cart program you learned how to motion with a constant force by updating the momentum and position of an object. In the Mathilde lab, you learned how to use VPython to calculate the gravitational forces exerted by two objects on each other. Here, you will combine the knowledge you have gained in the previous two labs to model a spacecraft orbiting the Earth, and then sending it to the Moon!

1. Creating the Objects


The first two lines of your program should be: from __future__ import division from visual import * Now create a sphere named Earth, at location < 0, 0, 0 > m, of radius 6.4e4 meters, colored cyan, representing the Earth:

Earth = sphere(pos=vector(0,0,0), radius=6.4e6, color=color.cyan) Create a second sphere named craft, at location < -10*Earth.radius, 0, 0 > m, with radius 1e6 m (greatly exaggerated!!), and make it yellow.

craft = ?? Create a second sphere named Moon, at location < 4e8, 0, 0 > m, with radius 1.75e6 m, and make it white.

Moon = ?? Run the program to see Earth, spacecraft, and the Moon.

33

Physics 172Lab 2. Constants & Physical Attributes

Lab 5: Moon Voyage

Since you will be calculating a gravitational force, you will need the constant G as well as the masses of all of the objects involved. Add the following constants to the program, on lines that come after the objects are created.

G = 6.7e-11 # units of N m^2 / kg^2 Earth.m = 6e24 # units of kg craft.m = 15e3 # units of kg Moon.m = 7e22 # units of kg

3. Initial Momentum of the Craft


We need to tell the craft what momentum it has to start with. For now, well start the craft off at rest and see what happens. Add the following lines to you program, which will set the initial velocity of the craft, and then calculate the crafts initial momentum. craft.v = vector(0, 0, 0) # units of m/s craft.p = craft.v*craft.m # units of kg m/s

4. Calculating the Gravitational Force on the Spacecraft & Updating its Motion
4.1 Setting up the Loop Structure
To repeatedly update the position and momentum of the spacecraft, we need to create a while loop, and place all of the force, momentum, and position calculations inside the loop. This is exactly what was done in your cart program from Lab 2. Create a while loop at the end of your program that runs for 4 years, with a t of 10 seconds. Add a rate statement so that 1000 frames are drawn per second. We will also turn off autoscaling. scene.autoscale = 0 t = 0 # units of seconds deltat = 10 # units of seconds while t< 4*365*24*60*60: rate(1000)

t=t+deltat

4.2 Adding the Force Calculations Remember that a sphere of mass m1 attracts a sphere of mass m 2 with a (vector) force given
by Fgrav on 2 by 1

= G

m1 m2 r21
2

r21 , where

G = 6.7e-11 Nm2/kg2 r21 is a relative position vector pointing from the center of object 1 to the center of object 2.

34

Physics 172Lab

Lab 5: Moon Voyage

r21 is a unit vector pointing from the center of object 1 to the center of object 2
You need to calculate the gravitational force exerted by the Earth on the spacecraft. Remember from Lab 3 that this is accomplished by calculating the relative position vector r21 that points from one object to the other calculating its magnitude using

r21
m1m2 r21
2

r21 to calculate the magnitude of the gravitational force Fgrav on 2 by 1 = G

calculating the unit vector r21 , which points from object 1 to object 2. calculating the vector gravitational force acting on object 2, the product of its magnitude and direction:
Fgrav on 2 by 1 = Fgrav on 2 by 1 Fgrav on 2 by 1 = Fgrav on 2 by 1 r21
We will let the Earth (E) be object 1 and the craft (c) be object 2.

You should reference your Mathilde program from Lab 3 if you have trouble calculating the gravitational force exerted on the spacecraft by the Earth. You make even copy and paste code where appropriate, just make sure to change names where appropriate and follow our notation conventions! Remember, r_cE is the relative position vector that points from the Earth to the craft. scene.autoscale = 0 deltat = 10 # units of seconds t = 0 # units of seconds while t< 4*365*24*60*60: rate(1000) r_cE = ?? rmag_cE = ?? rhat_cE = ?? Fmag_cE = ?? F_cE = ?? Fnet_c = ?? t=t+deltat

4.3 Update the Position and Momentum


Now the momentum and position of the craft must be updated. These must come after the net force is calculated, but still inside the loop. You are free to look at your cart program from Lab 2 for help in using the position update formula, as well as the update form of the momentum principle. scene.autoscale = 0 deltat = 10 # units of seconds t = 0 # units of seconds while t< 4*365*24*60*60: rate(1000) r_cE = ?? rmag_cE = ?? rhat_cE = ?? Fmag_cE = ??

35

Physics 172Lab
F_cE = ?? Fnet = ?? craft.p = ?? craft.pos = ?? t=t+deltat

Lab 5: Moon Voyage

4.4 Adding a Trail to Visualize the Path of the Craft


To better see the path that the craft takes, we need to create a curve object before the loop, and update the trail inside the loop. Add the following line to your program, on a line after where the spheres are created, but before everything else. trail = curve(color=craft.color) # adds a trail object with no points Inside the loop, after the position is updated, add the following line: trail.append(pos=craft.pos) # adds a point at the new craft position

4.5 Checking for Crashes Adding a Conditional Statement


We now a have program that will move our craft! Answer the following question in your notebook after discussing with your group:

1.) If the craft starts out with zero velocity, and the Earth is the only object exerting a force on the craft, what do you expect the craft to do? Why? Run your program! Does the craft do you what you expected?

If your spacecraft collides with the Earth, the program should stop. Add code similar to this inside your loop (using the name you defined for the distance between the spacecraft and the center of the Earth instead of rmag): if rmag < Earth.radius: print Crashed into Earth break This code tells VPython to get out of the loop if the spacecraft touches the Earth. Run your program to see that the conditional statement works correctly.

Well eventually be traveling near the Moon, so well want a second conditional statement that checks to see if weve crashed into the Moon. Add a conditional statement to your program that checks to see if youve crashed into the Moon. You may need to add some new relative position vectors to your code. if ?? < ??: print Crashed into Moon break

36

Physics 172Lab

Lab 5: Moon Voyage

CHECKPOINT 1: Ask an instructor to check your work for credit. You can read ahead while youre waiting to be checked off. 5. Visualizing the Force and Momentum Vectors with Arrows
Having calculated the momentum and net force vectors, we want to visualize them by displaying arrows representing the vectors. Add the following statements to your program before the loop to create two arrows on the screen that represent the momentum of the craft and the net force acting on the craft.

parr_c = arrow(color=color.blue) # momentum of craft arrow fnetarr_c = arrow(color=color.red) # net force on craft arrow Inside your loop, after the position of the craft is updated, update the pos and axis variables of both arrows. Choose pos and axis attributes so that the tails of the arrows are on the spacecraft and the arrows point in the direction of the momentum (for the momentum arrow) and the net force (for the force arrow). Do NOT use numbers! Write the values for the pos and axis attributes symbolically, in terms of the quantities you have already calculated. You may find your planets program from Lab 1 helpful. parr_c.pos = ?? parr_c.axis = ?? fnetarr_c.pos = ?? fnetarr_c.axis = ?? If you have calculated the net force correctly, you probably dont see an arrow! Here the force is so small you have to scale it up to be able to see it. How do you pick a scale factor? Estimating a good value for a scale factor This is what mapmakers have to do: pick a scale factor and stick to it for representing the real world on a small map. Run your program so you see your display showing the spacecraft and the asteroid. Put your hand near the monitor and, with your fingers, show about how long you would like the arrow representing the force to be. Estimate how long this is in the units of your virtual world. (Approximately what is the distance between the spacecraft and the asteroid? How long do you want your arrow to be compared to this distance?) You printed out the value of the force, so you can estimate the magnitude of the force. What would you need to multiply this by to get an arrow of the length you want? This multiplier is the scale factor (a scalar constant). For example, if the magnitude of the force was 2 Newtons, and you wanted an arrow that was 100 meters long in your virtual world, what scale factor would you use?

Desired_length_of_arrow = approximate_magnitude_of_quantity * scalefactor You may need to experiment a little to fine-tune your choice. Once you assign a value to the scale factor, your program should not change its value (your map has to have a constant scale). Add a statement near the start of your program to calculate an appropriate scale factor Fscale, and use it to scale the axis of your arrow statement, so that the arrow is visible. Single numbers, positive or negative, are called scalars, and they can be used to scale vectors. Use this scale factor with all arrows in this program.

Fscale = ??

37

Physics 172Lab

Lab 5: Moon Voyage

Repeat the above instructions for the momentum arrow and scale factor.

pscale = ??

6. Momentum and Net Force


Now that we have a fully functional program, its time to do some physics! Change the initial velocity of the craft so that it is moving at 1100 m/s in the positive y direction. Run your program. Answer the following questions in your notebook.

2.) Sketch the elliptical orbit that you see when the program runs. Draw the momentum vector of the craft at a few points on the orbit. Also draw the net force vector exerted on the craft at these points. Is the force vector always perpendicular to the momentum vector? 3.) What happens to the momentum of the spacecraft as the spacecraft moves away from the Earth? As it moves towards the Earth? Why? You should be able to explain this qualitatively in terms of the momentum principle. (Hint: draw the momentum vector and the change in momentum vector at some points on the orbit)

CHECKPOINT 2: Ask an instructor to check your work for credit. You can read ahead while youre waiting to be checked off. 7. To the Moon!
Now we want to head to the Moon. It will be useful to change the center the VPython graphics window to better see the Earth, Moon, and craft. Add the following statement to your program, to change the center the graphics window:

scene.center = vector(2e8, 0, 0) Give the craft an initial velocity of 3.3e3 m/s in the positive

direction. j direction each j

Run your program a few times, choosing slightly different values of the initial velocity in the time. Answer the following questions in your notebook:

4.) Is the orbit sensitive to the initial velocity? In other words, does a small change in the initial velocity produce a large change in the orbit? 5.) What initial velocity in the y direction is needed to crash into the Moon?

CHECKPOINT 3: Ask an instructor to check your work for credit. You can read ahead while youre waiting to be checked off.

38

Physics 172Lab

Lab 5: Moon Voyage

8. Turning on the Moons Gravity


Now, we want to add in the effect of the gravitational force that the Moon (M) exerts on the craft. The code for this is going to be very similar to the calculation of the gravitational force that the Earth exerts on the craft. You will, however, have to add modify the line that calculates the net force on the craft! Add the following lines of code to your program inside the loop, but before the net force is calculated. Note that, in accordance with our conventions, r_cM stands for the relative position vector that points from the Moon (M) to the craft (c). r_cM = ?? rmag_cM = ?? rhat_cM = ?? Fmag_cM = ?? F_cM = ?? Modify the line that calculates the net force on the craft so that it correctly uses the force from the Earth and the force from the Moon. You might want to check the definition of net force on page 43 of your text. Fnet_c = ?? Run your program to see how the orbit has changed.

Adjust the y component of the initial velocity so that you achieve a figure-8 orbit: an orbit that loops around the Moon before returning to Earth.

CHECKPOINT 4: Ask an instructor to check your work for credit. You can read ahead while youre waiting to be checked off.

9. Using Arrows to Visualize the Superposition of Gravitational Forces (required only if there is time remaining)
In the moon voyage program, the only force arrow displayed is the net force arrow. To get an idea of how big the competing forces are, we can add a force arrow for each of the individual forces on the craft. Add two new arrows to your code up where you defined your previous arrows. Well also change the net force arrow as well, and add a shaftwidth command to control how thick the arrows are. fnetarr_c=arrow(color=color.red,shaftwidth=2e6) # net force arrow fearr_c=arrow(color=color.cyan,shaftwidth=2e6) # force from Earth arrow fmarr_c=arrow(color=color.white,shaftwidth=2e6) # force from Moon arrow

.
Add code inside the loop (after you update the position of the craft) to update the pos and axis variables of your new arrows. Make sure the tails of the arrows are on the craft. fearr_c.pos = ??

39

Physics 172Lab
fearr_c.axis = ?? fmarr_c.pos = ?? fmarr_c.axis = ??

Lab 5: Moon Voyage

To enhance visibility of the force arrows, comment out anything relating to the momentum arrow. You may also have to adjust your force scalefactor (fscale). Run your program, and play around! Observe how the two individual force arrows add to give the resultant net force arrow. See what kinds of orbits you can come up with! You might want to try giving the craft an initial velocity of (0, 3.27e3, 0) m/s to start with.

40

You might also like