/* interfaces */ class Ball { public: Ball(); /* Constructor */ ~Ball(); /* Destructor */ void init(float, float, float);/* Initialise */ void integrate(); /* Integrate trajectory equation */ void print(); /* Write out trajectory */ protected: /* Array values */ double *wVel; /* Velocity vector (1d) */ double *pos; /* Position (1d) */ double *peVal; /* PE */ double *keVal; /* KE */ /* Scalar values */ double mass; /* Mass */ int nsteps; /* Number of time steps */ double mydt; }; /* ===== Class Methods ===== */ /* Constructor */ Ball::Ball(){ wVel=NULL; pos=NULL; peVal=NULL; keVal=NULL; } /* Destructor */ Ball::~Ball(){ delete wVel; delete pos; delete peVal; delete keVal; } /* Initial conditions */ void Ball::init( float tend, float dt, float w0 ) { nsteps = ( int ) (tend/dt); wVel = new double[nsteps+1]; pos = new double[nsteps+1]; peVal = new double[nsteps+1]; keVal = new double[nsteps+1]; if ( wVel == NULL ) { printf("allocation of wVel [%d] failed\n",nsteps); exit(-1); } if ( pos == NULL ) { printf("allocation of pos [%d] failed\n",nsteps); exit(-1); } if ( peVal == NULL ) { printf("allocation of peVal[%d] failed\n",nsteps); exit(-1); } if ( keVal == NULL ) { printf("allocation of keVal[%d] failed\n",nsteps); exit(-1); } wVel[0]=w0; wVel[1]=w0; mass =0.1; mydt = dt; } /* Integrator */ void Ball::integrate() { int i; /* Loop counter */ double a,b,c; /* Intermediate terms used in solving */ double term1, term2, term3, term4; /* quadratic equation. */ double mydt1; /* Intermediate terms used in finding */ double mydt2; /* wall impact time. */ double smallstep; /* Intermediate term used in finding */ double wVelImpact; /* velocity when ball bounces. */ /* Integrate trajectory */ for (i=1;i