/// <summary>
 /// Checks if a Rectangle collides with the Arc.
 /// </summary>
 /// <param name="rect">Rectangle to check</param>
 /// <returns>On collision, true is returned, false otherwise</returns>
 private bool InterceptWithPolygon(Polygon2 polygon, double tolerance = GeometrySettings.DEFAULT_TOLERANCE)
 {
     var borderLines = polygon.ToLines(); //get 4 borderlines from rect
     if (borderLines != null) {
         return InterceptLinesWith(borderLines, tolerance);
     }
     return false;
 }
 /// <summary>Checks if a Rectangle collides with the Arc.
 /// 
 /// </summary>
 /// <param name="rect">Rectangle to check</param>
 /// <returns>On collision, a List of interception Points is returned</returns>
 private List<Vector2> InterceptPolygon(Polygon2 polygon, double tolerance = GeometrySettings.DEFAULT_TOLERANCE)
 {
     var intersections = new List<Vector2>();
     var borderLines = polygon.ToLines(); //get 4 borderlines from rect
     if (borderLines != null) {
         intersections.AddRange(InterceptLines(borderLines, tolerance));
     }
     return intersections;
 }
Пример #3
0
        /// <summary>
        /// Finds all intersection points with the given polygon
        /// </summary>
        /// <param name="polygon"></param>
        /// <param name="tolerance"></param>
        /// <returns></returns>
        private List <Vector2> InterceptPolygon(Polygon2 polygon, double tolerance = GeometrySettings.DEFAULT_TOLERANCE)
        {
            var intersections = new List <Vector2>();

            foreach (var border in polygon.ToLines())
            {
                intersections.AddRange(this.InterceptLine(border, tolerance));
            }
            return(intersections);
        }
        /// <summary>
        /// Checks if a Rectangle collides with the Arc.
        /// </summary>
        /// <param name="rect">Rectangle to check</param>
        /// <returns>On collision, true is returned, false otherwise</returns>
        private bool InterceptWithPolygon(Polygon2 polygon, double tolerance = GeometrySettings.DEFAULT_TOLERANCE)
        {
            var borderLines = polygon.ToLines(); //get 4 borderlines from rect

            if (borderLines != null)
            {
                return(InterceptLinesWith(borderLines, tolerance));
            }
            return(false);
        }
        /// <summary>Checks if a Rectangle collides with the Arc.
        ///
        /// </summary>
        /// <param name="rect">Rectangle to check</param>
        /// <returns>On collision, a List of interception Points is returned</returns>
        private List <Vector2> InterceptPolygon(Polygon2 polygon, double tolerance = GeometrySettings.DEFAULT_TOLERANCE)
        {
            var intersections = new List <Vector2>();
            var borderLines   = polygon.ToLines(); //get 4 borderlines from rect

            if (borderLines != null)
            {
                intersections.AddRange(InterceptLines(borderLines, tolerance));
            }
            return(intersections);
        }
        /// <summary>
        /// Polygon - Polygon intersection
        /// </summary>
        /// <param name="other"></param>
        /// <param name="tolerance"></param>
        /// <returns></returns>
        private IEnumerable <Vector2> InterceptPolygon(Polygon2 otherPolygon, double tolerance = GeometrySettings.DEFAULT_TOLERANCE)
        {
            var intersections = new List <Vector2>();
            var thisLines     = ToLines();
            var otherLines    = otherPolygon.ToLines();

            foreach (var line in thisLines)
            {
                foreach (var other in otherLines)
                {
                    intersections.AddRange(line.Intersect(other));
                }
            }
            return(intersections);
        }
        /// <summary>
        /// Is the given Polygon fully contained in this one?
        /// </summary>
        /// <param name="polygon"> </param>
        /// <param name="tolerance"> </param>
        /// <returns></returns>
        public bool Contains(Polygon2 polygon, double tolerance = GeometrySettings.DEFAULT_TOLERANCE)
        {
            if (polygon.ToVertices().All(x => Contains(x, tolerance)))
            {
                // When all vertices are contained in a convex polygon
                // we already know that the given vertices are inside
                // this polygon thus we are done
                if (IsConvex()) return true;

                // Otherwise, this is a concave polygon
                // we need to ensure, that the vertices do not intersect any line
                var otherLines = polygon.ToLines();
                return !HasIntersection(otherLines, tolerance);
            }

            return false;
        }
        /// <summary>
        /// Is the given Polygon fully contained in this one?
        /// </summary>
        /// <param name="polygon"> </param>
        /// <param name="tolerance"> </param>
        /// <returns></returns>
        public bool Contains(Polygon2 polygon, double tolerance = GeometrySettings.DEFAULT_TOLERANCE)
        {
            if (polygon.ToVertices().All(x => Contains(x, tolerance)))
            {
                // When all vertices are contained in a convex polygon
                // we already know that the given vertices are inside
                // this polygon thus we are done
                if (IsConvex())
                {
                    return(true);
                }

                // Otherwise, this is a concave polygon
                // we need to ensure, that the vertices do not intersect any line
                var otherLines = polygon.ToLines();
                return(!HasIntersection(otherLines, tolerance));
            }

            return(false);
        }
Пример #9
0
 /// <summary>
 /// Creates the 4 Lines which encloses this Rectangle
 /// </summary>
 /// <returns></returns>
 public IEnumerable <LineSegment2> ToLines()
 {
     return(_rect.ToLines());
 }
        /// <summary>
        /// Polygon - Polygon intersection
        /// </summary>
        /// <param name="other"></param>
        /// <param name="tolerance"></param>
        /// <returns></returns>
        private IEnumerable<Vector2> InterceptPolygon(Polygon2 otherPolygon, double tolerance = GeometrySettings.DEFAULT_TOLERANCE)
        {
            var intersections = new List<Vector2>();
            var thisLines = ToLines();
            var otherLines = otherPolygon.ToLines();

            foreach (var line in thisLines)
            {
                foreach (var other in otherLines)
                {
                    intersections.AddRange(line.Intersect(other));
                }
            }
            return intersections; 
        }
 /// <summary>
 /// Finds all intersection points with the given polygon
 /// </summary>
 /// <param name="polygon"></param>
 /// <param name="tolerance"></param>
 /// <returns></returns>
 private List<Vector2> InterceptPolygon(Polygon2 polygon, double tolerance = GeometrySettings.DEFAULT_TOLERANCE)
 {
     var intersections = new List<Vector2>();
     foreach (var border in polygon.ToLines())
     {
         intersections.AddRange(this.InterceptLine(border, tolerance));
     }
     return intersections;
 }