标签:
1,path画刷,绘制正弦 点,线;
生成正弦点
profilePoint.Value =76 * (1 - Math.Sin(i * Math.PI / 92)); profilePoint.Type = 1;
画点
1 EllipseGeometry el = new EllipseGeometry(); 2 el.Center = p; 3 el.RadiusX = 0.5; 4 el.RadiusY = 0.5; 5 6 Path mypath = new Path(); 7 mypath.Stroke = s; 8 mypath.StrokeThickness = 1; 9 mypath.Data = el; 10 11 panelCanvas.Children.Add(mypath);
画线
1 LineGeometry line = new LineGeometry(); 2 line.StartPoint = startPoint; 3 line.EndPoint = endPoint; 4 5 Path mypath = new Path(); 6 mypath.Stroke = s; 7 mypath.StrokeThickness = 1; 8 mypath.Data = line; 9 10 panelCanvas.Children.Add(mypath);
2,回归直线
1 /// <summary> 2 /// 最小二乘法计算回归直线 3 /// </summary> 4 /// <param name="listPoints">最小二乘法计算单位</param> 5 /// <returns></returns> 6 public ApproximateLine calApproximateLine(List<Point> listPoints) 7 { 8 ApproximateLine appr = new ApproximateLine(); 9 double total = 0; //临时变量 10 double averageX = 0; //X平均值 11 double averageY = 0; //Y平均值 12 double dispersion = 0; //协方差 13 double b = 0; //斜率 14 double a = 0; //y轴截距 15 //x平均值计算 16 total = 0; 17 for (int i = 0; i < listPoints.Count; i++) 18 { 19 total += listPoints[i].X; 20 } 21 averageX = total / listPoints.Count; 22 //y平均值计算 23 total = 0; 24 for (int i = 0; i < listPoints.Count; i++) 25 { 26 total += listPoints[i].Y; 27 } 28 averageY = total / listPoints.Count; 29 //协方差计算 30 total = 0; 31 for (int i = 0; i < listPoints.Count; i++) 32 { 33 total += ((listPoints[i].Y - averageY)*(listPoints[i].X - averageX)); 34 } 35 dispersion = total / listPoints.Count; 36 //斜率计算 37 total = 0; 38 double tmp = 0; 39 for (int i = 0; i < listPoints.Count; i++) 40 { 41 total += listPoints[i].Y * listPoints[i].X; 42 tmp += Math.Pow(listPoints[i].X, 2); 43 } 44 b = (total - listPoints.Count*averageX*averageY)/(tmp - listPoints.Count*averageX*averageX); 45 //截距计算 46 a = averageY - b * averageX; 47 //确定起止点坐标 48 ScaleProfilePoint p1 = new ScaleProfilePoint(); 49 ScaleProfilePoint p2 = new ScaleProfilePoint(); 50 p1.Type = 1; 51 p1.ValueX = listPoints[0].X; 52 p1.ValueZ = a + b * p1.ValueX; 53 p2.Type = 1; 54 p2.ValueX = listPoints[listPoints.Count-1].X; 55 p2.ValueZ = a + b * p2.ValueX; 56 //填充返回值 57 appr.Dispersion = dispersion; 58 appr.Horizontal = true; 59 appr.StartPnt = p1; 60 appr.EndPnt = p2; 61 return appr; 62 }
3,去除canvas内的元素,清空画布
this.panelCanvas.Children.Clear();
标签:
原文地址:http://www.cnblogs.com/codeinet/p/4681814.html