/// <summary>
        /// Нахождение шага разбиения стороны
        /// </summary>
        /// <param name="fSide">длина стороны</param>
        /// <param name="step">первоначальный шаг разбиения</param>
        /// <returns>новый шаг разбиения</returns>
        public static double FindNewStep(double fSide, double step)
        {
            double newStep = 0;
            double n, step1, step2;

            n = fSide / step;
            if (n <= 1.4f)
            {
                newStep = fSide;
            }
            else if (fSide % step <= 0.3f * step)
            {
                newStep = step;
            }
            else
            {
                newStep = fSide / Mathematics.floor(fSide / step, 1.0);
                //step1 = step;
                //step2 = step;
                //while ((fSide % step) > (0.3f * step))
                //{
                //    step1 = step1 + 0.1f;
                //    if ((fSide % step1) <= (0.3f * step1))
                //        return step1;
                //    step2 = step2 - 0.1f;
                //    if ((fSide % step2) <= (0.3f * step2))
                //        return step2;
                //}
            }
            return(newStep);
        }
Esempio n. 2
0
        public float ScaleToFit(double _width, double _height)
        {
            float width = (float)_width, height = (float)_height;

            if (width == 0 && height == 0)
            {
                return(1.0f);
            }
            float prevScale = 1;
            float k         = (float)Mathematics.floor((scale >= 1.0f) ? scale : 1.0 / scale, 0.1);

            // максимизируем
            while (borders.Width < width || borders.Height < height)
            {
                prevScale = scale;
                IncreaseScale(ref k);
                RefreshBorders();
            }
            // минимизируем
            while (borders.Width > width && borders.Height > height)
            {
                prevScale = scale;
                DecreaseScale(ref k);
                RefreshBorders();
            }
            scale = prevScale;
            IncreaseScale(ref k);
            RefreshBorders();
            return(scale);
        }
        public static double ArcLength(double x1, double y1, double x2, double y2, double xc, double yc)
        {
            double a, b, c, angle;

            a = Mathematics.FindDist(x1, y1, x2, y2);
            b = Mathematics.FindDist(xc, yc, x1, y1);
            c = Mathematics.FindDist(xc, yc, x2, y2);

            angle = Math.Acos((b * b + c * c - a * a) / (2.0 * b * c));

            return(b * angle);
        }
        // метод для общих целей
        public static bool pointFitsArc(MyPoint point, MyArc arc, double precision)
        {
            double radius    = Mathematics.FindDist(arc.CenterPoint, arc.StartPoint);
            bool   pointFits = false;

            if (precision < 0)
            {
                double r = Mathematics.FindDist(arc.CenterPoint, arc.StartPoint);
                precision = r * 0.05;
            }
            pointFits = Math.Abs(Mathematics.FindDist(point, arc.CenterPoint) - radius) < precision;
            if (pointFits)
            {
                return(checkValidPointOnArc(point, arc));
            }
            else
            {
                return(false);
            }
        }
Esempio n. 5
0
 private void DecreaseScale(ref float k)
 {
     k = (float)Mathematics.floor(k, 0.1);
     if (scale > 1.0f)
     {
         k -= 0.1f;
     }
     else
     {
         k += 0.1f;
     }
     if (scale > 1.0f)
     {
         scale = k;
     }
     else
     {
         scale = 1.0f / k;
     }
 }
