//test if circle collides with other circle
 //used in robot collision detection
 public bool collide(Circle2D other)
 {
     double dx = other.p.x - p.x;
     double dy = other.p.y - p.y;
     dx *= dx;
     dy *= dy;
     double rad_sum = other.radius + radius;
     rad_sum *= rad_sum;
     if ((dx + dy) < rad_sum)
         return true;
     return false;
 }
        //calculate the nearest intersection of this line
        //with a circle -- if the line is interpreted as a ray
        //going from its first endpoint to the second
        public double nearest_intersection(Circle2D C, out bool found)
        {
            double dx, dy;

            dx = p2.x - p1.x;
            dy = p2.y - p1.y;

            double px = p1.x - C.p.x;
            double py = p1.y - C.p.y;

            double a = dx * dx + dy * dy;
            double b = 2 * px * dx + 2 * py * dy;
            double c = px * px + py * py - C.radius * C.radius;

            double det = b * b - 4.0 * a * c;

            if (det < 0.0)
            {
                found = false;
                return -1.0;
            }

            double sqrt_det = Math.Sqrt(det);
            double t1 = (-b + sqrt_det) / (2 * a);
            double t2 = (-b - sqrt_det) / (2 * a);

            found = false;
            double t = 0.0;
            if (t2 < 0)
            {
                if (t1 > 0)
                {
                    found = true;
                    t = t1;
                }
            }
            else
            {
                found = true;
                t = t2;
            }
            if (!found)
                return -1.0;

            return t * Math.Sqrt(dx * dx + dy * dy);

        }
 public Circle2D(Circle2D other)
 {
     p = other.p;
     radius = other.radius;
 }