winform 关于双曲线的动态绘制
2016-08-09 17:02
260 查看
任意输入 参数a,b的值,
大量瞄点连线,汇成双曲线。
具体代码如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZedGraph;
namespace 绘图
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
PointPairList list = new PointPairList();
PointPairList list1 = new PointPairList();
PointPairList list2 = new PointPairList();
PointPairList list3 = new PointPairList();
LineItem myCurve;
LineItem myCurve1;
LineItem myCurve2;
LineItem myCurve3;
private void Form1_Load(object sender, EventArgs e)
{
syszed();
}
int a;
int b;
double m;
private void button1_Click(object sender, EventArgs e)
{
list.Clear();
list1.Clear();
list2.Clear();
list3.Clear();
i = 0;
if (!int.TryParse(textBox1.Text, out a))
{
MessageBox.Show("填写的a的值不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
textBox1.Select();
return;
}
if (!int.TryParse(textBox2.Text, out b))
{
MessageBox.Show("填写的b的值不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
textBox2.Select();
return;
}
m = (a + b) / 2.0;
timer1.Start();
}
public void syszed()
{
this.zedGraphControl1.GraphPane.Title.Text = "双曲线图像";//折线图标题
this.zedGraphControl1.GraphPane.XAxis.Title.Text = "X轴值";//X轴标题
this.zedGraphControl1.GraphPane.YAxis.Title.Text = "Y轴值";//Y轴标题
this.zedGraphControl1.GraphPane.YAxis.Title.FontSpec.FontColor = Color.Red;//设置Y轴字体的颜色
this.zedGraphControl1.GraphPane.Title.FontSpec.FontColor = Color.Gray;//设置标题的颜色
this.zedGraphControl1.GraphPane.XAxis.Title.FontSpec.FontColor = Color.GreenYellow;//设置X轴的字体颜色
myCurve = zedGraphControl1.GraphPane.AddCurve("", list, Color.Red, SymbolType.Diamond);
myCurve.Symbol.Fill = new Fill(Color.Red, Color.Red, Color.Red);//
myCurve1 = zedGraphControl1.GraphPane.AddCurve("", list1, Color.Red, SymbolType.Diamond);
myCurve1.Symbol.Fill = new Fill(Color.Red, Color.Red, Color.Red);//
myCurve2 = zedGraphControl1.GraphPane.AddCurve("", list2, Color.Red, SymbolType.Diamond);
myCurve2.Symbol.Fill = new Fill(Color.Red, Color.Red, Color.Red);//
myCurve3 = zedGraphControl1.GraphPane.AddCurve("", list3, Color.Red, SymbolType.Diamond);
myCurve3.Symbol.Fill = new Fill(Color.Red, Color.Red, Color.Red);//
this.zedGraphControl1.AxisChange();
this.zedGraphControl1.Refresh();
}
int i = 0;
double x;
double f;
private void timer1_Tick(object sender, EventArgs e)
{
this.zedGraphControl1.AxisChange();
this.zedGraphControl1.Refresh();
x = a + i * 0.01; f = 0 - x;
double y = Math.Sqrt((b * b * x * x * 1.0 / a) / a - b * b);
list.Add(x, y); list2.Add(f, y);
y = 0-Math.Sqrt((b * b * x * x * 1.0 / a) / a - b * b);
list1.Add(f, y);
list3.Add(x, y);
i++;
if (list.Count > 10000)
{
list.RemoveAt(0);
}
}
}
}
下面这两幅图是在实时绘制过程截取两张图片,可以使研究者直观观察出函数变化趋势。
大量瞄点连线,汇成双曲线。
具体代码如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZedGraph;
namespace 绘图
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
PointPairList list = new PointPairList();
PointPairList list1 = new PointPairList();
PointPairList list2 = new PointPairList();
PointPairList list3 = new PointPairList();
LineItem myCurve;
LineItem myCurve1;
LineItem myCurve2;
LineItem myCurve3;
private void Form1_Load(object sender, EventArgs e)
{
syszed();
}
int a;
int b;
double m;
private void button1_Click(object sender, EventArgs e)
{
list.Clear();
list1.Clear();
list2.Clear();
list3.Clear();
i = 0;
if (!int.TryParse(textBox1.Text, out a))
{
MessageBox.Show("填写的a的值不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
textBox1.Select();
return;
}
if (!int.TryParse(textBox2.Text, out b))
{
MessageBox.Show("填写的b的值不正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
textBox2.Select();
return;
}
m = (a + b) / 2.0;
timer1.Start();
}
public void syszed()
{
this.zedGraphControl1.GraphPane.Title.Text = "双曲线图像";//折线图标题
this.zedGraphControl1.GraphPane.XAxis.Title.Text = "X轴值";//X轴标题
this.zedGraphControl1.GraphPane.YAxis.Title.Text = "Y轴值";//Y轴标题
this.zedGraphControl1.GraphPane.YAxis.Title.FontSpec.FontColor = Color.Red;//设置Y轴字体的颜色
this.zedGraphControl1.GraphPane.Title.FontSpec.FontColor = Color.Gray;//设置标题的颜色
this.zedGraphControl1.GraphPane.XAxis.Title.FontSpec.FontColor = Color.GreenYellow;//设置X轴的字体颜色
myCurve = zedGraphControl1.GraphPane.AddCurve("", list, Color.Red, SymbolType.Diamond);
myCurve.Symbol.Fill = new Fill(Color.Red, Color.Red, Color.Red);//
myCurve1 = zedGraphControl1.GraphPane.AddCurve("", list1, Color.Red, SymbolType.Diamond);
myCurve1.Symbol.Fill = new Fill(Color.Red, Color.Red, Color.Red);//
myCurve2 = zedGraphControl1.GraphPane.AddCurve("", list2, Color.Red, SymbolType.Diamond);
myCurve2.Symbol.Fill = new Fill(Color.Red, Color.Red, Color.Red);//
myCurve3 = zedGraphControl1.GraphPane.AddCurve("", list3, Color.Red, SymbolType.Diamond);
myCurve3.Symbol.Fill = new Fill(Color.Red, Color.Red, Color.Red);//
this.zedGraphControl1.AxisChange();
this.zedGraphControl1.Refresh();
}
int i = 0;
double x;
double f;
private void timer1_Tick(object sender, EventArgs e)
{
this.zedGraphControl1.AxisChange();
this.zedGraphControl1.Refresh();
x = a + i * 0.01; f = 0 - x;
double y = Math.Sqrt((b * b * x * x * 1.0 / a) / a - b * b);
list.Add(x, y); list2.Add(f, y);
y = 0-Math.Sqrt((b * b * x * x * 1.0 / a) / a - b * b);
list1.Add(f, y);
list3.Add(x, y);
i++;
if (list.Count > 10000)
{
list.RemoveAt(0);
}
}
}
}
下面这两幅图是在实时绘制过程截取两张图片,可以使研究者直观观察出函数变化趋势。
相关文章推荐
- c#调用COM组件
- 批量自动安装常用软件
- 批量自动安装常用软件
- 企业批量部署RealVNC远程控制软件
- 好用的Markdown编辑器一览
- C#实现把指定数据写入串口
- C#动态创建button的方法
- C#中抽象方法与虚拟方法的区别
- c#中虚函数的相关使用方法
- C#实现给图片加水印的方法
- C#使用加边法计算行列式的值
- C#实现多线程的同步方法实例分析
- C#中尾递归的使用、优化及编译器优化
- C#中的delegate委托类型基本学习教程
- C#实现子窗体与父窗体通信方法实例总结
- C#通用邮件发送类分享
- 举例讲解C#中自动实现的属性
- C#中this的用法集锦
- C#数据结构之顺序表(SeqList)实例详解