123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Uninpho.Railway.Waveform
- {
- class MathTools
- {
- string type = "";
- static int bs = 150;
- public List<float> xAxis = new List<float>();
- public List<float> xAxisF = new List<float>();
- public List<string> AxisValue = new List<string>();
- static double[] MaxMinArr;
- static double step = 10;
- static double[] clolist;
-
-
- public MathTools(string type)
- {
- this.type = type;
- }
- public void MathLoad(List<PointF> mycoor, int coutt)
- {
- MaxMinArr = ZuiZhiFanWei(mycoor);
- step = (MaxMinArr[0] - MaxMinArr[1]) / (coutt + 5);
-
-
-
-
-
-
-
-
-
- clolist = JiSuanChaValue(MaxMinArr[0], MaxMinArr[1], coutt);
- }
-
-
-
-
-
-
-
-
-
-
-
- public PointF[] getDrawPoints(List<PointF> mycoor, int Width, int Height, int OffsetX, int OffsetY, ref string revalue)
- {
- AxisValue.Clear();
- xAxis.Clear();
- xAxisF.Clear();
- List<PointF> points = new List<PointF>();
- List<PointF> pointtemp = new List<PointF>();
- PointF temp = new PointF();
- int index = 0;
- int indexqian = -1;
- for (int i = 0; i < mycoor.Count; i++)
- {
- if (mycoor[i].X >= MaxMinArr[1] + step * (OffsetX - 15) && mycoor[i].X <= MaxMinArr[1] + (OffsetX + bs) * step)
- {
- if (indexqian == -1)
- {
- indexqian = i;
- }
- if (mycoor[i].X >= MaxMinArr[1] + step * (OffsetX) && mycoor[i].X <= MaxMinArr[1] + (OffsetX + 10) * step)
- {
- temp = mycoor[i];
- }
- PointF p = GuiFiHua(mycoor[i], new double[] { MaxMinArr[1] + (OffsetX + 10) * step, MaxMinArr[1] + step * OffsetX, MaxMinArr[2], MaxMinArr[3] }, Height, Width);
-
- p.X -= OffsetX * 2;
- p.Y += OffsetY;
- pointtemp.Add(p);
- index = i;
- }
-
-
-
-
-
-
- }
- if (pointtemp[0].X > 0 && indexqian > 0)
- {
-
-
- PointF p = GuiFiHua(mycoor[indexqian - 1], new double[] { MaxMinArr[1] + (OffsetX + 10) * step, MaxMinArr[1] + step * OffsetX, MaxMinArr[2], MaxMinArr[3] }, Height, Width);
- p.X -= OffsetX * 2;
- p.Y += OffsetY;
- List<PointF> newlis = new List<PointF>() { p };
- pointtemp.InsertRange(0, newlis);
- }
- if (pointtemp[pointtemp.Count - 1].X < Width && index < mycoor.Count - 1)
- {
-
-
- PointF p = GuiFiHua(mycoor[index + 1], new double[] { MaxMinArr[1] + (OffsetX + 10) * step, MaxMinArr[1] + step * OffsetX, MaxMinArr[2], MaxMinArr[3] }, Height, Width);
- p.X -= OffsetX * 2;
- p.Y += OffsetY;
- pointtemp.Add(p);
- }
- for (int i = 0; i < clolist.Length; i++)
- {
- if (clolist[i] >= MaxMinArr[1] + step * (OffsetX - 15) && clolist[i] <= MaxMinArr[1] + (OffsetX + bs) * step)
- {
- PointF p = GuiFiHua(new PointF((float)clolist[i], 0), new double[] { MaxMinArr[1] + (OffsetX + 10) * step, MaxMinArr[1] + step * OffsetX, MaxMinArr[2], MaxMinArr[3] }, Height, Width);
- p.X -= OffsetX * 2;
- if ((i + 6) % 6 == 0)
- {
- xAxis.Add(p.X);
- AxisValue.Add(foo(clolist[i], 7).ToString());
- }
- else if ((i + 1) % 1 == 0)
- {
- xAxisF.Add(p.X);
- }
- }
- }
-
- revalue = foo(temp.Y, 5).ToString();
-
- return pointtemp.ToArray();
- }
- public PointF[] getDrawPointsOld(List<PointF> mycoor, int Width, int Height, int OffsetX, int OffsetY, int pianyi)
- {
- List<PointF> points = new List<PointF>();
- List<PointF> pointtemp = new List<PointF>();
- PointF temp = new PointF();
- int index = 0;
- int indexqian = -1;
- for (int i = 0; i < mycoor.Count; i++)
- {
- if (mycoor[i].X >= MaxMinArr[1] + step * (OffsetX - 15) && mycoor[i].X <= MaxMinArr[1] + (OffsetX + bs) * step)
- {
- if (indexqian == -1)
- {
- indexqian = i;
- }
- if (mycoor[i].X >= MaxMinArr[1] + step * (OffsetX) && mycoor[i].X <= MaxMinArr[1] + (OffsetX + 10) * step)
- {
- temp = mycoor[i];
- }
- PointF p = GuiFiHua(mycoor[i], new double[] { MaxMinArr[1] + (OffsetX + 10) * step, MaxMinArr[1] + step * OffsetX, MaxMinArr[2], MaxMinArr[3] }, Height, Width);
-
- p.X -= OffsetX * 2 + pianyi;
- p.Y += OffsetY;
- pointtemp.Add(p);
- index = i;
- }
- }
- if (pointtemp[0].X > 0 && indexqian > 0)
- {
-
-
- PointF p = GuiFiHua(mycoor[indexqian - 1], new double[] { MaxMinArr[1] + (OffsetX + 10) * step, MaxMinArr[1] + step * OffsetX, MaxMinArr[2], MaxMinArr[3] }, Height, Width);
- p.X -= OffsetX * 2 + pianyi;
- p.Y += OffsetY;
- List<PointF> newlis = new List<PointF>() { p };
- pointtemp.InsertRange(0, newlis);
- }
- if (pointtemp[pointtemp.Count - 1].X < Width && index < mycoor.Count - 1)
- {
-
-
- PointF p = GuiFiHua(mycoor[index + 1], new double[] { MaxMinArr[1] + (OffsetX + 10) * step, MaxMinArr[1] + step * OffsetX, MaxMinArr[2], MaxMinArr[3] }, Height, Width);
- p.X -= OffsetX * 2 + pianyi;
- p.Y += OffsetY;
- pointtemp.Add(p);
- }
- return pointtemp.ToArray();
- }
-
-
-
-
-
-
-
-
- public PointF GuiFiHua(PointF x0, double[] MaxMinArr, int Height, int Width)
- {
- float x = (float)(Width * (x0.X - MaxMinArr[1]) / (MaxMinArr[0] - MaxMinArr[1]));
- var zore = 0.0;
- if (Math.Abs(MaxMinArr[2]) + Math.Abs(MaxMinArr[3]) > Math.Abs(MaxMinArr[2] + MaxMinArr[3]))
- {
- zore = -MaxMinArr[3] / (MaxMinArr[2] - MaxMinArr[3]);
- }
- float y = 0.0F;
- if (MaxMinArr[2] == MaxMinArr[3])
- {
- y = (float)Height;
- }
- else
- {
- y = (float)((Height / 2) * ((x0.Y - MaxMinArr[3]) / (MaxMinArr[2] - MaxMinArr[3]) - zore));
- }
- return new PointF(x, y);
- }
-
-
-
-
-
-
- public double[] ZuiZhiFanWei(List<PointF> mycoor)
- {
- double ymax = -999999999, ymin = 999999999, xmin = 999999999, xmax = -999999999;
- foreach (var item in mycoor)
- {
- if (item.Y >= ymax)
- {
- ymax = item.Y;
- }
- if (item.Y < ymin)
- {
- ymin = item.Y;
- }
- if (item.X < xmin)
- {
- xmin = item.X;
- }
- if (item.X >= xmax)
- {
- xmax = item.X;
- }
- }
- return new double[] { xmax, xmin, ymax, ymin };
- }
-
-
-
- public int PYLJZ(double offset, double constOffset, int height, int step)
- {
- return (int)((height - (offset + constOffset) * height) / step) * step;
- }
-
-
-
-
-
-
- public double foo(double d, int n)
- {
- if (d == 0.0) return 0;
- if (d > 1 || d < -1)
- n = n - (int)Math.Log10(Math.Abs(d)) - 1;
- else
- n = n + (int)Math.Log10(1.0 / Math.Abs(d));
- if (n < 0)
- {
- d = (int)(d / Math.Pow(10, 0 - n)) * Math.Pow(10, 0 - n);
- n = 0;
- }
- return Math.Round(d, n);
- }
- static double[] JiSuanChaValue(double UpValue, double DownValue, int Number)
- {
- double[] dataList = new double[Number];
- dataList[0] = UpValue;
- bool IsUp = UpValue < DownValue ? true : false;
- double Up_Number = UpValue;
- double Cha = Math.Abs(DownValue - UpValue);
-
- double MeanValue = Cha / (Number - 1);
- if (IsUp)
- {
- for (int i = 1; i < Number - 1; i++)
- {
- dataList[i] = Up_Number + (MeanValue * (i));
- }
- }
- else
- {
- for (int i = 1; i < Number - 1; i++)
- {
- dataList[i] = Up_Number - (MeanValue * (i));
- }
- }
- dataList[dataList.Length - 1] = DownValue;
- return dataList;
- }
- }
- }
|