大家好:
    我学习v#时间不久,大概有一周的样子了。以前学过c语言,也自学过c++程序设计。目前由于保研而提前进入实验室,导师已经给我布置了课题,任务是开发一个旋转机械的故障诊断系统,包括数据采集、数据通讯、信号特征提取、故障模式识别和决策等模块。我目前已经看到c#的GDI编程了。有很多问题想不明白,可能是我心态过于急躁吧,总希望自己能早点学好c#,早点完成导师布置的任务。听师兄说实验室用的数据采集卡是研华的,它自带有驱动程序,能把采集到的数据自动保存到工控机中,在我设计的系统中起码要实现信号波形的时域显示、信号的傅里叶频谱图、伯德图等等。信号是时间的函数,在系统面板上要怎么才能实现信号随时间变化的图形呢?而且像傅里叶变换,是必须先知道函数的表达式才能变换的,采集来的数据是离散数据,没有表达式,是不是要经过曲线拟合才能进行变换?信号的频谱也要随着时间的变化而显示吗?
    哪位前辈有这方面的经验,能不能给点意见?告诉我应该看哪方面的书籍?现在看的c#程序设计中的图形显示都是静态图形,曲线也是关于空间位置的函数曲线,而且相当简单,我不知道应该怎么继续学下去。毕竟人的精力是有限的,不可能把程序设计的方方面面都学到,我目前只是想深入学习时域波形显示这方面的知识,有这方面的书籍吗?

