Пример #1
0
        public static float Angle(Segment2D a, Segment2D b)
        {
            if (a.Intersects(b))
            {
                return(Angle(a.IntersectionPoint(b), a.Vector, b.Vector));
            }

            Vector2 origin = a.ToLine().IntersectionPoint(b.ToLine());

            return(Angle(origin, a.Vector, b.Vector));
        }
Пример #2
0
 /// <summary>
 /// Calculates the intersection of the lines or segments AB and CD.
 /// </summary>
 /// <param name="A">First point of Line 1.</param>
 /// <param name="B">Second point of Line 1.</param>
 /// <param name="C">First point of Line 2.</param>
 /// <param name="D">Second point of Line 2.</param>
 /// <param name="onSegment">If true, point must be contained in both segments.</param>
 /// <returns>The intersection point of two lines or segments.(NaN, NaN) will be returned
 /// if they are parallel or the intersection point is not contained on both segments,
 /// should On Segment be true.</returns>
 public static Vector2 IntersectionPoint(Vector2 A, Vector2 B, Vector2 C, Vector2 D, bool onSegment)
 {
     if (onSegment)
     {
         Segment2D L1 = new Segment2D(A, B);
         Segment2D L2 = new Segment2D(C, D);
         return(L1.IntersectionPoint(L2));
     }
     else
     {
         Line2D L1 = new Line2D(A, B);
         Line2D L2 = new Line2D(C, D);
         return(L1.IntersectionPoint(L2));
     }
 }
Пример #3
0
        /// <summary>
        /// Calculates the intersection point of a segment with this polygon.
        /// </summary>
        /// <param name="segment"></param>
        /// <returns>The intersection points of a segment with this polygon.</returns>
        public virtual List <Vector2> IntersectionPoints(Segment2D segment)
        {
            List <Vector2> intersections = new List <Vector2>();

            Vector2 point;

            for (int i = 0; i < Edges.Length; i++)
            {
                point = segment.IntersectionPoint(Edges[i]);
                if (!point.IsNaN() && !point.IsInfinity())
                {
                    intersections.Add(point);
                }
            }

            return(intersections);
        }