其实是这样的,比如在第一象限,有两个点,他们距离圆心的距离肯定是一样的,这样呢,从第一个点(比如x0,y0)附近的一个点开始(可以让它为(x0-1,yo)),如果这个点到原点的距离比半径大,说明当前点在圆外,那么下一个点:x坐标-1,y不变。如果这个点到原点的距离比半径小,说明在圆内,那么下一个点:x左边不变,y+1.如此下去。每一步都比较当前点和终点的x,y坐标值,有一个相等的话就可以结束了。。
也就是说每次只需要画一个点。或者谁给我一个完整的画一个点的代码也可以。。因为完全没用过c#,所以,请给个完整代码,能直接运行的,别只给画点的方法。
我想这对学过c#的大虾们是很简单的。请提供第一象限画弧的完整代码,谢谢
今晚12点前就要交,可以追加分。

解决方案 »

  1.   

    计算机嘛,就是干这种活的。我用java都实现了。画很长的弧瞬间就完成,以至于我想看画的过程都得每画一个点就调用thread 的sleep方法。
      

  2.   

    那你把Java代码转换成C#代码不就OK了!
      

  3.   

    java实现的话c#还有什么难度?
    这主要是数学问题,写一个输入x坐标输出y坐标的函数之后Grahpic里一个个点画上去就是了
      

  4.   

    怎么能保证下一点交替在圆内和圆外出现呢,把Java的代码请楼主贴出学习学习
      

  5.   


    import java.awt.Color;
    import java.awt.Font;
    import java.awt.Graphics;
    import javax.swing.JFrame;public class DrawArc extends JFrame{
    int xs = 80;
    int ys = 200;
    int xe = 200;
    int ye = 80;
    int step = 1;
    int xm = xs;
    int ym = ys;
    public DrawArc(String title) {
    this.setBounds(300, 300, 300, 300);
    this.setVisible(true);
    this.setResizable(false);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setTitle(title);
    } /**
     * @param args
     */
    public static void main(String[] args) {
    new DrawArc("Draw Arc");
    } public void paint(Graphics g) {
    g.drawString("习题17:生成圆弧的逐点比较算法", 40, 100);
    try {
    Thread.currentThread().sleep(2000);
    } catch (InterruptedException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    }
    int width =0;
    while(width<300){
    width++;
    try {
    Thread.currentThread().sleep(2);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    g.clearRect(0, 0, width, width);
    }
    g.drawLine(40, 40, 40, 40);
    for (int i = 0; i < 3; i++) {
    g.clearRect(41, 41, 50, 60);
    try {
    Thread.currentThread().sleep(300);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    g.setColor(Color.RED);
    g.drawString("O", 50, 60);// 坐标原点
    try {
    Thread.currentThread().sleep(300);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    }
    g.setColor(Color.PINK);
    int xx = 40;
    int yy = 40;
    while (xx <= 280) {
    g.drawLine(30, 40, xx, 40);// x
    xx++;
    try {
    Thread.currentThread().sleep(3);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    }
    g.drawLine(280, 40, 275, 35);
    g.drawLine(280, 40, 275, 45);
    g.drawString("x", 270, 60); while (yy <= 280) {
    g.drawLine(40, 30, 40, yy);// y
    yy++;
    try {
    Thread.currentThread().sleep(3);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    }
    g.drawLine(40, 280, 35, 275);
    g.drawLine(40, 280, 45, 275);
    g.drawString("y", 50, 275);
    g.setColor(Color.BLACK);
    g.drawLine(80, 200, 80, 200);// start
    g.drawLine(200, 80, 200, 80);// end
    g.setColor(Color.RED);
    g.drawString("A(80,200)", 80, 215);// A
    try {
    Thread.currentThread().sleep(5);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    g.setColor(Color.BLACK);

    for (int i = 0; i < 2; i++) {
    g.clearRect(215, 60, 160, 140);
    try {
    Thread.currentThread().sleep(300);
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    g.setColor(Color.RED);
    g.drawString("B(200,80)", 215, 80);// B,end point
    try {
    Thread.currentThread().sleep(300);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    }

    for (int i = 0; i < 2; i++) {
    g.clearRect(80, 202, 60, 40);
    try {
    Thread.currentThread().sleep(300);
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    g.setColor(Color.RED);
    g.drawString("A(80,200)", 80, 215);// A,start point
    try {
    Thread.currentThread().sleep(300);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    }
    g.setColor(Color.BLACK);
    int r = 60 * 60 + 180 * 180;
    while (xm != xe && ym != ye) {
    try {
    Thread.currentThread().sleep(10);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    if (((xm - 20) * (xm - 20) + (ym - 20) * (ym - 20)) < r) {
    xm = xm + step;
    }
    if ((xm - 20) * (xm - 20) + (ym - 20) * (ym - 20) >= r) {
    ym = ym - step;
    }
    g.drawLine(xm, ym, xm, ym);
    }
    xs = 80;
    ys = 200;
    xe = 200;
    ye = 80;
    xm = xs;
    ym = ys;
    width = 0;
    while(width<300){
    width++;
    try {
    Thread.currentThread().sleep(2);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    g.clearRect(0, 0, width, width);
    }
    g.setColor(Color.RED);
    g.setFont(new Font("宋体",Font.BOLD, 40));
    g.drawString("Thank you!", 40, 170);
    g.setFont(new Font("宋体",Font.BOLD, 12));
    g.drawString("watch again?", 40, 230);
    g.drawString("min the window then max it!", 70, 240);
    g.setColor(Color.BLACK);
    g.drawString("习题17:生成圆弧的逐点比较算法", 40, 50);
    g.drawString("组员1  0658039", 40, 70);
    g.drawString("组员2  0658047", 40, 90);
    g.drawString("组员3  0658045", 40, 110);
    g.drawString("组员4 0658035", 40, 130);
    }}
      

  6.   

    首先建立一个C#的WinForm工程,在Form1的设计器里拖入一个PictureBox然后使用下面的代码using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                DrawArc();
            }        private void DrawArc()
            {
                double r = Math.Sqrt(x0 * x0 + y0 * y0);            int x = x0;
                int y = y0;
                Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
                {
                    // 画点,这里使用的是点在pictureBox中的坐标
                    bmp.SetPixel(x, pictureBox1.Height - y, Color.Black);
                    x--;
                    
                    while (x != x1 && y != y1)
                    {
                        bmp.SetPixel(x, pictureBox1.Height - y, Color.Black);
                        double r1 = Math.Sqrt(x * x + y * y);
                        if (r1 <= r)
                            y++;
                        else
                            x--;
                    }
                    bmp.SetPixel(x, pictureBox1.Height - y, Color.Black);
                    pictureBox1.BackgroundImage = bmp;
                }
            }        // 表示坐标系的值,从(100,10)画到(10,100)的弧
             int x0 = 100;
            int y0 = 10;        int x1 = 10;
            int y1 = 100;
        }
    }
      

  7.   

      using   System;
      using   System.Drawing;
      using   System.Drawing.Drawing2D;
      using   System.Collections;
      using   System.ComponentModel;
      using   System.Windows.Forms;
      using   System.Data;
        
      namespace   _1001
      {
      ///   <summary>   
      ///   Form1   的摘要说明。   
      ///   </summary>   
      public   class   Form1   :   System.Windows.Forms.Form   
      {
      ///   <summary>   
      ///   必需的设计器变量。
      ///   </summary>   
      private   System.ComponentModel.Container   components   =   null;   
        
      Pen   myPen   =   new   Pen(Color.Red);   
     // int xs = 80;
    //  int ys = 200;
      int xe = 200;
      int ye = 80;
      int step = 1;
      int xm = 80;
      int ym = 200;
      public   Form1()   
      {   
      //   
      //   Windows   窗体设计器支持所必需的   
      //   
      InitializeComponent();   
        
        
      //   
      //   TODO:   在   InitializeComponent   调用后添加任何构造函数代码   
      //   
      }   
        
      ///   <summary>   
      ///   清理所有正在使用的资源。   
      ///   </summary>   
      protected   override   void   Dispose(   bool   disposing   )   
      {   
      if(   disposing   )   
      {   
      if   (components   !=   null)     
      {   
      components.Dispose();   
      }   
      }   
      base.Dispose(   disposing   );   
      }   
        
      #region   Windows   Form   Designer   generated   code   
      ///   <summary>   
      ///   设计器支持所需的方法   -   不要使用代码编辑器修改   
      ///   此方法的内容。   
      ///   </summary>   
      private   void   InitializeComponent()   
      {   
      this.components   =   new   System.ComponentModel.Container();   
      this.Size   =   new   System.Drawing.Size(300,300);   
      this.Text   =   "Form1";   
      }   
      #endregion   
        
      ///   <summary>   
      ///   应用程序的主入口点。   
      ///   </summary>   
      [STAThread]   
      static   void   Main()     
      {   
      Application.Run(new   Form1());   
      }   
        
      protected   override   void   OnPaint(PaintEventArgs   e)   
      {   
      Graphics   g   =   e.Graphics;
      myPen.Width   =   1;
      g.DrawLine(myPen,40, 40, 40, 40);
      g.DrawLine(myPen,30, 40, 280, 40);// x
      g.DrawLine(myPen,280, 40, 275, 35);
      g.DrawLine(myPen,280, 40, 275, 45);
      
      g.DrawLine(myPen,40, 30, 40, 280);// y
      g.DrawLine(myPen,40, 280, 35, 275);
      g.DrawLine(myPen,40, 280, 45, 275);
      
      g.DrawLine(myPen,80, 200, 80, 201);// start
      g.DrawLine(myPen,200, 80, 200, 81);// end
      
      
      int r = 60 * 60 + 180 * 180;
      while (xm != xe && ym != ye) 
      {
    if (((xm - 20) * (xm - 20) + (ym - 20) * (ym - 20)) < r) {
    xm = xm + step;
        }
    if ((xm - 20) * (xm - 20) + (ym - 20) * (ym - 20) >= r) {
    ym = ym - step;
    }
    g.DrawLine(myPen,xm, ym, xm, ym-1);
      }
      }   
      }   
      }  这是我在网上找到画直线的方法,把OnPaint()方法改了一下,实现了,好像与楼上的是用不同的方式。
    希望后来的人能批评或借鉴
      

  8.   

    给你个画码表的表盘的代码参考下吧:   /********************************************************************************
             * 说明:写一个画类似汽车码表的函数,无返回值。
             * 参数:int Deg
             * 要求:
             * 在一个400*400的黑色画布中间画一个半径为100的圆,圆的上半部分被均分成0-180等分。传入一个角度值(画出指针指向的位置)
            ********************************************************************************/
            protected void DrawWatchCircle()
            {
                int r = 150;//大圆半径
                int r2 = 140;//小圆半径
                int r3 = 130;//整刻度线
                int x1=0;
                int x2 = 0;
                int y1 = 0;
                int y2=0;            Graphics g = panel2.CreateGraphics();
                g.DrawArc(new Pen(Color.White, 2), 50, 50, 300, 300, 45, 360);//画大圆
                //画刻度
                for (int i = 0; i <= 180; i++)
                {
                    if (i <= 90)
                    {
                        if (i % 2 == 0)
                        {
                            x1 = 200 - (int)(r * Math.Cos(i * Math.PI / 180));
                            y1 = 200 - (int)(r * Math.Sin(i * Math.PI / 180));
                            x2 = 200 - (int)(r2 * Math.Cos(i * Math.PI / 180));
                            y2 = 200 - (int)(r2 * Math.Sin(i * Math.PI / 180));
                        }
                        if (i % 10 == 0)
                        {
                            x2 = 200 - (int)(r3 * Math.Cos(i * Math.PI / 180));
                            y2 = 200 - (int)(r3 * Math.Sin(i * Math.PI / 180));
                            g.DrawString(Convert.ToString(i / 2), new Font("宋体", 10), Brushes.White, new Point(x2,y2));
                        }
                    }
                    else
                    {
                        if (i % 2 == 0)
                        {
                            x1 = 200 + (int)(r * Math.Cos((180 - i) * Math.PI / 180));
                            y1 = 200 - (int)(r * Math.Sin((180 - i) * Math.PI / 180));
                            x2 = 200 + (int)(r2 * Math.Cos((180 - i) * Math.PI / 180));
                            y2 = 200 - (int)(r2 * Math.Sin((180 - i) * Math.PI / 180));
                        }
                        if (i % 10 == 0)
                        {
                            x2 = 200 + (int)(r3 * Math.Cos((180 - i) * Math.PI / 180));
                            y2 = 200 - (int)(r3 * Math.Sin((180 - i) * Math.PI / 180));
                           // x2 -= 5;
                            //y2 -= 5;
                            g.DrawString(Convert.ToString(i / 2), new Font("宋体", 10), Brushes.White, new Point(x2-5, y2));
                        }
                    }
                    Point p1 = new Point(x1, y1);
                    Point p2 = new Point(x2, y2);                //g.DrawString(Convert.ToString(i / 2), new Font("宋体", 5), Brushes.White, p2);
                    g.DrawLine(new Pen(Color.White), p2, p1);//画刻度线
                }
            }        protected void DrawHand(int _Data)
            {
                _Data *= 2;
                if (_Data > 180)
                    _Data = 180;
                int r2 = 140;
                int Handx = 0;
                int Handy = 0;
                Point CenterPoint=new Point(200,200);
                if (_Data > 90)
                {
                    Handx = 200 - (int)(r2 * Math.Cos(_Data * Math.PI / 180));
                    Handy = 200 - (int)(r2 * Math.Sin(_Data * Math.PI / 180));
                }
                else
                {
                    Handx = 200 + (int)(r2 * Math.Cos((180 - _Data) * Math.PI / 180));
                    Handy = 200 - (int)(r2 * Math.Sin((180 - _Data) * Math.PI / 180));
                }            panel2.Refresh();
                Graphics g = panel2.CreateGraphics();
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                
               // g.Clear(Color.Black);
                 Point HandPoint = new Point(Handx,Handy);
              
                g.DrawLine(new Pen(Brushes.Blue), CenterPoint, HandPoint);
               
                g.Dispose();
            }
            protected void DrawHand()
            {
                int _Data = int.Parse(textBoxSpeed.Text.ToString());
                _Data *= 2;
                if (_Data > 180)
                    _Data = 180;
                int r2 = 140;
                int Handx = 0;
                int Handy = 0;
                Point CenterPoint = new Point(200, 200);
                if (_Data > 90)
                {
                    Handx = 200 - (int)(r2 * Math.Cos(_Data * Math.PI / 180));
                    Handy = 200 - (int)(r2 * Math.Sin(_Data * Math.PI / 180));
                }
                else
                {
                    Handx = 200 + (int)(r2 * Math.Cos((180 - _Data) * Math.PI / 180));
                    Handy = 200 - (int)(r2 * Math.Sin((180 - _Data) * Math.PI / 180));
                }            //panel2.Refresh();
                Graphics g = panel2.CreateGraphics();
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;            // g.Clear(Color.Black);
                Point HandPoint = new Point(Handx, Handy);            g.DrawLine(new Pen(Brushes.Blue), CenterPoint, HandPoint);
                g.Dispose();
            }