Exemplo n.º 1
0
        public void Init(ref DataP3[] _dataPoints)
        {
            this.dataPoints = _dataPoints;
            this.numDataPoints = dataPoints.Length;

            double minX = 0; double maxX = 0;
            double minY = 0; double maxY = 0;
            DataP3.FindMinMaxCoordinates(dataPoints,ref minX, ref maxX, ref minY, ref maxY);
            double widthNetX = (maxX - minX);
            double widthNetY = (maxY - minY);
            int cellWidth = 1;
            int kx = (int)(widthNetX / cellWidth) + 1;
            int ky = (int)(widthNetY / cellWidth) + 1;
            int numTargetPoints = kx * ky * 4;
            targetPoints = new DataP3[2 * kx, 2 * ky];

            int index = 0;
            for (double i = 0; i < kx; i += 0.5)
            {
                double x = minX + i * cellWidth;
                for (double j = 0; j < ky; j += 0.5)
                {
                    double y = minY + j * cellWidth;
                    targetPoints[(int)(2*i),(int)(2*j)] = new DataP3(x, y, 0);
                    index++;
                }
            }
        }
Exemplo n.º 2
0
        static void DrawIsoline(DataP3[,] Points, float H, ref PaintEventArgs e)
        {
            List<PointF> crossPoints = new List<PointF>();
            int rows = Points.GetLength(0);
            int cols = Points.GetLength(1);

            for (int i = 0; i < rows-1; i++)
            {
                for (int j = 0; j < cols-1; j++)
                {
                    DataP3 crPoint;
                    //up
                    crPoint = CheckExpression(Points[i, j], Points[i, j + 1], H);
                    if (crPoint.H != -1)
                        crossPoints.Add((PointF)crPoint);
                    //right
                    crPoint = CheckExpression(Points[i, j + 1], Points[i + 1, j + 1], H);
                    if (crPoint.H != -1)
                        crossPoints.Add((PointF)crPoint);
                    //down
                    crPoint = CheckExpression(Points[i + 1, j + 1], Points[i + 1, j], H);
                    if (crPoint.H != -1)
                        crossPoints.Add((PointF)crPoint);
                    //left
                    crPoint = CheckExpression(Points[i + 1, j], Points[i, j], H);
                    if (crPoint.H != -1)
                        crossPoints.Add((PointF)crPoint);

                    if (crossPoints.Count > 1 && crossPoints.Count < 4)
                        DrawCrossLines(crossPoints, ref e);
                    crossPoints.Clear();
                }
            }
        }
Exemplo n.º 3
0
 public DataP3[] FindPath(float x1, float y1, float x2, float y2)
 {
     DataP3 start = new DataP3(x1,y1, ObjectiveFunc(x1,y1));
     DataP3 finish = new DataP3(x2,y2, ObjectiveFunc(x2,y2));
     this.pathAlgorithm = new PathAlgorithm(start, finish,ref Algorithm.instance);
     return this.pathAlgorithm.FindPath();
 }
Exemplo n.º 4
0
 public void DrawPath(DataP3[] path)
 {
     Pen pen = new Pen(Color.BlueViolet, 0.05f);
     Pen pen1 = new Pen(Color.Green, 0.0f);
     graphics.DrawLines(pen, DataP3.ToPointFArray(path));
     //e.Graphics.DrawCurve(pen, DataP3.ToPointFArray(path));
 }
