public void Intersects(ref BoundingCircle circle, out bool result) { float distSq; Vectors2.DistanceSq(ref Center, ref circle.Center, out distSq); result = distSq <= (Radius * Radius + circle.Radius * circle.Radius); }
public void Intersects(ref BoundingRectangle rect, out bool result) { // Find the closest point to the circle within the rectangle Vector2 closest; Vector2.Clamp(ref Center, ref rect.Min, ref rect.Max, out closest); // Calculate the distance between the circle's center and this closest point float distanceSquared; Vectors2.DistanceSq(ref Center, ref closest, out distanceSquared); // If the distance is less than the circle's radius, an intersection occurs result = (distanceSquared < Radius * Radius); }
public static void FromVectors(Vector2[] vertices, out BoundingCircle result) { Contract.Requires(vertices != null); Contract.Requires(vertices.Length > 2); BoundingPolygon.GetCentroid(vertices, out result.Center); result.Radius = -1; for (var index = 0; index < vertices.Length; ++index) { float distSq; Vectors2.DistanceSq(ref result.Center, ref vertices[index], out distSq); if (result.Radius == -1 || (distSq < result.Radius)) { result.Radius = distSq; } } result.Radius = (float)Math.Sqrt(result.Radius); }