C:\> Rostislav Persion's Projects

.:: Projectile Simulation ::.
Projectile Simulation




This program simulates projectiles and includes wind resistance.

HEIGHT: meters

ANGLE: degrees

VELOCITY: meters/second

MASS: kilograms

DIAMETER: meters

DISTANCE: meters





SOFTWARE WRITTEN IN PHP
   1:  <?PHP
   2:   
   3:      $dt = 0.0001;
   4:   
   5:      $angle = (double)$_GET['angle'];
   6:      $y = (double)$_GET['height'];
   7:      $inity = $y;
   8:      $v = (double)$_GET['velocity'];
   9:      $d = (double)$_GET['diameter'];
  10:      $m = (double)$_GET['mass'];
  11:      $dist = (double)$_GET['distance'];
  12:      $t = 0.0;
  13:      
  14:      $vx = cos((3.14159/180)*$angle) * $v;
  15:      $vy = sin((3.14159/180)*$angle) * $v;
  16:      
  17:      $xdrag = 0.0;
  18:      $ydrag = 0.0;
  19:      $drag = 0.0;
  20:      $speed = 0.0;
  21:      
  22:   
  23:      $max_height = 0;
  24:   
  25:      while(($x < $dist) && ($y > 0))
  26:      {
  27:          $t += $dt;
  28:          
  29:   
  30:          $speed = sqrt(pow($vx,2) + pow($vy,2));
  31:          $drag = (0.5 * 1.29 * pow($speed,2) * 0.295 * (3.14159 * pow($d / 2,2))) / $m;
  32:   
  33:          $xdrag = -($vx / $speed) * $drag;
  34:          $ydrag = -($vy / $speed) * $drag;
  35:          
  36:          $ax = $xdrag;
  37:          $ay = -9.8 + $ydrag;
  38:          
  39:          $vx += ($ax * $dt);
  40:          $vy += ($ay * $dt);
  41:   
  42:          $x += ($vx * $dt);
  43:          $y += ($vy * $dt);
  44:   
  45:          if($y > $max_height) 
  46:          {
  47:              $max_height = $y;
  48:          }
  49:      
  50:      }
  51:      
  52:   
  53:      echo '<html><head><title>PROJECTILE SIMULATION</title></head><body bgcolor="#000000">';
  54:      echo '<font face="courier new" size="6" color="#FF0000">';
  55:      
  56:      echo '<b>PROJECTILE SIMULATION</b><br></font>';
  57:      echo '<font face="courier new" size="4" color="#FF0000"><b>BY ROSTISLAV PERSION</b></font>';
  58:      echo '<br><br>';
  59:      echo '</font>';
  60:   
  61:      
  62:      echo '<font face="courier new" size="4" color="#0000FF">';
  63:      echo '<b>INITIAL HEIGHT -----------></b> ' . number_format($inity,5 , '.', ',') . ' m<br>';
  64:      echo '<b>ANGLE --------------------></b> ' . number_format($angle,5 , '.', ',') . ' degrees<br>';
  65:      echo '<b>MUZZLE VELOCITY ----------></b> ' . number_format($v,5 , '.', ',') . ' m/sec<br>';
  66:      echo '<b>PROJECTILE DIAMETER ------></b> ' . number_format($d,5 , '.', ',') . ' m<br>';
  67:      echo '<b>PROJECTILE MASS ----------></b> ' . number_format($m,5 , '.', ',') . ' kg<br>';
  68:      echo '<b>TARGET DISTANCE ----------></b> ' . number_format($dist,5 , '.', ',') . ' m<br>';
  69:      echo '</font><br>';
  70:      
  71:      
  72:   
  73:      echo '<font face="courier new" size="4" color="#00FF00">';
  74:      
  75:      echo '<b>TIME ---------------------> </b> ' . number_format($t,5 , '.', ',') . ' sec<br>';
  76:      echo '<b>MAX HEIGHT ---------------> </b> ' . number_format($max_height,5 , '.', ',') . ' m<br>';
  77:   
  78:   
  79:      if ($y <= 0)
  80:      {
  81:          echo '<b>WARNING ------------------></b> BULLET HIT THE GROUND AT ' . number_format($x,5, '.', ',') . ' m <br>';
  82:      }
  83:      
  84:      echo '<b>FINAL HEIGHT -------------></b> ' . number_format($y,5 , '.', ',') . ' m<br>';
  85:      echo '<b>FINAL X VELOCITY ---------></b> ' . number_format($vx,5 , '.', ',') . ' m/sec<br>';
  86:      echo '<b>FINAL Y VELOCITY ---------></b> ' . number_format($vy,5 , '.', ',') . ' m/sec<br>';
  87:      echo '<b>FINAL VELOCITY -----------></b> ' . number_format(sqrt(pow($vx,2) + pow($vy,2)),5 , '.', ',') . ' m/sec<br>';
  88:      echo '<b>FINAL X DRAG -------------></b> ' . number_format($xdrag * $m,5 , '.', ',') . ' N<br>';
  89:      echo '<b>FINAL Y DRAG -------------></b> ' . number_format($ydrag * $m,5 , '.', ',') . ' N<br>';
  90:      echo '<b>FINAL DRAG ---------------></b> ' . number_format($drag * $m,5 , '.', ',') . ' N<br>';
  91:   
  92:      echo '</font>';
  93:      echo '</body></html>';
  94:   
  95:      
  96:      
  97:  ?>