bool checkNearness(Disc d1,Disc d2) { double vrel_radial,arel_radial; double vector_par[2],x,y,l; double xgap = abs(d1.getX() - d2.getX()); double ygap = abs(d1.getY() - d2.getY()); y=(d1.getY()-d2.getY()); x=(d1.getX()-d2.getX()); l=sqrt(y*y+x*x); vector_par[0]=x/l; vector_par[1]=y/l; vrel_radial=(d1.getVx()-d2.getVx())*vector_par[0]+(d1.getVy()-d2.getVy())*vector_par[1]; arel_radial=(d1.getAx()-d2.getAx())*vector_par[0]+(d1.getAy()-d2.getAy())*vector_par[1]; error=vrel_radial*delt+0.5*arel_radial*delt*delt; double r = d1.getRadius() + d2.getRadius()+error; if(xgap*xgap + ygap*ygap<=r*r ) //sleep(1); if(xgap*xgap + ygap*ygap <= r*r && (checkNextCollision(d1,d2))) { cout<<"colission bw "<<d1.getDiscNo()<<" "<<d2.getDiscNo()<<endl; //sleep(1); error=0; return true; } error=0; return false; }
bool checkNextCollision(Disc d1,Disc d2) { double relVx = d1.getVx() - d2.getVx(); double relVy = d1.getVy() - d2.getVy(); double relx = d1.getX() - d2.getX(); double rely = d1.getY() - d2.getY(); if(relVx*relx + relVy*rely < 0) return true; return false; }
void afterCollision(Disc d1,Disc d2,double v[][2]) { //double **v = (double**) malloc(4*sizeof(double)); //cout<<"array declared"<<endl; //sleep(2); double vector_par[2],vector_per[2],u_par[2],v_per[2],v_par[2],l; double v1[2][2],y,x; double v1x = d1.getVx(),v2x = d2.getVx(),v1y = d1.getVy(),v2y = d2.getVy(),m1 = d1.getMass(),m2 = d2.getMass(); double slope; y=(d1.getY()-d2.getY()); x=(d1.getX()-d2.getX()); l=sqrt(y*y+x*x); vector_par[0]=x/l; vector_par[1]=y/l; vector_per[0]=y/l; vector_per[1]=-x/l; //cout<<"vector par"<<vector_par[0]<<"+"<<vector_par[1]<<"\n"; //cout<<"vector_per"<<vector_per[0]<<"+"<<vector_per[1]<<"\n"; //cout<<"v1"<<v1x<<"+"<<v1y<<"\n"; //cout<<"v2"<<v2x<<"+"<<v2y<<"\n"; u_par[0]=v1x*vector_par[0]+v1y*vector_par[1]; u_par[1]=v2x*vector_par[0]+v2y*vector_par[1]; //cout<<u_par[0]<<"+"<<u_par[1]<<"\n"; v_per[0]=v1x*vector_per[0]+v1y*vector_per[1]; v_per[1]=v2x*vector_per[0]+v2y*vector_per[1]; //cout<<v_per[0]<<"+"<<v_per[1]<<"\n"; v_par[0]=(m1*u_par[0] + m2*u_par[1] + m2*ed*(u_par[1]-u_par[0]))/(m1+m2); v_par[1]=(m1*u_par[0] + m2*u_par[1] - m1*ed*(u_par[1]-u_par[0]))/(m1+m2); //cout<<v_par[0]<<"+"<<v_par[1]<<"+"; //cout<<"slope"<<slope<<"\n"; //sleep(2); v[0][0]=v_par[0]*vector_par[0]+v_per[0]*vector_per[0]; v[0][1]=v_par[0]*vector_par[1]+v_per[0]*vector_per[1]; v[1][0]=v_par[1]*vector_par[0]+v_per[1]*vector_per[0]; v[1][1]=v_par[1]*vector_par[1]+v_per[1]*vector_per[1]; //cout<<"disk"<<v[0][0]<<"+"<<v[0][1]<<"\n"; //cout<<"striker"<<v[1][0]<<"+"<<v[1][1]<<"\n"; }
bool checkNearness(Disc d, Wall w,int wallno) { bool cond = (wallno==0 || wallno==2); if(abs((cond?d.getY():d.getX()) - (cond?w.getY():w.getX())) <= d.getRadius() && (cond?d.getVy():d.getVx())*(cond?w.getY():w.getX())>= 0) { //cout<<d.getDiscNo()<<" colliding with wall"<<wallno<<endl; return true; } return false; }