Beispiel #1
0
        public static bool Collide(CircleF c1, CircleF c2)
        {
            float distanceX = c1.X - c2.X;
            float distanceY = c1.Y - c2.Y;

            float combinedradius = c1.Radius + c2.Radius;

            float distanceSquared = (distanceX * distanceX) + (distanceY * distanceY);
            return distanceSquared < (combinedradius * combinedradius);
        }
Beispiel #2
0
        public static bool Collide(CircleF c, RectangleF r)
        {
            // Find the closest point to the circle within the rectangle
            float closestX = MathHelper.Clamp(c.X, r.Left, r.Right);
            float closestY = MathHelper.Clamp(c.Y, r.Top, r.Bottom);

            // Calculate the distance between the circle's center and this closest point
            float distanceX = c.X - closestX;
            float distanceY = c.Y - closestY;

            // If the distance is less than the circle's radius, an intersection occurs
            float distanceSquared = (distanceX * distanceX) + (distanceY * distanceY);
            return distanceSquared < (c.Radius * c.Radius);
        }