Monday, March 31, 2008

Atari Space

My friend Justin was reminiscing about some Atari-aged video games: Subspace/Continuum. The problem they inspired reminds me more of Asteroids.

Problem:

A turret in a video game can rotate but not change location. It shoots bullets that travel with a constant velocity VB. An asteroid travels at a constant velocity VA. Where should the turret aim to hit the asteroid?

Solution:

You'll never find where you're going if you don't know where you started. Let's put the turret at the center of a Cartesian plane. Add a point A for the asteroid at (x0, y0), and add a point for the eventual collision at (x1, y1). Label the distances traveled by the asteroid and the bullet DA and DB. Recall that little ditty: "Distance = Rate × Time." We can use this whenever we are dealing with constant velocities. I've already labeled arrows RA and RB to represent the rates in the diagram.(I'm listing the equation numbers (abbreviated "eqn") on the left. When I use those equations later, I'll show which equation number I used on the right.) Note: the bullet and the asteroid travel for the same amount of time once the bullet is fired, so T has the same value in each equation.

We have two equations and three unknowns, so we'll need to find some more relationships. I can find more information about
DA and DB by breaking the distances into their horizontal and vertical components. I've added these components to the diagram below.Let β be the angle that the bullet's trajectory makes with the x-axis, and call the angle that the ship flies at with respect to the x-axis α.With all of these variables in play, let's take a moment to recap what is known and what we need to find.Now, we need to trade our variables down to get rid of some of those unknowns. I'll start with x1. Now do the same with the sines to get rid of y1. Now that we've gotten rid of x1 and y1, solve for T in equation 11 and substitute into equation 15... ...and simplify. Now we're down to one unknown: β. To find β, solve for sin(β), square both sides, and substitute 1 - cos2(β) for sin2(β). Then, use the quadratic equation to solve for the possible values of cos(β), and convert those values into the angles we want. Once we have β, we use equation 18 to find T and equations 4 and 5 to find x1 and y1.

I'm not going to attempt to finish this solution unless someone asks me to. I'm too likely to make a mistake somewhere in the tangled mass of algebra that is to follow, and Justin has access to math software that can do the manipulations for him. Comment if you have any questions.

2 comments:

John said...

All of which takes way too long, and you lose the game.

the brain can estimate all that in an instant, just lead the asteroid by what seems to be the correct amount. You'll get the hang of it after a few tries.

[/snark]

Jacqueline Granche said...

What, you can't do those calculations in your head in a fraction of a second?

I think Justin wants to design a game in which the computer will have to aim the turret, so no groovy organic brain to do the estimation.