Ejemplo n.º 1
0
 /// <summary>
 /// Get all intersections between a line segment and a list of vertices
 /// representing a polygon. The vertices reuse adjacent points, so for example
 /// edges one and two are between the first and second vertices and between the
 /// second and third vertices. The last edge is between vertex vertices.Count - 1
 /// and verts0. (ie, vertices from a Geometry or AABB)
 /// </summary>
 /// <param name="point1">The first point of the line segment to test</param>
 /// <param name="point2">The second point of the line segment to test.</param>
 /// <param name="vertices">The vertices, as described above</param>
 /// <param name="intersectionPoints">An list of intersection points. Any intersection points
 /// found will be added to this list.</param>
 public static void LineSegmentVerticesIntersect(ref Vector2 point1, ref Vector2 point2, Vertices vertices,
                                                 ref List <Vector2> intersectionPoints)
 {
     for (int i = 0; i < vertices.Count; i++)
     {
         Vector2 point;
         if (LineIntersect(vertices[i], vertices[vertices.NextIndex(i)],
                           point1, point2, true, true, out point))
         {
             intersectionPoints.Add(point);
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Get all intersections between a line segment and a list of vertices
        /// representing a polygon. The vertices reuse adjacent points, so for example
        /// edges one and two are between the first and second vertices and between the
        /// second and third vertices. The last edge is between vertex vertices.Count - 1
        /// and verts0. (ie, vertices from a Geometry or AABB)
        /// </summary>
        /// <param name="point1">The first point of the line segment to test</param>
        /// <param name="point2">The second point of the line segment to test.</param>
        /// <param name="vertices">The vertices, as described above</param>
        public static Vertices LineSegmentVerticesIntersect(ref Vector2 point1, ref Vector2 point2, Vertices vertices)
        {
            Vertices intersectionPoints = new Vertices();

            for (int i = 0; i < vertices.Count; i++)
            {
                Vector2 point;
                if (LineIntersect(vertices[i], vertices[vertices.NextIndex(i)], point1, point2, true, true, out point))
                {
                    intersectionPoints.Add(point);
                }
            }

            return(intersectionPoints);
        }