concept gravity in category python

appears as: gravity, gravity
Math for Programmers: 3D graphics, machine learning, and simulations with Python MEAP V11

This is an excerpt from Manning's book Math for Programmers: 3D graphics, machine learning, and simulations with Python MEAP V11.

Suppose you’re a programmer for Grand Theft Auto V and want to enable a basic use case like shooting a bazooka at a helicopter. A projectile coming out of a bazooka starts at the protagonist’s location and then its position changes over time. You can use numeric subscripts to label the various positions it has over its flight, starting with v0 = (x0, y0, z0). As time elapses, the projectile arrives at new positions labeled by vectors v1 = (x1, y1, z1), v2 = (x2, y2, z2), and so on. The rates of change for the x, y, and z values are decided by the direction and speed of the bazooka. Moreover, the rates can change over time—the projectile increases its z position at a decreasing rate because of the continuous downward pull of gravity (figure 1.10).

Figure 1.10: The position vector of the projectile changes over time due to its initial speed and the pull of gravity.

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.

In this function, source is a BlackHole object, and its x and y properties indicate its center as a PolygonModel, while its gravity property is the value passed to it in its constructor. The equivalent force field in mathematical notation would be written like this:

Here, Gbh represents the made-up gravity property of the black hole, and (xbh, ybh), once again, represents its position. The next step is to use this gravitational field to decide how objects should move.

Hello! Python

This is an excerpt from Manning's book Hello! Python.

  • Modeling real world processes such as gravity, light, and weather. This includes scientific models, but also most games.
  • You’ll add to the game by making the planet have gravity, so it pulls on the ship. If the ship collides with the planet, then BOOM! No more ship! Fending off aliens while trying to keep clear of the planet should add enough difficulty to keep the player occupied and entertained.

    Listing 9.7. Figuring out gravity
    sitemap

    Unable to load book!

    The book could not be loaded.

    (try again in a couple of minutes)

    manning.com homepage
    test yourself with a liveTest