Esempio n. 1
0
        public static WPoint2D Intersection_L2L(WPoint2D P11, WPoint2D P12, WPoint2D P21, WPoint2D P22)
        {
            ///判断头尾点是否相连
            if (Geos2D_Other.Check_PsMerge(P11, P21) == true || Geos2D_Other.Check_PsMerge(P11, P22) == true)
            {
                return(P11);
            }
            if (Geos2D_Other.Check_PsMerge(P12, P21) == true || Geos2D_Other.Check_PsMerge(P12, P22) == true)
            {
                return(P12);
            }
            ///求交点
            WVector2D d1 = P11.VectorTo(P12);
            WVector2D d2 = P21.VectorTo(P22);

            if (d1.IsParallelTo(d2, WGeos2D_Paras.E_Angle))
            {
                return(null);
            }
            double t = (P21 - P11).CrossProduct(d2) / (d1.CrossProduct(d2));

            if (t < 0 || t > 1)
            {
                return(null);
            }
            WPoint2D P = P11 + t * d1;

            if (CheckBound_Single(P21.X, P22.X, P.X) == false || CheckBound_Single(P21.Y, P22.Y, P.Y) == false)
            {
                return(null);
            }
            return(P);
        }
Esempio n. 2
0
        private static List <WPoint2D> DotPolyline_Times(WPolyLine2D PL, WPoint2D P1, WPoint2D P2, int Times, ref WGeometry2D WGC)
        {
            ///求取最近点
            WPoint2D p1 = (WPoint2D)Geos2D_Other.ClosestPoint_P2PL(P1, PL, true);
            WPoint2D p2 = (WPoint2D)Geos2D_Other.ClosestPoint_P2PL(P2, PL, true);

            if (p1.CheckNum > p2.CheckNum)   ///如果p2排在p1之前,需要对换位置
            {
                WPoint2D p = p1;
                p1 = p2;
                p2 = p;
            }
            List <WPoint2D> Ps = new List <WPoint2D>();

            Ps.Add(p1);
            for (int i = p1.CheckNum + 1; i <= p2.CheckNum; i++)
            {
                Ps.Add(PL[i]);
            }
            Ps.Add(p2);
            WPolyLine2D PL2 = new WPolyLine2D(Ps, ref WGC);

            return(DotPolyline_Times(PL2, Times));
        }
Esempio n. 3
0
        public static List <WPoint2D> Intersection_L2Pl(WPolyLine2D PL, WLine2D L)
        {
            List <WPoint2D>[] Pst = new List <WPoint2D> [0];
            ///Check头尾
            if (Geos2D_Other.Check_PsMerge(PL.StartPoint, L.StartPoint) == true ||
                Geos2D_Other.Check_PsMerge(PL.StartPoint, L.EndPoint) == true)
            {
                Array.Resize <List <WPoint2D> >(ref Pst, Pst.Length + 1);
                Pst[Pst.Length - 1] = new List <WPoint2D>();
                Pst[Pst.Length - 1].Add(PL.StartPoint);
            }
            if (Geos2D_Other.Check_PsMerge(PL.EndPoint, L.StartPoint) == true ||
                Geos2D_Other.Check_PsMerge(PL.EndPoint, L.EndPoint) == true)
            {
                Array.Resize <List <WPoint2D> >(ref Pst, Pst.Length + 1);
                Pst[Pst.Length - 1] = new List <WPoint2D>();
                Pst[Pst.Length - 1].Add(PL.EndPoint);
            }
            /////判断是否相互顶在一起
            //WPoint2D? Pnt = Geos2D_Other.ClosestPoint_P2PL(L.StartPoint, PL, true);
            //if (Pnt != null && Geos2D_Other.Check_PsMerge((WPoint2D)Pnt, L.StartPoint) == true)
            //{
            //    Array.Resize<List<WPoint2D>>(ref Pst, Pst.Length + 1);
            //    Pst[Pst.Length - 1] = new List<WPoint2D>();
            //    Pst[Pst.Length - 1].Add(L.StartPoint);
            //}
            //Pnt = Geos2D_Other.ClosestPoint_P2PL(L.EndPoint, PL, true);
            //if (Pnt != null && Geos2D_Other.Check_PsMerge((WPoint2D)Pnt, L.EndPoint) == true)
            //{
            //    Array.Resize<List<WPoint2D>>(ref Pst, Pst.Length + 1);
            //    Pst[Pst.Length - 1] = new List<WPoint2D>();
            //    Pst[Pst.Length - 1].Add(L.EndPoint);
            //}
            //Pnt = Geos2D_Other.ClosestPoint_P2L(PL.StartPoint, L, true);
            //if (Pnt != null && Geos2D_Other.Check_PsMerge((WPoint2D)Pnt, PL.StartPoint) == true)
            //{
            //    Array.Resize<List<WPoint2D>>(ref Pst, Pst.Length + 1);
            //    Pst[Pst.Length - 1] = new List<WPoint2D>();
            //    Pst[Pst.Length - 1].Add(PL.StartPoint);
            //}
            //Pnt = Geos2D_Other.ClosestPoint_P2L(PL.EndPoint, L, true);
            //if (Pnt != null && Geos2D_Other.Check_PsMerge((WPoint2D)Pnt, PL.EndPoint) == true)
            //{
            //    Array.Resize<List<WPoint2D>>(ref Pst, Pst.Length + 1);
            //    Pst[Pst.Length - 1] = new List<WPoint2D>();
            //    Pst[Pst.Length - 1].Add(PL.EndPoint);
            //}
            ///
            bool Array_Start = true;     /////判断Array是否要增加新数,如为true则增加新数
            bool List_Start  = true;     /////判断是否List要重新开始,如果为true则从新开始

            for (int i = 0; i < PL.Count - 1; i++)
            {
                if (CheckBound_Double(L, PL[i], PL[i + 1]) == true)
                {
                    if (Array_Start == true)
                    {
                        Array.Resize <List <WPoint2D> >(ref Pst, Pst.Length + 1);
                        Pst[Pst.Length - 1] = new List <WPoint2D>();
                        List_Start          = true;
                        Array_Start         = false;
                    }
                    if (List_Start == true)
                    {
                        Pst[Pst.Length - 1].Add(PL[i]);
                    }
                    Pst[Pst.Length - 1].Add(PL[i + 1]);
                }
                else
                {
                    Array_Start = true;
                }
            }
            //////////
            List <WPoint2D> Ps = new List <WPoint2D>();
            WPoint2D        P;

            for (int i = 0; i < Pst.Length; i++)
            {
                for (int j = 0; j < Pst[i].Count - 1; j++)
                {
                    P = Intersection_L2L(L, Pst[i][j], Pst[i][j + 1]);
                    if (P == null)
                    {
                        continue;
                    }
                    Ps.Add((WPoint2D)P);
                    break;
                }
            }
            Pst = null;
            return(Ps);
        }