示例#1
0
        //逐点插入法2
        public Edge[] PointByPointInsertion2()
        {
            double    ang;
            ArrayList tinlines = new ArrayList();
            //定义与第一点最近的点
            List <DataPoint> pointList = this.mPointSet.PointList;
            double           mindis    = pointList[0].GetDistance(pointList[1]);
            double           dis;
            int     count = 1;
            TinLine tl    = new TinLine();

            for (int i = 1; i < pointList.Count; i++)
            {
                dis = pointList[0].GetDistance(pointList[i]);
                if (dis < mindis)
                {
                    mindis = dis; count = i;
                }
            }
            //将第一条边反向已进行三角形扩展
            tl.Begin = (DataPoint)pointList[0];
            tl.End   = (DataPoint)pointList[count];
            tinlines.Add(tl);
            TinLine   line = new TinLine();
            DataPoint a    = ((TinLine)tinlines[0]).Begin;
            DataPoint b    = ((TinLine)tinlines[0]).End;

            line.Begin = b;
            line.End   = a;
            tinlines.Add(line);
            //对每一条边进行扩展
            for (int j = 0; j < tinlines.Count; j++)
            {
                double minang = 0;
                bool   OK;
                OK = false;
                TinLine tling1 = new TinLine();
                TinLine tling2 = new TinLine();
                for (int i = 0; i < pointList.Count; i++)
                {
                    int youbian;
                    //判断第三点与前两点的位置关系
                    youbian = DataPoint.LeftOrRight((DataPoint)pointList[i], ((TinLine)tinlines[j]).Begin, ((TinLine)tinlines[j]).End);
                    if (youbian == 1)
                    {
                        //获取角度最大点
                        ang = DataPoint.Angle((DataPoint)pointList[i], ((TinLine)tinlines[j]).Begin, ((TinLine)tinlines[j]).End);
                        if (ang > minang)
                        {
                            minang = ang; count = i;
                        }
                        OK = true;
                    }
                }
                if (OK == true)
                {
                    //将新生成两条边添加入集合中
                    int t1 = 0;
                    int t2 = 0;
                    tling1.Begin = ((TinLine)tinlines[j]).Begin;
                    tling1.End   = (DataPoint)pointList[count];
                    tling2.Begin = (DataPoint)pointList[count];
                    tling2.End   = ((TinLine)tinlines[j]).End;
                    tinlines.Add(tling1);
                    tinlines.Add(tling2);
                    for (int i = 0; i < tinlines.Count - 2; i++)
                    {
                        //判断新生成的两边是否与已生成的边重合
                        if ((tling2.Begin == ((TinLine)tinlines[i]).Begin && tling2.End == ((TinLine)tinlines[i]).End) ||
                            (tling2.Begin == ((TinLine)tinlines[i]).End && tling2.End == ((TinLine)tinlines[i]).Begin))
                        {
                            t2 = 1;
                        }
                        if ((tling1.Begin == ((TinLine)tinlines[i]).Begin && tling1.End == ((TinLine)tinlines[i]).End) ||
                            (tling1.Begin == ((TinLine)tinlines[i]).End && tling1.End == ((TinLine)tinlines[i]).Begin))
                        {
                            t1 = 1;
                        }
                    }
                    //两条边都重合
                    if (t2 == 1 && t1 == 1)
                    {
                        for (int i = 0; i < 2; i++)
                        {
                            tinlines.Remove(tinlines[tinlines.Count - 1]);
                        }
                    }
                    //第二条边重合
                    else if (t2 == 1)
                    {
                        tinlines.Remove(tinlines[tinlines.Count - 1]);
                    }
                    //第一条边重合
                    else if (t1 == 1)
                    {
                        tinlines.Remove(tinlines[tinlines.Count - 2]);
                    }
                }
            }
            tinlines.Remove(tinlines[0]);//将集合中的第一条边删除
            List <Edge> ResultEdge = new List <Edge>();
            int         eid        = 1;

            foreach (var tinLine in tinlines)
            {
                ResultEdge.Add(new Edge(((TinLine)tinLine).Begin, ((TinLine)tinLine).End)); eid++;
            }
            return(ResultEdge.ToArray());
        }