Пример #1
0
        /// <summary>
        /// 将增加长度最小的点插入
        /// </summary>
        /// <param name="origin"></param>
        /// <param name="border"></param>
        public static void putMinLengthDotToBorder(Dot2 origin, Border border)
        {
            double temp, lengh = double.MaxValue;

            if (border.DotCount <= 2)
            {
                border.Add(origin);
                return;
            }
            int j = 0;

            for (int i = 0; i < border.DotCount; i++)
            {
                temp = Math.Length(origin, border.get(i)) + Math.Length(origin, border.get(i + 1)) - border.getVecter(i).Length;
                if (temp < lengh)
                {
                    lengh = temp;
                    j     = i;
                }
            }
            border.Insert(origin, j + 1, DrawType.Ignore);
        }
Пример #2
0
        /// <summary>
        /// 将一个点插入到边界中,形成凸面体
        /// </summary>
        /// <param name="origin"></param>
        /// <param name="border"></param>
        /// <returns></returns>
        public static void putDotToBorder(Dot2 origin, Border border)
        {
            Dot2 dot;
            int  i, j = 0, count = border.DotCount, tempj;

            if (count <= 2)
            {
                border.Add(origin);
                return;
            }
            double temp, lengh = double.MaxValue;

            int isIntersects = 0;

            for (i = 0; i < count; i++)
            {
                temp = Math.Length(origin, border.get(i));
                if (temp < lengh)
                {
                    lengh = temp;
                    j     = i;
                }
            }

            //判断是否相交
            tempj = count + j;
            for (i = 0; i < count; i++)
            {
                if (i == tempj % count || i == (tempj - 1) % count)
                {
                    continue;
                }
                if (isIntersect(new Vector(origin, border.get(tempj)), border.getVecter(i), out dot))
                {
                    isIntersects = 1;
                    break;
                }
            }
            if (isIntersects == 1)
            {
                isIntersects = 4;
                lengh        = double.MaxValue;
                //采用面积最小方式
                for (i = 0; i < border.DotCount; i++)
                {
                    temp = Math.Area(origin, border.get(i), border.get((i + 1)));
                    if (temp < lengh)
                    {
                        lengh = temp;
                        j     = i;
                    }
                }
                //判断是否相交,若相交,取最近的相交的线段插入
                temp  = double.MaxValue;
                tempj = count + j;
                for (i = 0; i < count; i++)
                {
                    if (i == tempj % count || i == (tempj - 1) % count)
                    {
                        continue;
                    }
                    if (isIntersect(new Vector(origin, border.get(tempj)), border.getVecter(i), out dot))
                    {
                        temp = Math.Length(origin, dot);
                        if (temp < lengh)
                        {
                            isIntersects = 5;
                            lengh        = temp;
                            j            = i;
                        }
                    }
                }
                //if (isIntersects == 5)
                //{

                //}
                //tempj = count + i+1;
                //for (i = 0; i < count; i++)
                //{
                //    if (i == tempj % count || i == (tempj - 1) % count)
                //    {
                //        continue;
                //    }
                //    if (isIntersect(new Vector(origin, border.get(tempj)), border.getVecter(i), out dot))
                //    {
                //        isIntersects = 5;
                //        break;
                //    }
                //}
            }
            else
            {
                tempj = count + j - 1;
                for (i = 0; i < count; i++)
                {
                    if (i == tempj % count || i == (tempj - 1) % count)
                    {
                        continue;
                    }
                    if (isIntersect(new Vector(origin, border.get(tempj)), border.getVecter(i), out dot))
                    {
                        isIntersects = 1;
                        break;
                    }
                }
                tempj = count + j + 1;
                for (i = 0; i < count; i++)
                {
                    if (i == tempj % count || i == (tempj - 1) % count)
                    {
                        continue;
                    }
                    if (isIntersect(new Vector(origin, border.get(tempj)), border.getVecter(i), out dot))
                    {
                        if (isIntersects == 1)
                        {
                            isIntersects = 2;
                        }
                        else
                        {
                            isIntersects = 3;
                        }
                        break;
                    }
                }
            }


            switch (isIntersects)
            {
            case 0:    //两线段都无交点
                if (Math.Length(origin, border.get(j - 1)) + border.getVecter(j).Length > Math.Length(origin, border.get(j + 1)) + border.getVecter(j - 1).Length)
                {
                    border.Insert(origin, j + 1, DrawType.normal);
                }
                else
                {
                    border.Insert(origin, j, DrawType.normal);
                }
                break;

            case 1:    //仅左线段相交
                border.Insert(origin, j + 1, DrawType.Ignore);
                break;

            case 2:    //左右线段都相交
                break;

            case 3:    //仅右线段相交
                border.Insert(origin, j, DrawType.Ignore);
                break;

            case 4:    //采用面积最小方式,无相交
                border.Insert(origin, j + 1, DrawType.Ignore);
                break;

            case 5:    //采用面积最小方式,有相交,插入相交线段
                border.Insert(origin, j + 1, DrawType.Ignore);
                break;

            default:
                break;
            }
        }