


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
In this lab activity you will learn how to make VPython calculate gravitational forces, as vectors. Knowing how to do this will enable you to write programs ...
Typology: Exams
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Every program that models the motion of physical objects has two main parts:
In your fan cart program you studied motion with a constant force. But in the orbit of a planet around a star, or two stars orbiting each other (a “binary star”), the gravitational forces on the objects may change continually in magnitude and direction.
In this lab activity you will learn how to make VPython calculate gravitational forces, as vectors. 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.
The NEAR spacecraft flew past the asteroid Mathilde (for details, see Problem 2.11, p. 70 of the textbook). Create spheres representing Mathilde and the spacecraft: Mathilde
1200 km
NEAR spacecraft 10 km/s
from visual import * craft = sphere(pos=vector(-1.2e6,0.6e6,0), radius=1e4, color=color.cyan) Mathilde = sphere(pos=vector(0,-0.6e6,0), radius=5e4, color=color.white)
In addition to geometrical attributes such as pos and radius , you can give objects physical attributes such as mass. The mass of the NEAR spacecraft was 805 kg; add the following statement to your program:
craft.m = 805
The mass of Mathilde was estimated from its size as seen in photos taken by the spacecraft, and the density of typical rocks. The density of rocks is about 3000 kg/m^3 , and Mathilde appeared to be about 70 km by 50 km by 50 km in the photos (7e4 m by 5e4 m by 5e4 m). Add a statement that calculates the estimated mass of Mathilde in kilograms. Write out the calculation in the program and let Python do the calculation for you; don’t use your calculator. This lets you see in the program how the mass was calculated.
Mathilde.m =?
12
1 2
is a relative position vector pointing from one object to the other
In the following sections you will calculate the gravitational force that the Mathilde asteroid exerts on the NEAR spacecraft, by
that points from one object to the other
to calculate the magnitude of the gravitational force (^2) 12
1 2 grav
3.1 Calculate the relative position vector You know the vector positions of the two objects, which are craft.pos and Mathilde.pos.
r =?
3.2 Calculate the magnitude of the relative position vector
of the relative position vector , you need to know the following:
Knowing these features of VPython,
of the relative position vector:
rmag =?
3.3 Calculate the magnitude of the gravitational force
that you just calculated ( rmag ), and the masses craft.m and Mathilde.m ,
of the gravitational force. You should define G near the start of your program and use it here.
Fmag =?
3.4 Calculate the direction of the gravitational force You have calculated a vector that points from Mathilde to the spacecraft. The direction of this vector is along the
in the form of its unit
arr2 = arrow(pos=?, axis=?, color=color.yellow)
A question to ponder: In a ten second time interval, how would the change in the momentum of the spacecraft compare to the change in the momentum of Mathilde? How would the change in the velocity of the spacecraft compare to the change in the velocity of Mathilde? How would the total momentum (the momentum of the spacecraft plus the momentum of Mathilde) change during this time interval? Your instructor will ask you about these issues.
CHECKPOINT G1: Ask an instructor to check your work for credit. You can read ahead while you’re waiting to be checked off.
In order to see how the force on the spacecraft would vary at different positions of the spacecraft relative to Mathilde, calculate and display the force on the spacecraft (and on Mathilde) for four other locations.
craft.pos = vector(-0.6e6,0.6e6,0)
CHECKPOINT G2: Ask an instructor to check your work for credit. You can read ahead while you’re waiting to be checked off.
You might like to display the force arrows for some additional positions of the spacecraft.
In order to emphasize the physics rather than programming techniques, we had you make multiple copies of the calculational statements, which is clunky, and not feasible if there are hundreds of positions involved. It is not difficult to have just one copy of the calculations in a while loop where you increment the x component of the position of the spacecraft each time through the loop. Try it!
An advanced topic is to modify your program in such a way that you can drag the spacecraft around with the mouse, displaying the forces as you move, in which case you don’t want to create new arrows all the time, just update the attributes of the two existing arrows. To see how to handle mouse interactions, study the VPython demos that use the mouse, and see the “Visual” documentation on the IDLE help menu. Choose “Reference manual”, then “Mouse Interactions”. You may want to make the spacecraft bigger to make it easier to select and drag it.
Another advanced topic is to define a function (“def” in Python) that calculates the forces and displays them, then “call” that function repeatedly. We won’t need this technique in this course, but if you get interested in programming you might like to study the Python documentation available on the IDLE help menu. Python is an important and powerful programming language; we will barely scratch the surface of its capabilities.