Example #1
0
        /// <summary>
        /// 求两线段的交点
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        public Vector2 IntersectPoint(LineSegment2D line)
        {
            Vector2 seg = line.Direction;

            var h1 = Utility2D.GetTriangleArea(Src, Dest, line.Src) / seg.magnitude;
            var h2 = Utility2D.GetTriangleArea(Src, Dest, line.Dest) / seg.magnitude;

            var k = h1 / (h1 + h2);

            return(this.Direction * k);
        }
Example #2
0
        /// <summary>
        /// 是否相交
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        public bool Intersect(LineSegment2D line)
        {
            int statusSrc  = Utility2D.GetPointPosition(line.Src, Src, Dest);
            int statusDest = Utility2D.GetPointPosition(line.Dest, Src, Dest);

            if (statusSrc == 0 || statusDest == 0)
            {
                if (statusSrc == 0)
                {
                    return(this.Contains(line.Src));
                }
                if (statusDest == 0)
                {
                    return(this.Contains(line.Dest));
                }

                return(false);
            }
            return(statusSrc != statusDest);
        }
Example #3
0
 /// <summary>
 /// 是否平行
 /// </summary>
 /// <param name="line"></param>
 /// <returns></returns>
 public bool IsParallel(LineSegment2D line)
 {
     return(Utility2D.IsParallel(Direction, line.Direction));
 }