示例#1
0
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;
}
示例#2
0
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;
}