Esempio n. 1
0
        public void Calculation()
        {
            double A, B, C;

            //Вычисляем элементы кубического уравнения
            //x^3 + Ax^2 + Bx + C = 0
            A  = body.GetWidth() * (columns + 1) + body.GetLenght() * (rows + 1) + body.GetHeight() * (columns + 1) * (rows + 1);
            A /= (columns + 1) * (rows + 1); A *= (-1);
            B  = body.GetWidth() * body.GetLenght() + body.GetWidth() * body.GetHeight() * (rows + 1) + body.GetLenght() * body.GetHeight() * (columns + 1);
            B /= (columns + 1) * (rows + 1);
            C  = VCells - body.GetV(); C /= (columns + 1) * (rows + 1);

            //Получаем корни уравнения
            rootsList = GetRoots(A, B, C);
            k         = -1.0;

            foreach (Complex element in rootsList)
            {
                //MessageBox.Show(element.Real.ToString());
                if (element.Real < 0)
                {
                    continue;
                }
                if (element.Real == -1.0)
                {
                    k = -1.0;
                    break;
                }

                k = element.Real;
                double buff1, buff2, buff3;

                //Вычисляем предположительные значения сторон отверстия
                SetCellsWidth(); SetCellsHeight(); SetCellsLenght();
                if (cellWidth < 0 || cellHeight < 0 || cellLenght < 0)
                {
                    continue;
                }
                buff1 = columns * cellWidth + (columns + 1) * k;
                buff2 = rows * cellLenght + (rows + 1) * k;
                buff3 = k + cellHeight;

                if (Comporation(buff1, body.GetWidth()) && Comporation(buff2, body.GetHeight()) &&
                    Comporation(buff3, body.GetLenght()))
                {
                    SetVCellsFactical();
                    return;
                }
                else
                {
                    k = -1.0;
                }
            }
        }