Page 1 of 1

Putting Math Into the Context of Game Programming Part III- 3D Gravity Integrals, Area Between Curves, and Volumes of Revolving Solid

#1 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon

Reputation: 12317
  • View blog
  • Posts: 45,417
  • Joined: 27-December 08

Posted 14 April 2010 - 07:49 AM

So while helping out in the forums, I've seen a lot of misuse of mathematical formulas and notations in programs, specifically Precalculus and Calculus, that I hope to correct. Part III will cover area between curves for the purpose of finding the volumes of revolving solids and their applications in Game Programming.

In my last tutorial, Putting Math Into the Context of Game Programming Part II, we covered gravity in two-dimmensions. Gravity in three-dimmensions works similarly as in 2D; however, there are some key differences. First, let's start off with our 2D gravity field. In 2D, we could get away with using parametric equations to outline our bounds. However, in 3D, we have the extra dimmension of width to deal with. So when the character jumps, it can go forwards/backwards and sideways as well, in addition to up and down. Since we're working with a planar surface and a 3D jump, the best shape we can use to model the gravometric boundaries is a dome, or half an ellipsoid. We can extrapolate this by taking our 2D gravometric boundary, reflecting it over the x-axis, then revolving the area between the curves to get an ellipsoid. Taking half of this volume will give us the dome. So why integrate rather than using parametric equations as we did with 2D gravity? If we set up parametric equations for the x, y, and z-coordinates, we would end up with a cube as our gravometric bounds. Very simply, a cube does not allow for the gravitational modeling we need as it does not imply gravity.

Now that we've discussed the concepts of 3D gravity, let's work on the math behind it. As we said above, we first need the equation of our 2D gravometric bounds. So if you only have the parametric equations, you can plug in the points: (x-start, 0), (0, max-height), (x-end, 0) into your graphing calculator and run quadratic regression to get your equation. For the purpose of this tutorial, we will use the equation y = -x^2 + x + 2. Our next step is to reflect it over the x-axis, which will give us y = x^2 - x - 2. As both functions intersect the x-axis at -1 and 2, we have an area bounded by two curves in an ovular shape. The formula for the area between these curves is as follows: Area = Integrate(-1, 2, -x^2 + x + 2 - (x^2 - x - 2), dx), or more simply: Area = Integrate(-1, 2, -2x^2 + 2x + 4, dx). When we evaluate this integral, we get Area = 9, which will also be the height of our 3D ellipsoid when we revolve this area. Since we are looking for half of the ellipsoid, specifically the half above the z-axis, the maximum height of the dome will be 4.5 units.

So now we'll revolve the area between the curves around the x-axis to get our 3D dome, or half of the ellipsoid. Now let's find the volume. We will do this by integrating pi/4(f(x)^2 + g(x)^2) using the x-intersections of the two quadratic functions as our limits of integration. Basically, we will be rotating half of the top parabola and half of the bottom parabola, so (1/2)^2 = 1/4. So to find that volume we evaluate the following integral, V = pi/4 * integrate(-1, 2, (-x^2+x+2)^2 + (x^2-x-2)^2, dx), or more simply V = pi/4 * [(2x^5)/5 - x^4 - 2x^3 + 4x^2 +8x], evaluating the function in the brackets from -1 to 2. When we evaluate, we get V = 81pi/20 units.

Great! Now we know how much volume this dome will encompass. So how does that help us? To start, we also know the maximum height of the jump. Basically, we have our 2D gravometric boundaries, y = -x^2+x+2 standing up straight in 3D for any given jump. Since the area between our two parabolas is symetric, we can simply take the starting (x,y) coordinate of our character and determine the ending (x,y) coordinate based on the direction it is facing. Note that we are assuming the character will jump to completion, both in terms of height and distance across the xy-plane. If, however, the character stops short of jumping the full height or distance, our dome is still a valid container. However, we may want to set up a related rates equation to relate dDist/dt and 2dz/dt. Remember that since the jump requires the player to land as well, we care about the amount of time the character will take to reach the maximum height and land, or twice the amount of time to reach the maximum height. For mor information on related rates, check out Part I of my tutorial series.

Is This A Good Question/Topic? 2
  • +

Page 1 of 1