winform 关于双曲线的动态绘制

来源:互联网 发布:淘宝开店前期准备 编辑:程序博客网 时间:2024/05/01 04:55

任意输入 参数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);

            }
        }

    }
}

下面这两幅图是在实时绘制过程截取两张图片,可以使研究者直观观察出函数变化趋势。



0 0
原创粉丝点击