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.

Get Math for Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.