//Appendix A
#include<iostream.h>
#include<math.h>

float m;                 //The mass of the planet and asteroid
float va;                //Velocity of the planet
float vb;                //Velocity of the asteroid
float aa;                //Angle of the line of impact of the //planet
float ab;                //Angle of the line of impact of the asteroid
float ra;                 //The degrees converted into radians of the planets line
                             //of impact
float rb;                 //The degrees converted into radians of the asteroids
                             //line of impact
float n;                   //equation used to figure motion parallel to the line
                             //of impact
float l;                    //relation between relative velocities in the x
                             //directions
float pi=3.141592654;
get();                     //Function that obtains the variables
angle();                  //Function that converts angles into radians
math();                   //Function that determines the velocities of the planet
                              //and asteroid after the collision
main()
{
get();
angle();
math();
}

get()
{
cout<<"This program assumes that the coefficient of restitution is 0.9 \n";
cout<<"and that the planet and asteriod have the same mass \n";
cout<<"Enter the mass of the planet and asteroid \n";
cin>>m;
cout<<"Enter the velocity of the planet in ft/sec \n";
cin>>va;
cout<<"Enter the velocity of the asteriod in ft/sec \n";
cin>>vb;
cout<<"Enter the angle from the line of impact of the planet in degrees \n";
cin>>aa;
cout<<"Enter the angle from the line of impact of the asteriod in degrees \n";
cin>>ab;
return m, va, vb, aa, ab;
}

angle()
 {
 ra=aa*pi/180;
 rb=ab*pi/180;
 return ra, rb;
 }

math()
 {
 float vax;               //Initial velocity in the X direction of the planet
 float vay;               //Initial velocity in the Y direction of the planet
 float vbx;               //Initial velocity in the X direction of the asteroid
 float vby;               //Initial velocity in the Y direction of the asteroid
 float vpax;             //Finishing velocity in the X direction of the planet
 float vpbx;             //Finishing velocity in the X direction of the asteroid
 float vpa;               //Finishing velocity in the Y direction of the planet
 float vpb;               //Finishing velocity in the Y direction of the asteroid
 float e=0.9;            //The coefficient of restitution

 vax=va*cos(ra);
 vay=va*sin(ra);
 vbx=-vb*cos(rb);
 vby=vb*sin(rb);
 n=vax+vbx;
 l=e*(vax-vbx);
 vpax=(n+l)/2;
 vpbx=vpax-l;
 vpa=sqrt((vay*vay)+(vpax*vpax));
 vpb=sqrt((vby*vby)+(vpbx*vpbx));
 cout<<"The planet's velocity will be about "<<vpa<<" ft/sec after the collision \n";
 cout<<"The asteroid's velocity will be about "<<vpb<<" ft/sec after the collision \n";
 }
  back to home page