各位高手们好,我是一个C#的初学者,由于课程的问题编程的课程都放到了今年这一学期了,让我好头疼。老师讲了一个计算机图形学上的问题用DDA,中点画线,Bresenham三种方法画直线,要在C#是windows中实现我不知道怎么弄了,我编写了一个DDA的,但是有问题,希望高手们给予帮助,给在下指点迷津!感激不尽……
下面是我学的DDA算法
建立一个类:
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace DDA算法
{
    class zuobiao
    {
        private double x0, y0, x1, y1;
        public zuobiao()
        {
            x0 = y0 = x1 = y1 = 0;
        }

        public double 起始坐标x
        {
            set { x0 = value; }
            get { return x0; }
        }
        public double 起始坐标y
        {
            set { y0 = value; }
            get { return y0; }
        }
        public double 终止坐标x
        {
            set { x1 = value; }
            get { return x1; }
        }
        public double 终止坐标y
        {
            set { y1 = value; }
            get { return y1; }
        }
        public double huaxian()
        {
            double dx, dy, n, k;
            double xinc, yinc, x, y;
            dx = x1 - x0;
            dy = y1 - y0;
            if (Math.Abs(dx) > Math.Abs(dy))
                n = Math.Abs(dx);
            else
                n = Math.Abs(dy);
            xinc = dx / n;
            yinc = dy / n;
            x = x0;
            y = y0;
            for (k = 1; k<= n; k++)
            {
                Math.Round(x);
                Math.Round(y);
                x += xinc;
                y += yinc;
            }
        }
    }
}

用button画线:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DDA算法
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            zuobiao Draw = new zuobiao();
            double X0, Y0, X1, Y1;
            X0 = double.Parse(textBox1.Text);
            Y0 = double.Parse(textBox2.Text);
            X1 = double.Parse(textBox3.Text);
            Y1 = double.Parse(textBox4.Text);
            Draw.起始坐标x = X0;
            Draw.起始坐标y = Y0;
            Draw.终止坐标x = X1;
            Draw.终止坐标y = Y1;
            pictureBox1.Paint = Draw.huaxian();

        }
    }
}
希望高手们给予帮助!!!