/// <summary> /// Determines whether two convex polygons intersect. /// </summary> /// <param name="first">The first polygon.</param> /// <param name="second">The second polygon.</param> /// <returns>Whether the two polygons intersect.</returns> public static bool Intersects(this IConvexPolygon first, IConvexPolygon second) { Vector2[][] bothAxes = { first.GetAxes(), second.GetAxes() }; Vector2[][] bothVertices = { first.Vertices, second.Vertices }; return(intersects(bothAxes, bothVertices)); }
/// <summary> /// Determines whether two convex polygons intersect. /// </summary> /// <param name="first">The first polygon.</param> /// <param name="second">The second polygon.</param> /// <returns>Whether the two polygons intersect.</returns> public static bool Intersects(this IConvexPolygon first, Rectangle second) { Vector2[][] bothAxes = { first.GetAxes(), second.GetAxes() }; Vector2[] firstVertices = first.Vertices; Vector2[] secondVertices = second.GetVertices(); foreach (Vector2[] axes in bothAxes) { foreach (Vector2 axis in axes) { ProjectionRange firstRange = new ProjectionRange(axis, firstVertices); ProjectionRange secondRange = new ProjectionRange(axis, secondVertices); if (!firstRange.Overlaps(secondRange)) { return(false); } } } return(true); }