Lab #4 - Gravitational Force and Moon Voyage

Physics 172Lab
Lab 4: Gravitational Force & Moon Voyage
Lab #4 - Gravitational Force and Moon Voyage
Note: Save your own code and distribute a copy to your lab partners after the
experiment is done. You will need this code for later labs!
GOALS
In this lab you will learn:
• How to instruct vPython to calculate the gravitational force acting on one
object due to another object.
• How to write these instructions in a symbolic form that can later be used in an
iterative calculation (loop) to predict the motion of a spacecraft
• How to create and scale arrows to represent the gravitational force on an
object.
• How to model the motion of a spacecraft traveling around the Earth and
around Earth and Moon using the superposition of gravitational forces.
• Explore the effect of the spacecraft's initial velocity on its trajectory.
In your cart program you studied motion in one dimension. However, the orbit of a planet
around a star (or two stars orbiting each other in the case of a “binary star”), the
gravitational forces on the objects may change in two or three dimensions.
In section I of this lab you will learn how to make VPython calculate gravitational forces
exerted by two objects (Earth and a spacecraft) on each other. Knowing how to do this
will enable you to write programs that predict the motion of objects in space, for if you
can calculate the net force on an object, you can update its momentum just as you did in
the fan cart program. Knowing the momentum lets you update the position. Repeating
these momentum and position updates will trace out a complete trajectory. In section II,
you will combine the knowledge you have gained in section I and from previous labs to
model the spacecraft orbiting the Earth, and then send it to the Moon!
Section I: Beginning the program
1. Predict and Explain Program Output
A starting program has been provided to you on blackboard.
DO NOT RUN THE PROGRAM YET! Before running the program read through the
program as a group. Make sure everyone understands each program statement. Reading
and explaining code is an integral component of learning to create and modify
computational models.
© 2013 Purdue University
1
Physics 172Lab
Lab 4: Gravitational Force & Moon Voyage
After you have read the code answer the following questions:
What is the physical system that is modeled by the program?
How should this system behave? (Draw a sketch)
Will the program as it is written accurately model the real system? (DO NOT RUN THE
PROGRAM YET!) Draw a sketch of how you expect the objects defined in the program
will behave.
After your group has reached a consensus on how the physical system should behave and
how the system in the program will behave you may run the program. Discuss how
closely your prediction of the behavior of the program matched the program.
Does the program match the behavior of the physical system? Why or why not? What’s
missing from our model?
© 2013 Purdue University
2
Physics 172Lab
Lab 4: Gravitational Force & Moon Voyage
CHECKPOINT 1: Ask an instructor to check your work for credit.
You can read ahead while you’re waiting to be checked off.
For the following set of code we will be exploring the gravitational force on
the spacecraft. Please comment out the line of your code that updates the
position of the spacecraft in the while loop until you are told to put the
code back in.
Do the following section within the while loop!
2. Calculating the gravitational force on the spacecraft
Before proceeding with the lab please make sure that you include some lines of code to
update the momentum of the craft.
A sphere of mass m1 attracts a sphere of mass m 2 with a (vector) force given by

mm
Fgrav on 2 by 1 = −G 1 22 r̂21 , where
r21
G = 6.7e-11 N·m2/kg2

r21 is a relative position vector pointing from object 1 to object 2.
r̂21 is a unit vector pointing from object 1 to object 2
In the following sections you will calculate the gravitational force that the Earth exerts on
the spacecraft, by

• calculating the relative position vector r21 that points from object 1 to the object 2

• calculating its magnitude r21

• using r21 to calculate the magnitude of the gravitational force

mm
Fgrav on 2 by 1 = G 1 22
r21
•
•
calculating the unit vector r̂21 , 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 by1 = Fgrav on 2 by1 Fˆgrav on 2 by1 = − Fgrav on 2 by1 rˆ21
•
We will let Earth (E) be object 1 and the spacecraft (c) is object 2.
2.1 Calculate the relative position vector
You know the vector positions of the two objects, which are craft.pos and
Earth.pos.
© 2013 Purdue University
3
Physics 172Lab
Lab 4: Gravitational Force & Moon Voyage
Add a section of code called “calculate relative position vector”, and add a statement
to your program to calculate a vector r_cE that points from Earth (E) to the craft (c).
Think about what you know about calculating relative position vectors between two
objects. Don’t use any numbers, just symbols.
r_cE = ?
2.2 Calculate the magnitude of the relative position vector

In order to calculate the magnitude r21 of the relative position vector, you need to know
the following:
•
•
•
•
The components of a vector in VPython are given by its x, y, and z attributes. For
example, craft.pos.x is the x component of the position vector of the
spacecraft, and r_cE.y is the y component of the vector r_cE that you created.
To calculate a square of a quantity, use two asterisks. For example, 3**2 gives 9.
You will need to make use of this feature later.
To calculate the square root of a quantity, use the function sqrt. For example,
sqrt(9) is 3.
This is the long, error-prone way of finding the magnitude. Instead, add a

statement to your program to calculate the magnitude r21 of the relative position
vector using the mag() function:
rmag_cE = ?
2.3 Calculate the magnitude of the gravitational force