Exemplo n.º 5
0
        static DataP3 CrossPoint(DataP3 p1, DataP3 p2, float H)
        {
            double deltaH = (H - p1.H) / (p2.H - p1.H);
            double x = 0.0f;
            double y = 0.0f;

            if ((p1.X < p2.X) || (p1.X > p2.X))
            {
                x = Math.Min(p1.X, p2.X) + deltaH;
                y = p1.Y;
            }

            if ((p1.Y < p2.Y) || (p1.Y > p2.Y))
            {
                x = p1.X;
                y = Math.Min(p1.Y, p2.Y) + deltaH;
            }

            //if (p1.X > p2.X)
            //{ x = p2.X + deltaH; y = p2.y; }

            //if (p1.Y > p2.Y)
            //{ x = p2.X; y = p2.y + deltaH; }

            return new DataP3(x,y,H);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Запись в файл
 /// </summary>
 /// <param name="dataPoints">Исходные точки</param>
 /// <param name="targetPoints">Точки регулярной сетки</param>
 /// <param name="fileName">Имя файла записи</param>
 public void Write(ref DataP3[] dataPoints, ref DataP3[,] targetPoints, string fileName)
 {
     Init(fileName);
     if (dataPoints.Length != 0)
     {
         _workSheet.Cells[1, 1] = "X";
         _workSheet.Cells[1, 2] = "Y";
         _workSheet.Cells[1, 3] = "H";
         for (int i = 0; i < dataPoints.Length; i++) // по всем строкам
         {
             _workSheet.Cells[i + 2, 1] = dataPoints[i].X;
             _workSheet.Cells[i + 2, 2] = dataPoints[i].Y;
             _workSheet.Cells[i + 2, 3] = dataPoints[i].H;
         }
     }
     if (targetPoints.Length != 0)
     {
         _workSheet = _workSheet.Next;
         _workSheet.Cells[1, 1] = "X";
         _workSheet.Cells[1, 2] = "Y";
         _workSheet.Cells[1, 3] = "H";
         int indexCell = 2;
         for (int i = 0; i < targetPoints.GetLength(0); i++) // по всем строкам
             for (int j = 0; j < targetPoints.GetLength(1); j++)
             {
                 _workSheet.Cells[indexCell, 1] = targetPoints[i,j].X;
                 _workSheet.Cells[indexCell, 2] = targetPoints[i,j].Y;
                 _workSheet.Cells[indexCell, 3] = targetPoints[i,j].H;
                 indexCell++;
             }
     }
     _application.Visible = true;//открываем файл
 }
 public _3DSurfaceForm(DataP3[] _data, string _dataType)
 {
     InitializeComponent();
     control = Controller.getInstance();
     data = _data;
     dataType = _dataType;
     Init();
 }
Exemplo n.º 8
0
 static DataP3 CheckExpression(DataP3 p1, DataP3 p2, float H)
 {
     if (
         ((p1.H - H) < 0 && (H - p2.H) < 0) ||
         ((p1.H - H) > 0 && (H - p2.H) > 0)
       )
     { return CrossPoint(p1, p2, H); }
     else return new DataP3(0,0,-1);
 }
Exemplo n.º 9
0
 public void DrawAllIsolines(DataP3[,] Points)
 {
     double minH = 0;
     double maxH=0;
     DataP3.FindMinMaxHeight(Points, ref minH, ref maxH);
     for (float i = (float)minH; i <= maxH; i+=0.5f) {
         DrawIsoline(Points, i);
     }
 }
Exemplo n.º 10
0
 //Генерация сетки тестовой поверхности
 public static void GenerateTestSurface(ref DataP3[] surface, int lenght)
 {
     int num = 0;
     for (double i = 0; i < lenght; i += 0.05)
         for (double j = 0; j < lenght; j += 0.05)
         {
             double z = TestFunc(i, j);
             surface[num] = new DataP3(i, j, z);
             num++;
         }
 }
Exemplo n.º 11
0
 //Генерация исходных тестовых точек
 public static void GenerateTestData(ref DataP3[] data, int lenght, int max)
 {
     Random r = new Random();
     double x; double y; double z;
     for (int i = 0; i < lenght; i++)
     {
         x = r.NextDouble() * max;
         y = r.NextDouble() * max;
         z = TestFunc(x, y);
         data[i] = new DataP3(x, y, z);
     }
 }
Exemplo n.º 12
0
        public _3DSurfaceForm(DataP3[,] _data, string _dataType)
        {
            InitializeComponent();
            control = Controller.getInstance();

            data = new DataP3[_data.Length];
            int indexArr = 0;
            for (int i = 0; i < _data.GetLength(0); i++)
            {
                for (int j = 0; j < _data.GetLength(0); j++)
                {
                    data[indexArr] = _data[i, j];
                    indexArr++;
                }
            }

            dataType = _dataType;
            Init();
        }
Exemplo n.º 13
0
 public static Algorithm getInstance(ref DataP3[] _dataPoints)
 {
     if (instance == null) instance = new Algorithm(ref _dataPoints);
     return instance;
 }
Exemplo n.º 14
0
        private int type; //Тип весовой ф-ии

        #endregion Fields

        #region Constructors

        private Algorithm(ref DataP3[] _dataPoints)
        {
            Init(ref _dataPoints);
        }
Exemplo n.º 15
0
 public static void DrawAllIsolines(DataP3[,] Points, ref PaintEventArgs e)
 {
     DrawIsoline(Points, 0.5f, ref e);
 }
Exemplo n.º 16
0
        static DataP3 CrossPoint(DataP3 p1, DataP3 p2, float H)
        {
            //double deltaH = (H - p1.H) / (p2.H - p1.H);
            double x = 0.0f;
            double y = 0.0f;

            /*
            if ((p1.X < p2.X) || (p1.X > p2.X))
            {
                y = p1.Y;
                //x = (Math.Abs(H - p1.H) < Math.Abs(H - p2.H)) ? p1.X : p2.X;
                x = p1.X;
                x += deltaH;
            }

            if ((p1.Y < p2.Y) || (p1.Y > p2.Y))
            {
                x = p1.X;
                //y = (Math.Abs(H - p1.H) < Math.Abs(H - p2.H)) ? p1.Y : p2.Y;
                y = p1.Y;
                y += deltaH;
            }
            */

            if ((p1.X < p2.X) || (p1.X > p2.X))
            {
                if (Math.Abs(H - p1.H) < Math.Abs(H - p2.H))
                {
                    double deltaH = (H - p1.H) / (p2.H - p1.H);
                    x = p1.X;
                    if (p1.X < p2.X)
                        x += deltaH;
                    else
                        x -= deltaH;
                }
                else
                {
                    double deltaH = (H - p2.H) / (p1.H - p2.H);
                    x = p2.X;
                    if (p1.X > p2.X)
                        x += deltaH;
                    else
                        x -= deltaH;
                }
                y = p1.Y;
            }

            if ((p1.Y < p2.Y) || (p1.Y > p2.Y))
            {
                if (Math.Abs(H - p1.H) < Math.Abs(H - p2.H))
                {
                    double deltaH = (H - p1.H) / (p2.H - p1.H);
                    y = p1.Y;
                    if (p1.Y < p2.Y)
                        y += deltaH;
                    else
                        y -= deltaH;
                }
                else
                {
                    double deltaH = (H - p2.H) / (p1.H - p2.H);
                    y = p2.Y;
                    if (p1.Y > p2.Y)
                        y += deltaH;
                    else
                        y -= deltaH;
                }
                x = p1.X;
            }

            return new DataP3(x, y, H);
        }