Пример #1
0
        private void TuBao(IPoint A, IPoint B, ArrayList C)//判断C中所有点是否在A,B连线的同一侧。。。。
        {
            int count;

            count = 0;

            foreach (IPoint D in C)
            {
                //int count;
                double z;
                //count = 0;
                z = (D.X - A.X) * (B.Y - A.Y) / (B.X - A.X) + A.Y;
                if (z > D.Y)
                {
                    count++;
                }
            }
            if (count == list.Count - 2 || count == 0)
            {
                TuLine line = new TuLine();
                line.Begin = A;
                line.End   = B;
                linelist.Add(line);
            }
        }
Пример #2
0
        public static IPolyline CreatePolyline(TuLine t)
        {
            ISegment           pSegment;
            ILine              pLine;
            object             o     = Type.Missing;
            ISegmentCollection pPath = new PathClass();

            pLine = new LineClass();
            pLine.PutCoords(t.Begin, t.End);
            pSegment = pLine as ISegment;
            pPath.AddSegment(pSegment, ref o, ref o);
            IGeometryCollection pPolyline = new PolylineClass();

            pPolyline.AddGeometry(pPath as IGeometry, ref o, ref o);
            return(pPolyline as IPolyline);
        }
Пример #3
0
        public static List <TuLine> DrawDog(List <IPoint> pointLoc, double yuzhi)
        {
            int number = pointLoc.Count;
            ////原始数据绘图
            //Graphics myGraphics = this.CreateGraphics();
            //myGraphics.DrawLines(new Pen(Color.Red), pointLoc);
            //myGraphics.Dispose();

            // this.label1.Text = Convert.ToString(yuzhi);

            //程序主体
            //******************思路*********************
            //首先定义一个用于存储中间存在最远距离大于阈值的点的点组数组,unpoint_index,数据个数定为最坏情况大小
            //在定义一个用于存储中间已经不存在最远距离大于阈值的点的点组数组,alpoint_index,数据个数定为最坏情况大小
            //unfirst,unlast分别是正在处理中的点组角标
            //求最远点
            //然后基本是和书本等资料中表示的流程一样了

            int un      = 0;
            int al      = -1;
            int unfirst = 0;
            int unlast  = number - 1;

            int[,] unpoint_index = new int[number * (number - 1) / 2, 2];
            unpoint_index[0, 0]  = 0;
            unpoint_index[0, 1]  = number - 1;

            int[,] alpoint_index = new int[number * (number - 1) / 2, 2];
            int now = 0;

            double l_every    = 0; //点线距离
            double l_most     = 0; //点线最远距离,在每次循环中赋初值0
            int    index_most = 0; //最远点的角标

pel:
            //求最远点
            double[] ABC = lineFunction(pointLoc[unfirst].X, pointLoc[unfirst].Y, pointLoc[unlast].X, pointLoc[unlast].Y);
            for (int a = unfirst; a <= unlast; a++)
            {
                l_every = pointToLine(ABC[0], ABC[1], ABC[2], pointLoc[a].X, pointLoc[a].Y);
                if (l_every > l_most)
                {
                    l_most     = l_every;
                    index_most = a;
                }
            }
            //与阈值判断
            if (l_most >= yuzhi)
            {
                un++;
                unpoint_index[un, 0] = unfirst;
                unpoint_index[un, 1] = index_most;
                un++;
                unpoint_index[un, 0] = index_most;
                unpoint_index[un, 1] = unlast;
                l_most = 0;
                now++;
                unfirst = unpoint_index[now, 0];
                unlast  = unpoint_index[now, 1];
                goto
                pel;
            }
            else
            {
                al++;
                alpoint_index[al, 0] = unfirst;
                alpoint_index[al, 1] = unlast;

                if (now != un)
                {
                    l_most = 0;
                    now++;
                    unfirst = unpoint_index[now, 0];
                    unlast  = unpoint_index[now, 1];
                    goto
                    pel;
                }
            }


            List <TuLine> listTuLine = new List <TuLine>();

            for (int a = 0; a <= al; a++)
            {
                TuLine tuLine = new TuLine();
                tuLine.Begin = pointLoc[alpoint_index[a, 0]];
                tuLine.End   = pointLoc[alpoint_index[a, 1]];
                listTuLine.Add(tuLine);
            }
            return(listTuLine);
            ////////Graphics myGraphics1 = this.CreateGraphics();
            ////////for (int a = 0; a <= al; a++)
            ////////{
            ////////    myGraphics1.DrawLine(new Pen(Color.Blue), pointLoc[alpoint_index[a, 0]], pointLoc[alpoint_index[a, 1]]);
            ////////}
            ////////myGraphics1.Dispose();
        }