public double timeToHit(Particle that){
  if (this == that)   return INFINITY;
  double dx=that.rx - this.rx;
  double dy=that.ry - this.ry;
  double dvx=that.vx - this.vx;
  double dvy=that.vy - this.vy;
  double dvdr=dx * dvx + dy * dvy;
  if (dvdr > 0)   return INFINITY;
  double dvdv=dvx * dvx + dvy * dvy;
  double drdr=dx * dx + dy * dy;
  double sigma=this.radius + that.radius;
  double d=(dvdr * dvdr) - dvdv * (drdr - sigma * sigma);
  if (d < 0)   return INFINITY;
  return -(dvdr + Math.sqrt(d)) / dvdv;
}

public double timeToHit ( Particle that ) { if ( this == that ) return INFINITY ; double dx = that . rx - this . rx ; double dy = that . ry - this . ry ; double dvx = that . vx - this . vx ; double dvy = that . vy - this . vy ; double dvdr = dx * dvx + dy * dvy ; if ( dvdr > 0 ) return INFINITY ; double dvdv = dvx * dvx + dvy * dvy ; double drdr = dx * dx + dy * dy ; double sigma = this . radius + that . radius ; double d = ( dvdr * dvdr ) - dvdv * ( drdr - sigma * sigma ) ; if ( d < 0 ) return INFINITY ; return - ( dvdr + Math . sqrt ( d ) ) / dvdv ; }
returns the amount of time for this particle to collide with the specified particle , assuming no interening collisions .
