动画Cannon Shells C程序的轨迹

时间:2017-03-29 02:58:10

标签: c physics

我无法看到我的代码错误。我应该确定两个炮弹在以500米/秒的速度向水平方向50度角射击时将采取的轨迹。假设其中一个壳体没有受到阻力而另一个壳体的阻力系数为0.0001。我想知道为什么我的代码没有正确绘图。任何帮助都会很棒!

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include "philsplot.h"


// Number of shells
#define N 2
// Defining the value of PI
#define PI 3.1415926535

  int main()
  {
    double xmin, xmax, ymin, ymax, theta = (50 * (PI/180));
    int color, style;
    double expand;

    // philsplot function to open an x-window
    open_plot("800x600");
    int i,j;
    double vx[N], vy[N], x[N], y[N], h, ax[N], ay[N];
    h = 0.01;

    // philsplot function erases the canvas after flushpoint is called
    erase_plot();

    // plot using km for distance
    xmin = 0; xmax = 1;
    ymin = 0; ymax = 1;
    expand = 1.1;
    color = 1;

    // philsplot function to set limits of the plotting canvas
    box_plot(xmin,xmax,ymin,ymax,expand,color,"Distance (km)","Height (km)","RRRR","TTTT");
    // philsplot function that maps the plotting canvas onto the screen
    flush_plot();

    style = 2;
    color = 3;
    expand = 1.0;
    // The initial values
    for(i=0; i<N; i++) {
      // want the initial x-position to be this
      x[i] = 0;
      // want the initial y-position to be this
      y[i] = 0;
      // want the initial x-velocity to be this
      vx[i] = 0.5*cos(theta);
      // want the initial y-velocity to be this
      vy[i] = 0.5*sin(theta);
    }
      for(j=0; j<N-1; j++) {
    // Using Euler's method you get this:
    ax[j] = (-0.0001) * (0.5) * vx[j];
    ay[j] = (-0.00981) - (0.0001) * (0.5) * vy[j];
    vx[j] = vx[j] - ax[j] * h;
    vy[j] = vy[j] - ay[j] * h;
    x[j] = x[j] + vx[j] * h;
    y[j] = y[j] + vy[j] * h;

      putpoint_plot(x[j],y[j],10, style, color, expand, 1);

      flush_plot();

      delay_plot(1000);

    }

    printf("hit enter for next plot: ");
    getchar();
    return 0;
}

0 个答案:

没有答案