Beispiel #1
0
        public static bool CircleToCircle(Circle a, Circle b)
        {
            double c2 = (a.cX - b.cX) * (a.cX - b.cX) + (a.cY - b.cY) * (a.cY - b.cY);
            double r2 = (a.R + b.R) * (a.R + b.R);

            return c2 <= r2;
        }
Beispiel #2
0
 public static bool CircleToRectangle(Circle a, Rectangle b)
 {
     double dmin = 0;
     double[] C = new double[] { a.cX, a.cY };
     double[] Bmin = new double[] { b.X, b.Y };
     double[] Bmax = new double[] { b.X + b.W, b.Y + b.H };
     for (int i = 0; i < C.Length; i++)
     {
         if (C[i] < Bmin[i]) dmin += (C[i] - Bmin[i]) * (C[i] - Bmin[i]);
         else if (C[i] > Bmax[i]) dmin += (C[i] - Bmax[i]) * (C[i] - Bmax[i]);
     }
     return dmin <= a.R * a.R;
 }