示例#1
0
        private void CreateTrianglesWithPotential()
        {
            trianglesWithPotential.Clear();
            foreach (Triangle triangle in list_triangles)
            {
                TrianglePotential TP = new TrianglePotential();

                foreach (Potential pot in allPotential)
                {
                    if (pot.point == triangle.point1)
                    {
                        TP.point1.point = triangle.point1; TP.point1.value = pot.value; continue;
                    }
                    if (pot.point == triangle.point2)
                    {
                        TP.point2.point = triangle.point2; TP.point2.value = pot.value; continue;
                    }
                    if (pot.point == triangle.point3)
                    {
                        TP.point3.point = triangle.point3; TP.point3.value = pot.value; continue;
                    }
                }
                trianglesWithPotential.Add(TP);
            }
        }
示例#2
0
        public List <LevelLines> GetForceLines()
        {
            int size_triangles = triangles.Count;
            int size_magnet1   = magnet1.Count;
            int size_magnet2   = magnet2.Count;

            forceLines.Clear();
            for (int i = 0; i < size_magnet1; ++i)
            {
                Potential pot           = magnet1[i];
                PointF    reducentPoint = new PointF();
                reducentPoint = pot.point;


                int num_triangle                 = 0;
                TrianglePotential triangle       = new TrianglePotential();
                PointF            passPoint1     = new PointF();
                PointF            passPoint2     = new PointF();
                PointF            mainPoint      = new PointF();
                PointF            pointIntersect = new PointF(); //точка пересечения
                /*Поиск любого треугольника на границе магнита содержащего точку pot*/
                for (int j = 0; j < size_triangles; j++)
                {
                    if (pot.point == triangles[j].point1.point)
                    {
                        num_triangle = j;
                        passPoint1   = pot.point;
                        passPoint2   = triangles[j].point2.point;
                        mainPoint    = triangles[j].point3.point;
                        break;
                    }
                    if (pot.point == triangles[j].point2.point)
                    {
                        num_triangle = j;
                        passPoint1   = pot.point;
                        passPoint2   = triangles[j].point1.point;
                        mainPoint    = triangles[j].point3.point;
                        break;
                    }
                    if (pot.point == triangles[j].point3.point)
                    {
                        num_triangle = j;
                        passPoint1   = pot.point;
                        passPoint2   = triangles[j].point2.point;
                        mainPoint    = triangles[j].point1.point;
                        break;
                    }
                }
                triangle = triangles[num_triangle];

                float A = -DpDx(triangle.point1, triangle.point2, triangle.point3);
                float B = -DpDy(triangle.point1, triangle.point2, triangle.point3);

                //крайняя точка градиента
                pointIntersect.X = (passPoint1.X + passPoint2.X) / 2;
                pointIntersect.Y = (passPoint1.Y + passPoint2.Y) / 2;
                pot.point        = pointIntersect;
                PointF pot2 = new PointF {
                    X = pot.point.X + A, Y = pot.point.Y + B
                };


                LevelLines line = new LevelLines();

                PointF futureBoardPoint1 = new PointF();     //точки стороны, с которой будет пересечение градиента
                PointF futureBoardPoint2 = new PointF();



                //Пробую найти пересечение с однйо из сторон треугольника
                float ka = 0, kb = 0;
                ka = Ua(mainPoint, passPoint2, pot.point, pot2);
                kb = Ub(mainPoint, passPoint2, pot.point, pot2);
                PointF intersectBuf = new PointF();
                if (ka <= 1 && ka >= 0)
                {
                    intersectBuf.X    = mainPoint.X + ka * (passPoint2.X - mainPoint.X);
                    intersectBuf.Y    = mainPoint.Y + ka * (passPoint2.Y - mainPoint.Y);
                    futureBoardPoint1 = mainPoint;
                    futureBoardPoint2 = passPoint2;
                    reducentPoint     = passPoint1;

                    pointIntersect = intersectBuf;
                    line.point1    = pot.point;
                    line.point2    = pointIntersect;

                    forceLines.Add(line);
                }
                else
                {
                    ka = Ua(mainPoint, passPoint1, pot.point, pot2);
                    kb = Ub(mainPoint, passPoint1, pot.point, pot2);

                    if (ka <= 1 && ka >= 0)
                    {
                        intersectBuf.X    = mainPoint.X + ka * (passPoint1.X - mainPoint.X);
                        intersectBuf.Y    = mainPoint.Y + ka * (passPoint1.Y - mainPoint.Y);
                        futureBoardPoint1 = mainPoint;
                        futureBoardPoint2 = passPoint1;
                        reducentPoint     = passPoint2;

                        pointIntersect = intersectBuf;
                        line.point1    = pot.point;
                        line.point2    = pointIntersect;

                        forceLines.Add(line);
                    }
                }


                for (int z = 0; z < 200; z++)
                {
                    triangle   = new TrianglePotential();
                    passPoint1 = new PointF();
                    passPoint2 = new PointF();
                    mainPoint  = new PointF();
                    /*Поиск любого треугольника содержащего точки futureBoardPoints*/
                    for (int j = 0; j < size_triangles; j++)
                    {
                        TrianglePotential tr = new TrianglePotential();
                        tr = triangles[j];
                        if (futureBoardPoint1 == tr.point1.point && futureBoardPoint2 == tr.point2.point && reducentPoint != tr.point3.point)
                        {
                            num_triangle = j;
                            passPoint1   = tr.point1.point;
                            passPoint2   = tr.point2.point;
                            mainPoint    = tr.point3.point;
                        }
                        if (futureBoardPoint1 == tr.point1.point && futureBoardPoint2 == tr.point3.point && reducentPoint != tr.point2.point)
                        {
                            num_triangle = j;
                            passPoint1   = tr.point1.point;
                            passPoint2   = tr.point3.point;
                            mainPoint    = tr.point2.point;
                        }
                        if (futureBoardPoint1 == tr.point2.point && futureBoardPoint2 == tr.point1.point && reducentPoint != tr.point3.point)
                        {
                            num_triangle = j;
                            passPoint1   = tr.point2.point;
                            passPoint2   = tr.point1.point;
                            mainPoint    = tr.point3.point;
                        }
                        if (futureBoardPoint1 == tr.point2.point && futureBoardPoint2 == tr.point3.point && reducentPoint != tr.point1.point)
                        {
                            num_triangle = j;
                            passPoint1   = tr.point2.point;
                            passPoint2   = tr.point3.point;
                            mainPoint    = tr.point1.point;
                        }
                        if (futureBoardPoint1 == tr.point3.point && futureBoardPoint2 == tr.point2.point && reducentPoint != tr.point1.point)
                        {
                            num_triangle = j;
                            passPoint1   = tr.point3.point;
                            passPoint2   = tr.point2.point;
                            mainPoint    = tr.point1.point;
                        }
                        if (futureBoardPoint1 == tr.point3.point && futureBoardPoint2 == tr.point1.point && reducentPoint != tr.point2.point)
                        {
                            num_triangle = j;
                            passPoint1   = tr.point1.point;
                            passPoint2   = tr.point3.point;
                            mainPoint    = tr.point2.point;
                        }
                    }

                    triangle = triangles[num_triangle];

                    A = -DpDx(triangle.point1, triangle.point2, triangle.point3);
                    B = -DpDy(triangle.point1, triangle.point2, triangle.point3);

                    pot.point = pointIntersect;
                    pot2.X    = pot.point.X + A;
                    pot2.Y    = pot.point.Y + B;



                    //Пробую найти пересечение с однйо из сторон треугольника
                    ka           = 0; kb = 0;
                    ka           = Ua(mainPoint, passPoint2, pot.point, pot2);
                    kb           = Ub(mainPoint, passPoint2, pot.point, pot2);
                    intersectBuf = new PointF();
                    if (ka <= 1 && ka >= 0)
                    {
                        intersectBuf.X    = mainPoint.X + ka * (passPoint2.X - mainPoint.X);
                        intersectBuf.Y    = mainPoint.Y + ka * (passPoint2.Y - mainPoint.Y);
                        futureBoardPoint1 = mainPoint;
                        futureBoardPoint2 = passPoint2;
                        reducentPoint     = passPoint1;

                        pointIntersect = intersectBuf;
                        line.point1    = pot.point;
                        line.point2    = pointIntersect;

                        forceLines.Add(line);
                    }
                    else
                    {
                        ka = Ua(mainPoint, passPoint1, pot.point, pot2);
                        kb = Ub(mainPoint, passPoint1, pot.point, pot2);

                        if (ka <= 1 && ka >= 0)
                        {
                            intersectBuf.X    = mainPoint.X + ka * (passPoint1.X - mainPoint.X);
                            intersectBuf.Y    = mainPoint.Y + ka * (passPoint1.Y - mainPoint.Y);
                            futureBoardPoint1 = mainPoint;
                            futureBoardPoint2 = passPoint1;
                            reducentPoint     = passPoint2;



                            pointIntersect = intersectBuf;
                            line.point1    = pot.point;
                            line.point2    = pointIntersect;

                            forceLines.Add(line);
                        }
                    }
                }
            }
            for (int i = 0; i < size_magnet2; ++i)
            {
                Potential pot           = magnet2[i];
                PointF    reducentPoint = new PointF();
                reducentPoint = pot.point;

                // if (pot.value > 0)
                // {
                int num_triangle                 = 0;
                TrianglePotential triangle       = new TrianglePotential();
                PointF            passPoint1     = new PointF();
                PointF            passPoint2     = new PointF();
                PointF            mainPoint      = new PointF();
                PointF            pointIntersect = new PointF(); //точка пересечения
                /*Поиск любого треугольника на границе магнита содержащего точку pot*/
                for (int j = 0; j < size_triangles; j++)
                {
                    if (pot.point == triangles[j].point1.point)
                    {
                        num_triangle = j;
                        passPoint1   = pot.point;
                        passPoint2   = triangles[j].point2.point;
                        mainPoint    = triangles[j].point3.point;
                        break;
                    }
                    if (pot.point == triangles[j].point2.point)
                    {
                        num_triangle = j;
                        passPoint1   = pot.point;
                        passPoint2   = triangles[j].point1.point;
                        mainPoint    = triangles[j].point3.point;
                        break;
                    }
                    if (pot.point == triangles[j].point3.point)
                    {
                        num_triangle = j;
                        passPoint1   = pot.point;
                        passPoint2   = triangles[j].point2.point;
                        mainPoint    = triangles[j].point1.point;
                        break;
                    }
                }
                triangle = triangles[num_triangle];

                float A = -DpDx(triangle.point1, triangle.point2, triangle.point3);
                float B = -DpDy(triangle.point1, triangle.point2, triangle.point3);

                //крайняя точка градиента
                pointIntersect.X = (passPoint1.X + passPoint2.X) / 2;
                pointIntersect.Y = (passPoint1.Y + passPoint2.Y) / 2;
                pot.point        = pointIntersect;
                PointF pot2 = new PointF {
                    X = pot.point.X + A, Y = pot.point.Y + B
                };


                LevelLines line = new LevelLines();

                PointF futureBoardPoint1 = new PointF();     //точки стороны, с которой будет пересечение градиента
                PointF futureBoardPoint2 = new PointF();



                //Пробую найти пересечение с однйо из сторон треугольника
                float ka = 0, kb = 0;
                ka = Ua(mainPoint, passPoint2, pot.point, pot2);
                kb = Ub(mainPoint, passPoint2, pot.point, pot2);
                PointF intersectBuf = new PointF();
                if (ka <= 1 && ka >= 0)
                {
                    intersectBuf.X    = mainPoint.X + ka * (passPoint2.X - mainPoint.X);
                    intersectBuf.Y    = mainPoint.Y + ka * (passPoint2.Y - mainPoint.Y);
                    futureBoardPoint1 = mainPoint;
                    futureBoardPoint2 = passPoint2;
                    reducentPoint     = passPoint1;

                    pointIntersect = intersectBuf;
                    line.point1    = pot.point;
                    line.point2    = pointIntersect;

                    forceLines.Add(line);
                }
                else
                {
                    ka = Ua(mainPoint, passPoint1, pot.point, pot2);
                    kb = Ub(mainPoint, passPoint1, pot.point, pot2);

                    if (ka <= 1 && ka >= 0)
                    {
                        intersectBuf.X    = mainPoint.X + ka * (passPoint1.X - mainPoint.X);
                        intersectBuf.Y    = mainPoint.Y + ka * (passPoint1.Y - mainPoint.Y);
                        futureBoardPoint1 = mainPoint;
                        futureBoardPoint2 = passPoint1;
                        reducentPoint     = passPoint2;

                        pointIntersect = intersectBuf;
                        line.point1    = pot.point;
                        line.point2    = pointIntersect;

                        forceLines.Add(line);
                    }
                }


                for (int z = 0; z < 200; z++)
                {
                    triangle   = new TrianglePotential();
                    passPoint1 = new PointF();
                    passPoint2 = new PointF();
                    mainPoint  = new PointF();
                    /*Поиск любого треугольника содержащего точки futureBoardPoints*/
                    for (int j = 0; j < size_triangles; j++)
                    {
                        TrianglePotential tr = new TrianglePotential();
                        tr = triangles[j];
                        if (futureBoardPoint1 == tr.point1.point && futureBoardPoint2 == tr.point2.point && reducentPoint != tr.point3.point)
                        {
                            num_triangle = j;
                            passPoint1   = tr.point1.point;
                            passPoint2   = tr.point2.point;
                            mainPoint    = tr.point3.point;
                        }
                        if (futureBoardPoint1 == tr.point1.point && futureBoardPoint2 == tr.point3.point && reducentPoint != tr.point2.point)
                        {
                            num_triangle = j;
                            passPoint1   = tr.point1.point;
                            passPoint2   = tr.point3.point;
                            mainPoint    = tr.point2.point;
                        }
                        if (futureBoardPoint1 == tr.point2.point && futureBoardPoint2 == tr.point1.point && reducentPoint != tr.point3.point)
                        {
                            num_triangle = j;
                            passPoint1   = tr.point2.point;
                            passPoint2   = tr.point1.point;
                            mainPoint    = tr.point3.point;
                        }
                        if (futureBoardPoint1 == tr.point2.point && futureBoardPoint2 == tr.point3.point && reducentPoint != tr.point1.point)
                        {
                            num_triangle = j;
                            passPoint1   = tr.point2.point;
                            passPoint2   = tr.point3.point;
                            mainPoint    = tr.point1.point;
                        }
                        if (futureBoardPoint1 == tr.point3.point && futureBoardPoint2 == tr.point2.point && reducentPoint != tr.point1.point)
                        {
                            num_triangle = j;
                            passPoint1   = tr.point3.point;
                            passPoint2   = tr.point2.point;
                            mainPoint    = tr.point1.point;
                        }
                        if (futureBoardPoint1 == tr.point3.point && futureBoardPoint2 == tr.point1.point && reducentPoint != tr.point2.point)
                        {
                            num_triangle = j;
                            passPoint1   = tr.point1.point;
                            passPoint2   = tr.point3.point;
                            mainPoint    = tr.point2.point;
                        }
                    }

                    triangle = triangles[num_triangle];

                    A = -DpDx(triangle.point1, triangle.point2, triangle.point3);
                    B = -DpDy(triangle.point1, triangle.point2, triangle.point3);

                    pot.point = pointIntersect;
                    pot2.X    = pot.point.X + A;
                    pot2.Y    = pot.point.Y + B;



                    //Пробую найти пересечение с однйо из сторон треугольника
                    ka           = 0; kb = 0;
                    ka           = Ua(mainPoint, passPoint2, pot.point, pot2);
                    kb           = Ub(mainPoint, passPoint2, pot.point, pot2);
                    intersectBuf = new PointF();
                    if (ka <= 1 && ka >= 0)
                    {
                        intersectBuf.X    = mainPoint.X + ka * (passPoint2.X - mainPoint.X);
                        intersectBuf.Y    = mainPoint.Y + ka * (passPoint2.Y - mainPoint.Y);
                        futureBoardPoint1 = mainPoint;
                        futureBoardPoint2 = passPoint2;
                        reducentPoint     = passPoint1;

                        pointIntersect = intersectBuf;
                        line.point1    = pot.point;
                        line.point2    = pointIntersect;

                        forceLines.Add(line);
                    }
                    else
                    {
                        ka = Ua(mainPoint, passPoint1, pot.point, pot2);
                        kb = Ub(mainPoint, passPoint1, pot.point, pot2);

                        if (ka <= 1 && ka >= 0)
                        {
                            intersectBuf.X    = mainPoint.X + ka * (passPoint1.X - mainPoint.X);
                            intersectBuf.Y    = mainPoint.Y + ka * (passPoint1.Y - mainPoint.Y);
                            futureBoardPoint1 = mainPoint;
                            futureBoardPoint2 = passPoint1;
                            reducentPoint     = passPoint2;



                            pointIntersect = intersectBuf;
                            line.point1    = pot.point;
                            line.point2    = pointIntersect;

                            forceLines.Add(line);
                        }
                    }
                }


                //  }
            }
            return(forceLines);
        }