Example #1
0
        public void Intersects(ref BoundingCircle circle, out bool result)
        {
            float distSq;

            Vector2Helper.DistanceSq(ref Center, ref circle.Center, out distSq);
            result = distSq <= (Radius * Radius + circle.Radius * circle.Radius);
        }
Example #2
0
        public void Intersects(ref BoundingRectangle rect, out bool result)
        {
            // Find the closest point to the circle within the rectangle
            var     x       = MathF.Clamp(Center.X, rect.Min.X, rect.Max.X);
            var     y       = MathF.Clamp(Center.Y, rect.Min.Y, rect.Max.Y);
            Vector2 closest = new Vector2(x, y);

            // Calculate the distance between the circle's center and this closest point
            float distanceSquared;

            Vector2Helper.DistanceSq(ref Center, ref closest, out distanceSquared);
            // If the distance is less than the circle's radius, an intersection occurs
            result = (distanceSquared < Radius * Radius);
        }
Example #3
0
        public static void FromVectors(Vector2[] vertices, out BoundingCircle result)
        {
            BoundingPolygon.GetCentroid(vertices, out result.Center);
            result.Radius = -1;
            for (var index = 0; index < vertices.Length; ++index)
            {
                float distSq;
                Vector2Helper.DistanceSq(ref result.Center, ref vertices[index], out distSq);
                if (result.Radius == -1 || (distSq < result.Radius))
                {
                    result.Radius = distSq;
                }
            }

            result.Radius = MathF.Sqrt(result.Radius);
        }