Using the quantity r21 that you just calculated (rmag_cE), and the masses mcraft and
mEarth,
• Add a statement to your program to calculate the magnitude of gravitational force
on craft by Earth. Place this in a section of code labeled “calculate gravitational
force”.
Fmag_cE = ?
2.4 Calculate the unit vector
You have calculated a vector that points from spacecraft to the Earth. The direction of
this vector is along the line of the gravitational forces between the two objects, so if we

knew the direction of r21 in the form of its unit vector r̂21 , we could use it to get the
direction of the gravitational force.
© 2013 Purdue University
4
Physics 172Lab
•
Lab 4: Gravitational Force & Moon Voyage

You know both the vector r21 (r_cE) and its magnitude (rmag_cE). Use these
quantities to add a statement to your program to calculate the unit vector r̂21
(pronounced “r-two-one-hat”):
rhat_cE = ?
2.5 Calculate the gravitational force as a vector
Now you have everything you need to be able to calculate the gravitational force that the
Earth exerts on the spacecraft. Remember that any vector can be factored into a product
of its magnitude times its direction. You know the magnitude of the gravitational force,
so to get the vector force you just need to multiply by the unit vector for the force. You
already have the unit vector for the relative position vector, which lies along the same
line as the force vector.
Think carefully about whether you want to multiply the magnitude of the gravitational
force times r̂21 , or rather by − r̂21 . That is, is the force that acts on the spacecraft in the
same direction as the rhat_cE unit vector (or r_cE vector), or in the opposite
direction?
•
Add a statement to your program to calculate the gravitational force acting on the
spacecraft by Earth. We’ll assume that Earth is the only object near enough to
have a significant effect on the spacecraft.
F_cE = ?
•
Add another statement that calculates the net force on the spacecraft (there is only
one force present here, but this structure is useful when dealing with more
complex situations).
Fnet_c = ?
•
Add a print statement to your program to show the components of the net force,
and ask yourself whether the signs of the force make sense (then make changes to
your program if necessary):
print(“Fnet_c =”, Fnet_c)
3. Visualizing the Force and Momentum Vectors with Arrows
Having calculated the gravitational force vector, we want to visualize it by displaying an
arrow representing the vector.
•
Copy the lines of code that calculate the gravitational force on the craft due to the
earth and paste them before the while loop.
© 2013 Purdue University
5
Physics 172Lab
•
Lab 4: Gravitational Force & Moon Voyage
Add a statement to your program before the while loop to create an arrow on the
screen that represents the gravitational force acting on the spacecraft. Choose pos
and axis attributes so that the tail of the arrow is on the spacecraft and the arrow
points toward Earth. Do NOT use numbers! Write the values for the pos and
axis attributes symbolically, in terms of the quantities you have already
calculated.
#physical quantity vector arrows
arr_c = arrow(pos=?, axis=?, color=color.yellow)
If you have calculated the gravitational force correctly, you probably don’t 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
VPython has no concept of the different kinds of units we use in physics. Thus, when it
draws an arrow that is “1 meter” in length, it will have the same size as an arrow we draw
to represent a force “1 Newton” in size. When the distances in the situation we are
analyzing are vastly “different” than the sizes of the forces or momenta, we need to use
scale factors so that everything is easily visible on the screen.
•
•
Run your program so you see your display showing the spacecraft and the Earth.
Calculate the numerical value for magnitude of the gravitational force at t = 0
between the Earth and the craft. Write this number down. This is how long VPython
is currently drawing the force arrow.
•
What is the distance (in meters) from the center of the craft to the center of the Earth?
•
How many times larger is the craft-Earth distance than the length of the gravitational
force arrow?
•
This number is roughly what we have to scale the length of the force arrow by in
order to make it visible. Choose a number somewhat smaller than this for Fscale,
maybe .5 or .75 this number, and play around with a few values until you find one
that you think looks best.
© 2013 Purdue University
6
Physics 172Lab
•
Lab 4: Gravitational Force & Moon Voyage
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 the scale factor found above with all force arrows in this
program.
Fscale = ?
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).
Having calculated the momentum and 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.
#physical quantity vector arrows
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.
parr_c.pos = ??
parr_c.axis = ??
fnetarr_c.pos = ??
fnetarr_c.axis = ??
Repeat the above instructions for the force scale factor arrow to determine a momentum
scale factor, assuming that the initial speed of the craft is 1100 m/s. We will use this
value in the next section.
pscale = ??
© 2013 Purdue University
7
Physics 172Lab
Lab 4: Gravitational Force & Moon Voyage
4. The force acting on Earth
Now that you have displayed the force that the Earth exerts on the spacecraft, also display
the force that the spacecraft exerts on Earth. Think carefully about how this force would
be calculated. You should realize that you don’t need to do any new calculations! If you
find yourself doing new calculations, you’ve missed an important property of the
gravitational force law.
•
Add a statement to your program before the while loop to display an arrow
representing the force that the spacecraft exerts on Earth. Put the tail of the arrow
on Earth. Don’t add any new calculations, and don’t use any numbers, just
symbols.
arr_E = arrow(pos=?, axis=?, color=color.yellow)
1.) In a ten second time interval, how would the change in the momentum of the
spacecraft compare to the change in the momentum of Earth? Show why:
2.) How would the change in the velocity of the spacecraft compare to the change in the
velocity of Earth? Show why:
3.) How would the total momentum (the momentum of the spacecraft plus the
momentum of Earth) change during this time interval? Show why:
© 2013 Purdue University
8
Physics 172Lab
Lab 4: Gravitational Force & Moon Voyage
5. Controlling Autoscaling
By default, VPython will zoom the graphics window in and out to make sure that all of
the objects stay visible. This can sometimes give a false impression of the motion that’s
occurring.
•
Turn off autoscaling by placing the following line of code before the while loop:
scene.autoscale = 0
The zero tells VPython to turn off autoscaling. Deleting the line or replacing the zero
with a one tells VPython to turn on the autoscaling.
•
Run the program to see Earth and the spacecraft with the arrows
Adding the moon!!
Now we will add the moon into our code by using the following procedure:
•
Just after you created spacecraft and the Earth, create a third sphere named “Moon”,
at location < 4e8, 0, 0 > m, with radius 1.75e6 m, and make it white.
Moon = ??
•
Add the mass of the moon to your code just after you added mass of the craft and
Earth
Moon.m = 7e22 # units of kg
6. 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 3 for help in using the position update formula, as well as the update
form of the momentum principle.
#update craft momentum
delta_p = ??
craft.p = ??
You should also uncomment the code that updates the position or, if you deleted those
lines, insert the following code:
#update craft position
delta_r = ??
craft.pos = ??
Make sure to comment out the lines you added in section 3 as they are no longer
necessary.
© 2013 Purdue University
9
Physics 172Lab
Lab 4: Gravitational Force & Moon Voyage
7. Checking for Crashes – Adding a Conditional Statement
We now a have program that will move our craft!
•
Answer the following questions after discussing with your group:
4) 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? Use the momentum
principle in your reasoning.
•
Update your program so that the initial velocity of the craft is <0,0,0> and run your
program! Does the craft do what you expected? What does it do?
5) Why does the craft fly off of the screen?
6) We know the craft shouldn’t fly off of the screen, so something must be going wrong
at some point in the code. Using the definition of the momentum principle, think if
any of our assumptions are violated when the craft is near the center of the Earth, and
write them down below:
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):
© 2013 Purdue University
10
Physics 172Lab
Lab 4: Gravitational Force & Moon Voyage
#check for crash with earth
if rmag_cE < 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.
We’ll eventually be traveling near the Moon, so we’ll want a second conditional
statement that checks to see if we’ve crashed into the Moon.
•
Add a conditional statement to your program that checks to see if you’ve crashed into
the Moon. You may need to define some new relative position vectors to your
code.
#check for crash with moon
if ?? < ??:
print(“Crashed into Moon”)
break
CHECKPOINT 2: Ask an instructor to check your work for credit.
You can read ahead while you’re waiting to be checked off.
Before proceeding further you should comment out the lines of code that print the
gravitational force.
8. Momentum and Net Force
Now that we have a fully functional program, it’s 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.
7) 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?
© 2013 Purdue University
11
Physics 172Lab
Lab 4: Gravitational Force & Moon Voyage
8) 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)
9. 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 of the graphics
window:
scene.center = vector(2e8, 0, 0)
•
Give the craft an initial velocity of 3.3e3 m/s in the positive ŷ direction.
•
You may want to change the rate statement to a larger value so that your program
runs quicker.
•
Run your program a few times, choosing slightly different values of the initial
velocity in the ŷ direction each time.
•
Answer the following questions:
9.) 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?
10.) What initial velocity in the y direction is needed to crash into the Moon?
© 2013 Purdue University
12
Physics 172Lab
Lab 4: Gravitational Force & Moon Voyage
10. Turning on the Moon’s 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 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).
#calculate relative position vector: Craft – Moon
r_cM = ??
rmag_cM = ??
rhat_cM = ??
#calclate gravitational force: craft - moon
Fmag_cM = ??
Fhat_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.
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 where it started. Both “loops” of
the 8 do not have to be equal in size, one will be much larger than the other.
11. Using Arrows to Visualize the Superposition of Gravitational Forces
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 in the appropriate section. We’ll 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
© 2013 Purdue University
13
Physics 172Lab
Lab 4: Gravitational Force & Moon Voyage
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.
#update craft arrows
fearr_c.pos = ??
fearr_c.axis = ??
fmarr_c.pos = ??
fmarr_c.axis = ??
• To enhance visibility of the force arrows, comment out anything relating to the
momentum arrow. You may also have to adjust your force scale factor (Fscale).
• Now that you have 3 force arrows (one each for the net force, force from the Earth,
and force from the Moon), you can try to position the tail of the Moon force arrow so that
it is always at the head of the Earth force arrow. This will allow you to watch the
graphical vector addition as the program runs through the orbit.
• 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.
CHECKPOINT 3: Ask an instructor to check your work for credit.
© 2013 Purdue University
14