首页 技术 正文
技术 2022年11月20日
0 收藏 672 点赞 2,261 浏览 1790 个字

1,path画刷,绘制正弦 点,线;

生成正弦点

                profilePoint.Value = * ( - Math.Sin(i * Math.PI / ));
profilePoint.Type = ;

画点

             EllipseGeometry el = new EllipseGeometry();
el.Center = p;
el.RadiusX = 0.5;
el.RadiusY = 0.5; Path mypath = new Path();
mypath.Stroke = s;
mypath.StrokeThickness = ;
mypath.Data = el; panelCanvas.Children.Add(mypath);

画线

             LineGeometry line = new LineGeometry();
line.StartPoint = startPoint;
line.EndPoint = endPoint; Path mypath = new Path();
mypath.Stroke = s;
mypath.StrokeThickness = ;
mypath.Data = line; panelCanvas.Children.Add(mypath);

2,回归直线

         /// <summary>
/// 最小二乘法计算回归直线
/// </summary>
/// <param name="listPoints">最小二乘法计算单位</param>
/// <returns></returns>
public ApproximateLine calApproximateLine(List<Point> listPoints)
{
ApproximateLine appr = new ApproximateLine();
double total = ; //临时变量
double averageX = ; //X平均值
double averageY = ; //Y平均值
double dispersion = ; //协方差
double b = ; //斜率
double a = ; //y轴截距
//x平均值计算
total = ;
for (int i = ; i < listPoints.Count; i++)
{
total += listPoints[i].X;
}
averageX = total / listPoints.Count;
//y平均值计算
total = ;
for (int i = ; i < listPoints.Count; i++)
{
total += listPoints[i].Y;
}
averageY = total / listPoints.Count;
//协方差计算
total = ;
for (int i = ; i < listPoints.Count; i++)
{
total += ((listPoints[i].Y - averageY)*(listPoints[i].X - averageX));
}
dispersion = total / listPoints.Count;
//斜率计算
total = ;
double tmp = ;
for (int i = ; i < listPoints.Count; i++)
{
total += listPoints[i].Y * listPoints[i].X;
tmp += Math.Pow(listPoints[i].X, );
}
b = (total - listPoints.Count*averageX*averageY)/(tmp - listPoints.Count*averageX*averageX);
//截距计算
a = averageY - b * averageX;
//确定起止点坐标
ScaleProfilePoint p1 = new ScaleProfilePoint();
ScaleProfilePoint p2 = new ScaleProfilePoint();
p1.Type = ;
p1.ValueX = listPoints[].X;
p1.ValueZ = a + b * p1.ValueX;
p2.Type = ;
p2.ValueX = listPoints[listPoints.Count-].X;
p2.ValueZ = a + b * p2.ValueX;
//填充返回值
appr.Dispersion = dispersion;
appr.Horizontal = true;
appr.StartPnt = p1;
appr.EndPnt = p2;
return appr;
}

3,去除canvas内的元素,清空画布

this.panelCanvas.Children.Clear();

附上工程源码

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,000
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,512
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,358
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,141
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,771
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,849