11 Simulating force fields

 

This chapter covers

  • Modeling forces like gravity using scalar and vector fields
  • Calculating force vectors using the gradient
  • Taking the gradient of a function in Python
  • Adding gravitational force to the asteroid game
  • Calculating gradients and working with vector fields in higher dimensions

There has just been a catastrophic event in the universe of our asteroid game: a black hole has appeared in the center of the screen! As a result of this new object in our game, shown in figure 11.1, the spaceship and all of the asteroids will feel a “gravitational pull” toward the middle of the screen. This makes the game even more challenging, and it gives us a new mathematical challenge as well−understanding force fields.

Figure 11.1 Oh no, a black hole!

Gravity is a familiar example of a force that acts at a distance, meaning that you don’t have to be touching an object to feel its gravitational pull. For instance, when you’re flying on an airplane, you can still walk around normally because, even at 30,000 feet, the Earth is pulling you downward. Magnetism and static electricity are other familiar forces that act at a distance. In physics, we picture sources of these kinds of forces, like magnets or statically charged balloons, as generating an invisible force field around themselves. Anywhere in the Earth’s gravitational force field, called its gravitational field, an object will feel a pull toward the Earth.

11.1 Modeling gravity with a vector field

11.1.1 Modeling gravity with a potential energy function

11.2 Modeling gravitational fields

11.2.1 Defining a vector field

11.2.2 Defining a simple force field

11.3 Adding gravity to the asteroid game

11.3.1 Making game objects feel gravity

11.3.2 Exercises

11.4 Introducing potential energy

11.4.1 Defining a potential energy scalar field

11.4.2 Plotting a scalar field as a heatmap

11.4.3 Plotting a scalar field as a contour map