BBC BASIC for Windows
General >> General Board >> Artillery
http://bb4w.conforums.com/index.cgi?board=general&action=display&num=1300917262

Artillery
Post by Kendall Down on Mar 23rd, 2011, 9:54pm

I want to write a simple artillery type game for my grandsons. Does anyone have a formula for calculating the path of a canonball given angle of gun and muzzle velocity? Gravity should come into it somewhere, I suppose.

Re: Artillery
Post by admin on Mar 23rd, 2011, 10:43pm

on Mar 23rd, 2011, 9:54pm, Guest-Kendall Down wrote:
Does anyone have a formula for calculating the path of a canonball given angle of gun and muzzle velocity?

There's a formula here:

http://en.wikipedia.org/wiki/Trajectory

User Image

(where v0 is the initial speed, theta is the angle of elevation and g is the acceleration due to gravity).

Or in BASIC code:

Code:
y = - (x^2) * g / COS(theta)^2 / (2 * v0^2) + x * TAN(theta) 

Or in an entire program:

Code:
      MODE 8
      
      v0 = 110
      g = 9.8
      theta = RAD(60)
      
      a = TAN(theta)
      b = g / COS(theta)^2 / (2 * v0^2)
      
      FOR x = 0 TO 1278 STEP 2
        y = x * a - x^2 * b
        DRAW x,y
      NEXT 

Richard.
Re: Artillery
Post by Kendall K Down on Apr 8th, 2011, 09:39am

Thanks. I shall play around with that over the weekend.