Ejemplo n.º 1
0
        /// <summary>
        /// Checks for intersection between two circles.
        /// </summary>
        /// <param name="a">The first circle.</param>
        /// <param name="b">The second circle.</param>
        /// <returns>True if the two specified circles intersect or if one is entirely contained in the other.  False otherwise.</returns>
        public static bool Intersects(ICircle2D a, ICircle2D b)
        {
            float centerDistanceSquared = (a.Center - b.Center).LengthSquared();
            float radiusSum             = a.Radius + b.Radius;

            return(centerDistanceSquared <= radiusSum * radiusSum);
        }
Ejemplo n.º 2
0
        public bool Intersects(ICircle2D other)
        {
            float centerDistance = (_center - other.Center).Length();
            float radiusSum      = _radius + other.Radius;

            return(centerDistance <= radiusSum);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Finds the closest on the on specified circle.
        /// </summary>
        /// <param name="point">The point to which we want to find the closest point on the circle.</param>
        /// <param name="circle">The circle on which to find the closest point.</param>
        /// <returns>The point on the circle that is closest to the specified point.</returns>
        public static Vector2 FindClosestPointOnCircle(Vector2 point, ICircle2D circle)
        {
            Vector2 vector = point - circle.Center;

            vector.Normalize();
            vector *= circle.Radius;
            return(circle.Center + vector);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Checks for intersection between a polygon and a circle.
        /// </summary>
        /// <param name="polygon">The circle.</param>
        /// <param name="circle">The polygon.</param>
        /// <returns>True if the two shapes intersect.  False othwerise.</returns>
        public static bool Intersects(IPolygon2D polygon, ICircle2D circle)
        {
            // See if the closest point of each edge to the circle's center is inside the center
            Vector2 circleCenter = circle.Center;

            for (int i = 0; i < polygon.NumSides; i++)
            {
                Vector2 closestPointOfEdge =
                    (i == polygon.NumSides - 1 ?
                     ShapeUtility.CalculateClosestPointOnEdge(circleCenter, polygon.Vertices[i], polygon.Vertices[0]) :
                     ShapeUtility.CalculateClosestPointOnEdge(circleCenter, polygon.Vertices[i], polygon.Vertices[i + 1]));
                if (circle.Contains(closestPointOfEdge))
                {
                    return(true);
                }
            }

            // See if this polygon contains the other circle
            if (polygon.Contains(circle.Center))
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 5
0
 public bool Intersects(ICircle2D other)
 {
     return(ShapeUtility.Intersects(this, other));
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Checks to see if the specified point is contained in the specified circle.
        /// </summary>
        /// <param name="point">The point to check containment for.</param>
        /// <param name="circle">The circle to check if the point lies within.</param>
        /// <returns>True if the specified point is within the circle.  False otherwise.</returns>
        public static bool ContainsForCircle(Vector2 point, ICircle2D circle)
        {
            float centerDistanceSquared = (circle.Center - point).LengthSquared();

            return(centerDistanceSquared <= circle.Radius * circle.Radius);
        }
Ejemplo n.º 7
0
 public override bool Intersects(ICircle2D other)
 {
     return(ShapeUtility.Intersects(other, this));
 }
Ejemplo n.º 8
0
 public static void DrawCircle(this SpriteBatch spriteBatch, ICircle2D circle, Color color, Matrix transformFromWorldToCamera)
 {
     DrawCircle(spriteBatch, circle.Center, circle.Radius, color, transformFromWorldToCamera);
 }
Ejemplo n.º 9
0
 public static void DrawCircle(this SpriteBatch spriteBatch, ICircle2D circle, Color color)
 {
     DrawCircle(spriteBatch, circle.Center, circle.Radius, color, Matrix.Identity);
 }
Ejemplo n.º 10
0
 public abstract bool Intersects(ICircle2D other);
Ejemplo n.º 11
0
 public bool Intersects(ICircle2D other)
 {
     return(_polygon.Intersects(other));
 }