/// <summary> /// Detects collision between a rectangle and a circle /// </summary> /// <param name="c">the bounding circle</param> /// <param name="r">the bounding rectangle</param> /// <returns>True for collision, false otherwise</returns> public static bool Collides(BoundingCircle c, BoundingRectangle r) { float nearestX = MathHelper.Clamp(c.Center.X, r.Left, r.Right); float nearestY = MathHelper.Clamp(c.Center.Y, r.Top, r.Bottom); return(Math.Pow(c.Radius, 2) >= Math.Pow(c.Center.X - nearestX, 2) + Math.Pow(c.Center.Y - nearestY, 2)); }
/// <summary> /// Tests for collision between this a bounding circle /// </summary> /// <param name="other">The bounding circle</param> /// <returns>True for collision, false otherwise</returns> public bool CollidesWith(BoundingCircle other) { return(CollisionHelper.Collides(other, this)); }
/// <summary> /// Determines if there is a collision between a circle and rectangle /// </summary> /// <param name="r">The bounding rectangle</param> /// <param name="c">The bounding circle</param> /// <returns>true for collision, false otherwise</returns> public static bool Collides(BoundingRectangle r, BoundingCircle c) { BoundingPoint p = new BoundingPoint(MathHelper.Clamp(c.X, r.X, r.X + r.Width), MathHelper.Clamp(c.Y, r.Y, r.Y + r.Height)); return(Collides(c, p)); }
/// <summary> /// Detects a collision between a circle and point /// </summary> /// <param name="c">the circle</param> /// <param name="p">the point</param> /// <returns>true on collision, false otherwise</returns> public static bool Collides(BoundingCircle c, BoundingPoint p) { return(Math.Pow(c.Radius, 2) >= Math.Pow(c.X - p.X, 2) + Math.Pow(c.Y - p.Y, 2)); }
/// <summary> /// Detects a collision between two circles /// </summary> /// <param name="c1">the first circle</param> /// <param name="c2">the second circle</param> /// <returns>true for a collision, false otherwise</returns> public static bool Collides(BoundingCircle c1, BoundingCircle c2) { return(Math.Pow(c1.Radius + c2.Radius, 2) >= Math.Pow(c2.X - c1.X, 2) + Math.Pow(c2.Y - c1.Y, 2)); }
/// <summary> /// Determines if this BoundingRectangle collides with a BoundingCircle /// </summary> /// <param name="c">the BoundingCircle</param> /// <returns>true on collision, false otherwise</returns> public bool CollidesWith(BoundingCircle c) { return(CollisionHelper.Collides(this, c)); }
/// <summary> /// Detects collision between a rectangle and a circle /// </summary> /// <param name="r">the bounding rectangle</param> /// <param name="c">the bounding circle</param> /// <returns>True for collision, false otherwise</returns> public static bool Collides(BoundingRectangle r, BoundingCircle c) => Collides(c, r);
/// <summary> /// Detects collision between two BoundingCircles /// </summary> /// <param name="a">The first BoundingCircle</param> /// <param name="b">The second BoundingCircle</param> /// <returns>true for collision, false otherwise</returns> public static bool Collides(BoundingCircle a, BoundingCircle b) { return(Math.Pow(a.Radius + b.Radius, 2) >= Math.Pow(a.Center.X - b.Center.X, 2) + Math.Pow(a.Center.Y - b.Center.Y, 2)); }