Exemple #1
0
        protected float Cal_distance_po_edge(PO p1, PO p2)
        {
            //计算p1沿p1-p2方向到边界的距离
            util  u1 = new util();
            PO    np;
            float f1, f2;

            f1 = 0;
            f2 = 0;
            Node <PO> pn = edge_pl.Head;

            while (pn.Next != null)
            {
                //寻找与p1,p2相交的直线段
                np = u1.IsXl(pn.Data, pn.Next.Data, p1, p2, ref f1, ref f2);
                if (f1 > 0 && f1 < 1 && f2 >= 0 && f1 <= 1)
                {//将np插入到pn-pnt之间
                    return(np.Me_to_po_length(p1));
                }
                pn = pn.Next;
            }
            np = u1.IsXl(pn.Data, edge_pl.Head.Data, p1, p2, ref f1, ref f2);
            if (f1 > 0 && f1 < 1 && f2 >= 0 && f1 <= 1)
            {//将np插入到pn-pnt之间
                return(np.Me_to_po_length(p1));
            }
            return(0);
        }
Exemple #2
0
        private void Insert(LINE l0)
        {
            util u1 = new util();

            pg.ToString();
            /*获取线链的头边和尾边的外端点*/
            PO PLa, PFa;

            if (pkey == l0.p1)
            {
                PLa = l0.p2;
            }
            else
            {
                PLa = l0.p1;
            }
            if (pkey == pre_l.Head.Data.p1)
            {
                PFa = pre_l.Head.Data.p2;
            }
            else
            {
                PFa = pre_l.Head.Data.p1;
            }
            //PFa.ToString();
            // pg.ToString();
            if (u1.IsXl(pg, PLa, PFa, pkey))
            {
                //pg是当前边首边的外端点
                AddLine(PFa, PLa, pkey);
                Set_direction(pre_l.Head.Data, PLa);
                Set_direction(l0, pkey);
            }
            else
            {
                if (pg.selected)
                {
                    //如果pg已经被选过
                    #region pg==PFa;
                    LINE lt;//获取相应边
                    if (pg == PFa)
                    {
                        lt = Is_OutSide(PLa, PFa);
                        lt = Is_OutSide(PLa, pg);
                        if (lt != null)
                        {
                            //如果PFa-PLa已存在
                            u1.InFile(u1.infopath, "PFa-PLa existed");
                            Set_direction(pre_l.Head.Data, PLa);
                            Set_direction(pre_l.Last.Data, PFa);
                            Set_direction(lt, pkey);
                            return;
                        }
                        else
                        {
                            // u1.InFile(u1.infopath, "PFa==pg");
                            AddLine(PFa, PLa, pkey);
                            Set_direction(pre_l.Head.Data, PLa);
                            Set_direction(l0, pkey);
                            return;
                        }
                    }
                    #endregion pg=PFa
                    #region last'soutside
                    //如果pg是last的边链的外端点
                    lt = Is_OutSide(PLa, pg);
                    if (lt != null)
                    {
                        //u1.InFile(u1.infopath, "last's  outside");
                        AddLine(pkey, pg, PLa);
                        Set_direction(lt, pkey);
                        Set_direction(pre_l.Last.Data, pg);
                        if (PLa.p_parent != null)
                        //如果当前点是影子点,调整边链
                        {
                            //u1.InFile(u1.infopath, "in shadow");
                            shadowpo(PLa, pkey, PLa.p_parent, pg);
                        }
                        return;
                    }
                    #endregion last'soutside
                    #region first'soutside
                    //如果pg是first的边链的外端点
                    lt = Is_OutSide(PFa, pg);
                    if (lt != null)
                    {
                        LINE lt2 = AddLine(pkey, pg, PLa);
                        AddLine(PLa, pg, pkey);
                        Set_direction(lt, pkey);
                        Set_direction(pre_l.Head.Data, pg);
                        Set_direction(lt2, PFa);
                        Set_direction(pre_l.Last.Data, pg);
                        return;
                    }
                    #endregion first'soutside
                    #region arbitrary location
                    //如果pg是非特殊位置
                    PO pt = new PO(pg.x, pg.y, pg.z);
                    pt.p_parent = pg;
                    pg          = pt;
                    //u1.InFile(u1.infopath, "here1");
                    AddLine(pkey, pg, PLa);
                    // u1.InFile(u1.infopath, "here2");
                    AddLine(PLa, pg, pkey);
                    //u1.InFile(u1.infopath, "here3");
                    Set_direction(l0, pg);
                    // u1.InFile(u1.infopath, "here4");
                    work_pl.Insert(pg);
                    //u1.InFile(u1.infopath,"here5");
                    pg.selected = true;
                    #endregion
                }
                else
                {
                    //pg作为普通点处理
                    AddLine(pkey, pg, PLa);
                    AddLine(PLa, pg, pkey);
                    Set_direction(l0, pg);
                    work_pl.Insert(pg);
                    //work_pl.Dispaly();
                    pg.selected = true;
                }
            }
        }
