示例#1
0
        /// <summary>
        /// Determines if this polygon intersects with another polygon.
        /// </summary>
        /// <param name="polygon">The polygon to test against.</param>
        /// <returns>A value indicating if the two polygons intersect.</returns>
        public bool IntersectsWith(GsPolygon polygon)
        {
            GsRectangle boxA = GsRectangle.FromLTRB(this.mMinX, this.mMinY, this.mMaxX, this.mMaxY);
            GsRectangle boxB = GsRectangle.FromLTRB(polygon.mMinX, polygon.mMinY, polygon.mMaxX, polygon.mMaxY);

            return(boxA.IntersectsWith(boxB));
        }
示例#2
0
        /// <summary>
        /// Calculate the projection of a polygon on an axis and returns it as a [min, max] interval
        /// </summary>
        private static void ProjectPolygon(GsVector axis, GsPolygon hull, ref float min, ref float max)
        {
            // get the points
            GsVector[] points = hull.mPoints;

            // To project a point on an axis use the dot product
            float d = GsVector.Dot(axis, points[0]);

            min = d;
            max = d;
            for (int i = 0; i < points.Length; i++)
            {
                d   = GsVector.Dot(points[i], axis);
                min = Math.Min(min, d);
                max = Math.Max(max, d);
            }
        }