Equations list

Realistic space travel timer (source code)

Collision detection engine demo (source code, theory)

First, a couple of quick definition-type-things:

I've put formulae in square brackets so they stand out.

Scalar: something like a speed, which has only a magnitude and no direction.

Vector: something like a velocity, with a magnitude and a direction. Can also be defined as the sum of movements in multiple dimensions (ie, an x movement plus a y movement), which makes life much easier when you're trying to add vectors. For some reason, the component in the x direction is measured in terms of

Acceleration: rate of change of velocity. You probably know that, but just to be safe.

In formulae, angles are denoted by the Greek letter theta. However, I'm lazy so I'm going to use g (as in an

I'm going to use standard units if I use any at all - metres for distance, seconds for time and the like - but you can easily use whatever units you like; units and turns, for example, or even quasits and rushyos should you so choose. (Further note: it's probably sensible to use SI (standard) units - it makes life easier, especially when dealing with constants like G)

Resolving direction/magnitude form vectors into components:

This is basic trigonometry. First, make sure the angle is in degrees clockwise from North. Then, with that as your angle and the magnitude as the hypotenuse, your

Going back to direction/magnitude form:

The magnitude is [|x| = SQRT(i^2 + j^2)] (magnitude is the square root of the i value squared plus the j value squared; Pythagoras' theorem).

The direction is [g = arctan (i/j)] (angle equals the inverse tangent of the i value over the j value).

All calculations will be done in component form; as mentioned earlier it's much easier that way (I'm not even sure if it's possible otherwise).

To get the final velocity (v), you need the initial velocity (u), the acceleration (a) and the length of time (t).

[v = u + at] (final velocity is the initial velocity plus the acceleration multiplied by the length of time the acceleration is applied for). Since I assume you'll be recalculating position every turn, you can basically ignore the time component, in which case the final velocity is simply [v = u + a]. I suspect the easiest way to do this will be to do the calculation twice, once for the x direction and once for the y direction.

For example, a ship with velocity 5i + 2j fires its engines at 45 degrees with a magnitude of root 8 (that is, the square root of 8).

Resolving the acceleration vector, the i value is root 8 sin 45 and the j value is root 8 cos 45, both of which come to 2, so the acceleration is 2i + 2j. (Yeah, I cheated to make the numbers easy.)

Therefore, to get the velocity after a turn:

i component: v = 5i + 2i = 7i

j component: v = 2j + 2j = 4j

So v = 7i + 4j.

Unfortunately, you still don't know where the ship actually is.

To get the distance (s) you need the initial velocity (u), the time (t) and the acceleration (a).

[s = ut + (1/2)*a*t^2] (the distance is the initial velocity multiplied by the time plus half the acceleration multiplied by the time squared). Complicated, but since we're working on a timescale of 1, you can reduce that to [s = u + a/2].

Therefore, for the position of the ship mentioned above, the change in position is:

x direction: s = 5i + (2/2)i = 6i

y direction: s = 2j + (2/2)j = 3j

Add those values to the coordinates of the ship's original position and you have your ship's new position and its velocity. Physics for idio- mathematicians.

Incidentally, if you want to find out what direction and how hard to fire your engines in order to stop in a turn:

[a = -u], that is, the acceleration must equal minus the initial velocity. If you resolve that value and it's greater than the ship's rated maximum acceleration, find how many times greater than its maximum acceleration that value is, round up, and do it again with a/that rounded value.

To get the acceleration (a)to stop at a point, you need the distance from you to the point (s), your initial speed (u), and your final velocity (v) which has to be 0.

[v^2 = u^2 + 2as] (final velocity squared equals initial velocity squared plus twice the acceleration multiplied by the distance). Because you're trying to stop, [0 = u^2 + 2as]. This re-arranges to [a = -((u^2)/2s)]. Again, if you've left it too late to give the command the acceleration may be too hard for the ship, while if you give the command too early, you'll be slowly deccelerating for ages. Fun fun.

Further equations of motion are available on their wikipedia page. With that, basic 2D vector theory, and the examples I've provided here you should be fine. Just bear in mind that while you're working in vectors to make adding accelerations and suchlike easier, you'll have to do every calculation twice, once in the x direction and once in the y direction. If your direction of motion, your ship and your destination all line up in a neat one-dimensional space, you can resolve things back to direction/magnitude and forget about the direction, but it's probably easier to do everything twice than check for alignment.

If you have further questions or individual applications you can't work out the formulae for, ask and trained monkey physicist will oblige. I hope this all makes sense; it's 3am.

Rate ship engines as force provided rather than acceleration provided. This can then be combined with the force due to gravity to get the total force and direction (see vector addition in previous section - convert to component form and add). Then use [f=ma] (force equals mass times acceleration) on each component to get the acceleration in component form.

Momentum is basically a measure of how hard something is to stop, and is defined as [p = mv] (momentum = mass times velocity). Momentum is conserved if no force acts, for example in a collision the total momentum of the colliding parties before and after is equal. I doubt we'll need this.

Mass increases as speed increases, as a consequence of special relativity. [M =

The equation for force due to gravity is [F = (GMm)/(s^2)] (Force due to gravity equals Newton's gravitational constant, 6.67e-11, multiplied by the mass of one object multiplied by the mass of the other object all divided by the distance between the centres of the two objects squared). The force applies to both objects, pulling them both towards each other with this force, but at the kind of scales we're talking about it's probably easier to assume the heavier object (probably a planet or sun) is fixed and the lighter object (ship) is the only one that does anything.

Angular velocity is [

Now the fun bit: orbits. If something is moving in a

Now, the acceleration holding the object in a circular path is called the centripetal acceleration and is also related to the angular momentum and radius: [a = r

Anyway, the main point here is that in an orbit, the centripetal force

Coming soon: eccentric orbits!