Exemple #3
0
        private void Cal_new_edge_po_insert(model2d m0, PO p1, PO p2)
        {
            util  u1 = new util();
            PO    np;
            float f1, f2;

            f1 = 0;
            f2 = 0;
            bool      flag = false;
            Node <PO> pn = m0.edge_pl.Head, pnt, pnt1;

            pnt1 = null;
            LINE lt = new LINE(p1, p2);

            //PAINT.pl_tag.Insert(m0.edge_pl.Last.Data);
            if (pn != null)
            {
                while (pn.Next != null)
                {
                    //寻找与p1,p2相交的直线段
                    np = u1.IsXl(pn.Data, pn.Next.Data, p1, p2, ref f1, ref f2);
                    if (f1 > 0 && f1 < 1 && np != null)
                    {//将np插入到pn-pnt之间
                        pnt = new Node <PO>(np);
                        PAINT.pl_tag.Insert(np);
                        pnt.Next = pn.Next;
                        pn.Next  = pnt;
                        pn       = pn.Next;
                        if (pnt1 == null)
                        {
                            pnt1 = pnt;
                            //u1.InFile(u1.wherepath,"find point 1");
                            //u1.InFile(u1.wherepath, u1.Direct_2d(lt, pn.Next.Data));
                            //u1.InFile(u1.wherepath, u1.Direct_2d(lt, m0.center));
                            //PAINT.pl_tag.Insert(pn.Next.Data);
                            //PAINT.pl_tag.Insert(m0.center);
                            if (u1.Direct_2d(lt, pn.Next.Data) * u1.Direct_2d(lt, m0.center) < 0)
                            {
                                flag = true;
                                //u1.InFile(u1.wherepath, "flag=true");
                            }
                        }
                        else
                        {
                            if (flag)
                            {
                                //u1.InFile(u1.wherepath, "deal 1");
                                pnt1.Next = pnt;
                                return;
                            }
                            else
                            {
                                //u1.InFile(u1.wherepath, "deal 2");
                                m0.edge_pl.Head      = pnt1;
                                m0.edge_pl.Last      = pnt;
                                m0.edge_pl.Last.Next = null;
                                return;
                            }
                        }
                    }
                    pn = pn.Next;
                }
            }
            //u1.InFile(u1.wherepath, "middle");
            np = u1.IsXl(pn.Data, m0.edge_pl.Head.Data, p1, p2, ref f1, ref f2);
            if (f1 > 0 && f1 < 1 && np != null)
            {    //将np插入到pn-pnt之间
                np.key = 2;
                PAINT.pl_tag.Insert(np);
                pnt      = new Node <PO>(np);
                pnt.Next = pn.Next;
                pn.Next  = pnt;
                if (pnt1 != null)
                {
                    if (flag)
                    {
                        //u1.InFile(u1.wherepath, "deal 1");
                        pnt1.Next = pnt;
                        return;
                    }
                    else
                    {
                        //u1.InFile(u1.wherepath, "deal 2");
                        m0.edge_pl.Head = pnt1;
                        m0.edge_pl.Last = pnt;
                        return;
                    }
                }
            }
        }