Пример #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);
        }
Пример #2
0
        /// <summary>
        /// 点是否在线上
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        public bool Contains(Vector2 point)
        {
            if (Src == point || Dest == point)
            {
                return(true);
            }

            if (!MathUtility.IsInRange(point, Src, Dest))
            {
                return(false);
            }

            return(Utility2D.IsSameDirection(Direction, point - Src));
        }
Пример #3
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);
        }
Пример #4
0
 /// <summary>
 /// 是否平行
 /// </summary>
 /// <param name="line"></param>
 /// <returns></returns>
 public bool IsParallel(LineSegment2D line)
 {
     return(Utility2D.IsParallel(Direction, line.Direction));
 }
Пример #5
0
        /// <summary>
        /// 是否包含点
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        public bool Contains(Vector2 point)
        {
            int ret = Utility2D.GetPointPosition(point, Points);

            return(ret <= 0);
        }