Esempio n. 6
0
        public void DrawBadElements(MyFiniteElement[] elems, double minAngle, double maxAngle, double minSqr, double maxSqr, GradationType colorGradationType)
        {
            int count = elems.Length * 3;

            if (count == 0)
            {
                return;
            }
            float[] pts = new float[count * 2];
            float[] cls = new float[count * 3];
            int     i = 0, j;
            double  midAngle = (maxAngle + minAngle) / 2;
            double  difAngle = midAngle - minAngle;

            foreach (MyFiniteElement FE in elems)
            {
                double[] angles = Mathematics.getFEangles(FE);
                double   feSqr  = Mathematics.GeronLaw(FE.Nodes);
                float[]  color  = null;
                switch (colorGradationType)
                {
                case GradationType.Angle:
                    if (minAngle > angles.Min() || maxAngle < angles.Max())
                    {
                        color = new float[] { 1.0f, 0, 0 }
                    }
                    ;
                    else
                    {
                        double howBad = Math.Max(Math.Abs(midAngle - angles.Min()), Math.Abs(midAngle - angles.Max()));
                        color = new float[] { (float)(howBad / difAngle), 1.0f - (float)(howBad / difAngle) / 3, 0 };
                    }
                    break;

                case GradationType.Square:
                    if (minSqr > feSqr)
                    {
                        color = new float[] { 1.0f, 0, 0 }
                    }
                    ;
                    else
                    {
                        double howBad = 1.0f - (feSqr - minSqr) / (maxSqr - minSqr);
                        color = new float[] { (float)(howBad), 1.0f - (float)howBad / 3f, 0 };
                    }
                    break;
                }
                for (j = 0; j < 9; j++)
                {
                    cls[(i * 9) + j] = color[j % 3];
                }
                pts[(i * 6)]     = (float)FE.Nodes[0].X;
                pts[(i * 6) + 1] = (float)FE.Nodes[0].Y;
                pts[(i * 6) + 2] = (float)FE.Nodes[1].X;
                pts[(i * 6) + 3] = (float)FE.Nodes[1].Y;
                pts[(i * 6) + 4] = (float)FE.Nodes[2].X;
                pts[(i * 6) + 5] = (float)FE.Nodes[2].Y;
                i++;
            }
            int list = Gl.glGenLists(1);

            Gl.glNewList(list, Gl.GL_COMPILE);
            Gl.glLineWidth((float)(1.0));
            Gl.glEndList();
            drawBuffer.Add(new DrawingOperation(Gl.GL_TRIANGLES, pts, list, cls));
        }
Esempio n. 7
0
        public void DrawForces(MyFiniteElementModel model, double scale, Color color, bool showValues = true)
        {
            MyNode[] forcedNodes = model.Nodes.FindAll(n => n.ForceX != 0.0 || n.ForceY != 0.0).ToArray();
            int      nodesCount  = forcedNodes.Length;

            if (nodesCount == 0)
            {
                return;
            }
            int count = 6 * nodesCount;

            float[] pts = new float[count * 2];
            Gl.glColor3dv(colorArray(color));

            for (int i = 0; i < nodesCount; i++)
            {
                MyNode node = forcedNodes[i];
                // силу будем рисовать, как линию со стрелочкой на конце. Если сила > 0, то она идет вверх или вправо ( зависит от нагрузки - по X или по Y)
                // плюс, надо еще масштабировать длину стрелки
                // координаты начальной и конечной точки в пикселях

                float forceLengthX = (float)node.ForceX;
                float forceLengthY = (float)node.ForceY;
                float x1           = (float)node.X;
                float y1           = (float)node.Y;
                float x2           = x1 + forceLengthX * (float)scale; // масштабируем длину стрелки
                float y2           = y1 + forceLengthY * (float)scale; // масштабируем длину стрелки

                pts[(i * 12)]     = x1;
                pts[(i * 12) + 1] = y1;
                pts[(i * 12) + 2] = x2;
                pts[(i * 12) + 3] = y2;

                // вычисляем угол нагрузки
                float alfa = (float)Math.Atan2(y2 - y1, x2 - x1);
                // длина стрелочки
                float aSize = (float)Math.Pow(((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)), 0.5) / 10.0f;

                float px1 = x2;
                float py1 = y2;
                float px2 = (float)(x2 - aSize * Math.Cos(alfa + 15.0 * (Math.PI / 180.0)));
                float py2 = (float)(y2 - aSize * Math.Sin(alfa + 15.0 * (Math.PI / 180.0)));
                float px3 = (float)(x2 - aSize * Math.Cos(alfa - 15.0 * (Math.PI / 180.0)));
                float py3 = (float)(y2 - aSize * Math.Sin(alfa - 15.0 * (Math.PI / 180.0)));

                pts[(i * 12) + 4] = px1;
                pts[(i * 12) + 5] = py1;
                pts[(i * 12) + 6] = px2;
                pts[(i * 12) + 7] = py2;

                pts[(i * 12) + 8]  = px1;
                pts[(i * 12) + 9]  = py1;
                pts[(i * 12) + 10] = px3;
                pts[(i * 12) + 11] = py3;

                if (showValues)
                {
                    float  f      = (float)Math.Pow((Math.Pow(node.ForceX, 2) + Math.Pow(node.ForceY, 2)), 0.5);
                    double fRound = Mathematics.floor(f, Mathematics.accuracy_medium);
                    DrawString(fRound.ToString(), x2, y2, true);
                }
            }
            int list;

            list = Gl.glGenLists(1);
            Gl.glNewList(list, Gl.GL_COMPILE);
            Gl.glColor3dv(colorArray(color));
            Gl.glLineWidth(1.0f);
            Gl.glEndList();
            drawBuffer.Add(new DrawingOperation(Gl.GL_LINES, pts, list));
            if (showValues)
            {
                FlushText(color);
            }
        }