解决方案 »

  1.   

    有c和c++的基础学c#很容易的
    楼主原来是搞计算机图形学的
    我记得当初上学有本windows计算机图形学的书,外文书,有中文版很不错
    不过图形学太难了,所以就放弃了..
    楼主不要着急,慢慢来,图形学本来就难
      

  2.   

    一小段代码,lz可以参考一下,它是通过监测一个陀螺仪的数值,实时画在指定的控件上,由于是写了玩的,代码不漂亮,也没注释.
    当然,少了陀螺仪数据收集等步骤,下面的代码是运行不起来的,但你可以参考下画动态图形的方法(画线的方法,双倍缓冲,GDI+对象的基本使用等),你画函数图像,基本原理是相同的,只是你的y坐标不是收集的,而是计算得出的.
        internal class DrawCoordinate
        {
            private Graphics _g;
            private Bitmap _b;
            private Graphics _bg;
            private Pen _xc;
            private Pen _yc;
            private Pen _ac;
            private Brush _xcb;
            private Brush _ycb;
            private Brush _acb;
            private Pen _sc;
            private Color _bc;
            private Pen _cc;
            private Brush _sb;
            private Control _c;
            private int Height;
            private int Width;
            public float FullHeight = 1000;        public List<ThinkPad.AccData> List;
            private string apstemp, time, info, fn, fw, fe, fs;        public Graphics Graphics
            {
                get { return _g; }
            }        public DrawCoordinate(Control c, Color Xcolor, Color Ycolor, Color Acolor, Color stateColor, Color backColor, string language)
            {
                if (c == null)
                    throw new Exception("Need a control for init.");
                _c = c;
                c.Resize += new EventHandler(c_Resize);
                _g = Graphics.FromHwnd(c.Handle);
                _sc = new Pen(stateColor, 1);
                _bc = backColor;
                _cc = new Pen(Color.White, 1);
                _cc.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                _ac = new Pen(Acolor, 1);
                _xc = new Pen(Xcolor, 1);
                _yc = new Pen(Ycolor, 1);            _acb = new SolidBrush(Acolor);
                _xcb = new SolidBrush(Xcolor);
                _ycb = new SolidBrush(Ycolor);            //new Pen(Color.FromArgb(255 - _bc.A, 255 - _bc.G, 255 - _bc.B));
                _sb = new SolidBrush(stateColor);
                Height = _c.Height;
                Width = _c.Width;
                _b = new Bitmap(Width, Height);
                _bg = Graphics.FromImage(_b);
                List = new List<ThinkPad.AccData>(1000);
                if (language == "CN")
                {
                    apstemp = Language.APSTemperature_CN;
                    time = Language.CurrentTime_CN;
                    info = Language.CurrentInfo_CN;
                    fe = "东";
                    fw = "西";
                    fs = "南";
                    fn = "北";
                }
                else
                {
                    apstemp = Language.APSTemperature_EN;
                    time = Language.CurrentTime_EN;
                    info = Language.CurrentInfo_EN;
                    fe = "E";
                    fw = "W";
                    fs = "S";
                    fn = "N";
                }
            }        void c_Resize(object sender, EventArgs e)
            {
                Height = _c.Height;
                Width = _c.Width;
                _b = new Bitmap(Width, Height);
                _bg = Graphics.FromImage(_b);
                _g = Graphics.FromHwnd(_c.Handle);
            }
            public void Draw(bool showState, int axis_type)
            {
                _bg.Clear(_bc);
                float hrate = (float)Height / 20f;
                float yx = 0, yy = 0;
                int sIdx = Width > List.Count ? 0 : List.Count - Width - 1;
                if (sIdx < 0)
                    sIdx = 0;
                PointF[] p1 = new PointF[List.Count - sIdx];
                PointF[] p2 = new PointF[List.Count - sIdx];
                PointF[] p3 = new PointF[List.Count - sIdx];
                if (p1.Length <= 1)
                    return;
                int idx = 0;
                int state = 0;
                ushort x = 0, y = 0;
                ushort lx = 0, ly = 0;
                int ax = 0, ay = 0;
                float speedA = 0, speedAt = 0;
                for (int i = sIdx; i < List.Count; i++)
                {
                    yx = (float)Height / FullHeight;
                    yy = yx; speedA = yx;
                    if (i == sIdx)
                    {
                        p1[idx] = new PointF(0, yx * FullHeight / 2);
                        p2[idx] = p1[idx];
                        p3[idx] = p1[idx++];
                        continue;
                    }
                    if (axis_type == 1)
                    {
                        x = List[i].LatestAccelDataX;
                        y = List[i].LatestAccelDataY;
                        lx = List[i - 1].LatestAccelDataX;
                        ly = List[i - 1].LatestAccelDataY;
                    }
                    else if (axis_type == 2)
                    {
                        x = List[i].LatestZeroG_X;
                        y = List[i].LatestZeroG_Y;
                        lx = List[i - 1].LatestZeroG_X;
                        ly = List[i - 1].LatestZeroG_Y;
                    }
                    else
                    {
                        x = List[i].LatestRawAccelDataX;
                        y = List[i].LatestRawAccelDataY;
                        lx = List[i - 1].LatestRawAccelDataX;
                        ly = List[i - 1].LatestRawAccelDataY;
                    }
                    yx *= ((x - 500) + FullHeight / 2); yy *= ((y - 500) + FullHeight / 2);                if (idx == 0)
                        state = List[i].PresentState;
                    else
                        if (showState && state != List[i].PresentState)
                        {
                            ThinkPad.Status state1 = ThinkPad.convertStatusCode(state);
                            state = List[i].PresentState;
                            if (state1 != ThinkPad.Status.Undefined)
                            {
                                _bg.DrawLine(_sc, idx, (int)(state * hrate), idx, Height / 2);
                                _bg.DrawString(state1.ToString(), _c.Font, _sb, (float)idx, (state * hrate));
                            }
                        }
                    PointF px = new PointF((float)idx, yx);
                    PointF py = new PointF((float)idx, yy);
                    ax = (x - lx); ay = (y - ly);
                    speedAt = (float)Math.Sqrt((double)(ax * ax + ay * ay)) * (ay > 0 ? 1 : -1);
                    speedA *= (speedAt + FullHeight / 2);
                    PointF pa = new PointF((float)idx, speedA);
                    p1[idx] = px;
                    p2[idx] = py;
                    p3[idx++] = pa;
                }
                _bg.DrawString(apstemp + List[List.Count - 1].Temperature.ToString(), _c.Font, Brushes.Red, 160f, 0f);
                _bg.DrawString(time + DateTime.Now.ToString("hh:mm:ss") + "." + DateTime.Now.Millisecond.ToString("000"), _c.Font, Brushes.White, 0f, 0f);
                _bg.DrawString(string.Format(info, x, y, speedAt, (ay > 0 ? fw : fe), (ax > 0 ? fn : fs)), _c.Font, Brushes.White, 0f, 20f);
                if (p1.Length > 1)
                {
                    _bg.DrawLines(_xc, p1);
                    _bg.DrawLines(_yc, p2);
                    _bg.DrawLines(_ac, p3);
                }
                if (p1[p1.Length - 1].X > Width - 30)
                    p1[p1.Length - 1].X = p1[p1.Length - 1].X - 30;
                _bg.DrawString(List[List.Count - 1].LatestRawAccelDataX.ToString(), _c.Font, _xcb, p1[p1.Length - 1].X, p1[p1.Length - 1].Y);
                _bg.DrawString(List[List.Count - 1].LatestRawAccelDataY.ToString(), _c.Font, _ycb, p1[p1.Length - 1].X, p2[p2.Length - 1].Y);
                _bg.DrawString(speedAt.ToString("0.00"), _c.Font, _acb, p1[p1.Length - 1].X, p3[p3.Length - 1].Y);
                _bg.DrawLine(_cc, 0, Height / 2, Width, Height / 2);            _bg.Save();
                _g.DrawImage(_b, 0, 0);
            }
        }
      

  3.   

    效果如图链接中的视频,不过主要是演示其他功能的,画图不太清楚
    http://www.tudou.com/programs/view/SHRtJX-m6IU
      

  4.   

     谢谢wjq 我去好好研究下