版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、下面是C#随机数格点值等值线绘制案例(包含源码),希望对大家有些帮助!1020306070显報点査看殆径源码:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.WindowsForms;namespaceMyContourpublicpartialclassfrmMain:Form#region属性publicstaticboolshowPoint=false;public
2、staticbooldrawLines=true;privatefloat,_Data;/等值线原始格点数据/publicfloat,Datagetreturn_Data;set_Data=value;privatefloat_ContourValues;/等值线值数组/publicfloatContourValuesgetreturn_ContourValues;set_ContourValues=value;#endregion#region窗体所有操作publicfrmMain()InitializeComponent();MakeTestData();setColor();gg=pic
3、tureBox1.CreateGraphics();privatevoidbutton1_Click(objectsender,EventArgse)this.timer1.Enabled=false;initValue();/重新初始化绘制路径的数组MakeTestData();pictureBox1.Refresh();privatevoidpictureBox1_Paint(objectsender,PaintEventArgse)if(this.Data=null)return;StringFormatsf=newStringFormat();sf.Alignment=StringAl
4、ignment.Center;sf.LineAlignment=StringAlignment.Center;Penpen=newPen(Color.DarkGray,1);/绘制等值线if(drawLines)this.plotContour(e.Graphics,pictureBox1.Size);/绘制网格if(frmMain.showPoint)intww=pictureBoxl.Width/(Data.GetLength(O)-1);/x轴间隔长度intyy=pictureBox1.Height/(Data.GetLength(1)-1);/y轴间隔长度/绘制网格横竖线for(int
5、p=0;pData.GetLength(0);p+)e.Graphics.DrawLine(pen,newPoint(p*ww,0),newPoint(p)*ww,pictureBox1.Height);for(intk=0;kData.GetLength(1);k+)e.Graphics.DrawLine(pen,newPoint(0,k*yy),newPoint(pictureBox1.Width,k*yy);/绘制网格斜线for(intj=0;jData.GetLength(0)-1;j+)for(inti=1;iData.GetLength(1);i+)e.Graphics.DrawL
6、ine(pen,newPoint(j*ww,(i-1)*yy),newPoint(j+1)*ww,i*yy);e.Graphics.DrawLine(pen,newPoint(j*ww,i*yy),newPoint(j+1)*ww,(i-1)*yy);/绘制格点值for(intj=0;jData.GetLength(1);j+)for(inti=0;iData.GetLength(0);i+)e.Graphics.DrawString(Datai,j.ToString(f0),DefaultFont,Brushes.Blue,i*pictureBox1.Width/(Data.GetLengt
7、h(0)-1),j*pictureBox1.Height/(Data.GetLength(1)-1),sf);privatevoidpictureBox1_SizeChanged(objectsender,EventArgse)pictureBox1.Refresh();privatevoidsetColor()label1.BackColor=getSpectrumColor(0f);label2.BackColor=getSpectrumColor(1f);label3.BackColor=getSpectrumColor(2f);label4.BackColor=getSpectrumC
8、olor(3f);label5.BackColor=getSpectrumColor(4f);label6.BackColor=getSpectrumColor(5f);label7.BackColor=getSpectrumColor(6f);label8.BackColor=getSpectrumColor(7f);privatevoidcheckBox1_CheckedChanged(objectsender,EventArgse)frmMain.showPoint=checkBox1.Checked;pictureBox1.Refresh();/生成路径按钮privatevoidbut
9、ton2_Click(objectsender,EventArgse)drawLines=false;this.pictureBox1.Refresh();nums=0;if(drawValuesnums.color!=null)pens.Color=drawValuesnums.color;gg.DrawLine(pens,drawValuesnums.x1,drawValuesnums.y1,drawValuesnums.x2,drawValuesnums.y2);nums+;elsethis.timer1.Enabled=false;nums=0;timer1.Enabled=true;
10、drawLines=true;Graphicsgg=null;/绘制路径的对象Penpens=newPen(Color.Black,1);privatevoidtimer1_Tick(objectsender,EventArgse)if(drawValuesnums.color!=Color.FromArgb(0,0,0)pens.Color=drawValuesnums.color;gg.DrawLine(pens,drawValuesnums.x1,drawValuesnums.y1,drawValuesnums.x2,drawValuesnums.y2);nums+;elsethis.t
11、imer1.Enabled=false;nums=0;#endregion#region绘制等值线操作/生成测试数据/publicvoidMakeTestData()constintnx=10,ny=10,nv=7;ContourValues=newfloatnv;for(inti=0;inv;i+)_ContourValuesi=i*10;_Data=newfloatnx,ny;/nx列,ny行Randomran=newRandom();for(intj=0;jny;j+)for(inti=0;inx;i+)_Datai,j=ran.Next(0,70);/如果格点值等于等值线值,格点值加一
12、个小值for(intk=0;knv;k+)if(_Datai,j=ContourValuesk)_Datai,j+=0.0001f;intv1,v2,v3,small,medium,large;intix=newint4,iy=newint4;floatx1,x2,y1,y2,target;floatX=newfloat5,Y=newfloat5,value=newfloat5;intiX(floatx,intwidth)return(int)Math.Round(width/(Data.GetLength(0)-1)*x);intiY(floaty,intheight)return(int)
13、Math.Round(height/(Data.GetLength(1)-1)*y);/根据等值线值取得相应级别颜色/publicColorgetSpectrumColor(floatvalue)Colorc=Color.Black;floatc0=0.0F,c1=256.0F,c2=256.0F*2.0F,c3=256.0F*3.0F,c4=256.0F*4.0F,c5=256.0F*5.0F;floatStep=c5*(value)/ContourValues.Length;if(Stepc4&Stepc3&Stepc2&Stepc1&Step=c0&Step=c1)floata=Step
14、;c=Color.FromArgb(int)(255.0F-255.0F*a/c1),0,255);elsec=Color.Black;returnc;/插值计算/floatinterp(floatxa,floatya,floatxb,floatyb,floatyy)if(yb-ya)!=0.0F)returnxa+(yy-ya)*(xb-xa)/(yb-ya);elsereturn0.0F;Fontfont=newFont(TimesNewRoman,8.0f);Brushbrush=newSolidBrush(Color.Blue);/等值线分析及绘图publicvoidplotConto
15、ur(Graphicsg,Sizesize)nums=0;Penpen=newPen(Color.Black,1);for(intj=0;jData.GetLength(1)-1;j+)for(inti=0;iData.GetLength(0)-1;i+)/网格四个角坐标,变量值X0=i;Y0=j;value0=Datai,j;X1=i+1;Y1=j;value1=Datai+1,j;X2=i+1;Y2=j+1;value2=Datai+1,j+1;X3=i;Y3=j+1;value3=Datai,j+1;/网格中心点坐标,变量值X4=0.5F*(X0+X1);Y4=0.5F*(Y1+Y2);
16、value4=0.25F*(value0+value1+value2+value3);v3=4;/巡检单元格范围内所有的点信息for(v1=0;v14;v1+)v2=v1+1;if(v1=3)v2=0;reorder(v1,v2,v3);/巡检点范围内所有的点信息for(intlines=0;linesContourValues.Length;lines+)target=ContourValueslines;if(valuesmalltarget&targetvaluemedium)x2=interp(Xmedium,valuemedium,Xlarge,valuelarge,target);
17、y2=interp(Ymedium,valuemedium,Ylarge,valuelarge,target);elsex2=interp(Xsmall,valuesmall,Xmedium,valuemedium,target);y2=interp(Ysmall,valuesmall,Ymedium,valuemedium,target);pen.Color=getSpectrumColor(target/10);g.DrawLine(pen,iX(x1,size.Width),iY(y1,size.Height),iX(x2,size.Width),iY(y2,size.Height);/
18、g.DrawString(target.ToString(),font,brush,newPointF(iX(x1,size.Width)+iX(x2,size.Width)/2,(iY(y1,size.Height)+iY(y2,size.Height)/2);drawValuesnums.color=getSpectrumColor(target/10);drawValuesnums.x1=iX(x1,size.Width);drawValuesnums.y1=iY(y1,size.Height);drawValuesnums.x2=iX(x2,size.Width);drawValuesnums.y2=iY(y2,size.Height);nums+;intnums=0;structDrawValuespublicColorcolor;publicintx1;publicinty1;publicintx2;publicinty2;DrawValuesdrawValues=newDrawValues90000;/存储绘制点的信息/根据i,j,k三点值,算出大中小三点/voidreorder(inti,intj,intk)
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年焦炉试题及答案
- 医院肛肠科20XX年终工作总结
- 2025年工业机器人仿真编程实战考核模拟试题及答案
- 施工期间交通导行方案
- 2025年一般生产经营单位安全培训考试试题附参考答案(完整版)
- 2025年内镜消毒隔离试题及答案
- 建设工程施工合同纠纷要素式起诉状模板律师常用版本
- 建设工程施工合同纠纷要素式起诉状模板电子档随时编辑
- 网球教学2026年技能提升
- 俞敏洪介绍教学课件
- 2026年劳动关系协调师综合评审试卷及答案
- 黑龙江八一农垦大学公开招聘辅导员和教师22人参考题库附答案解析
- 2026年房地产经纪协理考试题库及答案(名师系列)
- 南京工装合同范本
- 2025年二年级上册语文期末专项复习-按课文内容填空默写表(含答案)
- 登高作业监理实施细则
- 2025年妇产科副高试题库及答案
- 2025食品机械行业智能化分析及技术升级趋势与投资可行性评估报告
- 2025年度党委党建工作总结
- 《经济法学》2025-2025期末试题及答案
- CAICV智能网联汽车远程升级(OTA)发展现状及建议
评论
0/150
提交评论