该程序是等分圆,获取各个等分点的坐标,请各位大牛看看有撒子错误啦,我运行没有错误,但是输出的坐标根本就不对。
class Program
    {
        static void Main(string[] args)
        {
            float x, y, r;
            int n;
            Console.WriteLine("请输入等分数:");
            n = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入圆心横坐标:");
            x = float.Parse(Console.ReadLine());
            Console.WriteLine("请输入圆心纵坐标:");
            y = float.Parse(Console.ReadLine());
            Console.WriteLine("请输入圆的半径:");
            r = float.Parse(Console.ReadLine());
            ArrayCircle(r, x, y, n);
            Console.Read();        }
        static void ArrayCircle(float r, float x, float y, int n)
        {
            const float PI = 3.1415926F;
            float[,] arrcircle = new float[n, 2];
            float x1 = x + r;
            float y1 = y;
            arrcircle[0, 0] = x1;
            arrcircle[0, 1] = y1;
            float a = 2*PI/n;
            for (int i = 1; i < n; i++)
            {
                x1 = (float)((x1-x) * Math.Cos(a) - (y1-y) * Math.Sin(a) +x);
                y1 = (float)((x1-x) * Math.Sin(a) + (y1-y) * Math.Cos(a) +y);
                arrcircle[i, 0] = x1;
                arrcircle[i, 1] = y1;
            }
            for (int j= 0; j < n; j++)
            {
                Console.WriteLine("等分点坐标:({0},{1})", arrcircle[j, 0], arrcircle[j, 1]);
                Console.WriteLine("\n");
            }
        }
    }

解决方案 »

  1.   

      for (int i = 1; i < n; i++)
      {
      x1 = (float)((x1-x) * Math.Cos(a) - (y1-y) * Math.Sin(a) +x);
      y1 = (float)((x1-x) * Math.Sin(a) + (y1-y) * Math.Cos(a) +y);
      arrcircle[i, 0] = x1;
      arrcircle[i, 1] = y1;
      }
    这段循环写的不对
    依次增加的是角度,类似于
    r.Math.cos(i*a)+x;
      

  2.   


    static void Main(string[] args)
            {
                float x, y, r;
                int n;
                Console.WriteLine("请输入等分数:");
                n = int.Parse(Console.ReadLine());
                Console.WriteLine("请输入圆心横坐标:");
                x = float.Parse(Console.ReadLine());
                Console.WriteLine("请输入圆心纵坐标:");
                y = float.Parse(Console.ReadLine());
                Console.WriteLine("请输入圆的半径:");
                r = float.Parse(Console.ReadLine());
                ArrayCircle(r, x, y, n);
                Console.Read();        }
            static void ArrayCircle(float r, float x, float y, int n)
            {
                const float PI = 3.1415926F;
                float[,] arrcircle = new float[n, 2];
                float x1 = x + r;
                float y1 = y;
                arrcircle[0, 0] = x1;
                arrcircle[0, 1] = y1;
                float a = 2*PI / n;
                for (int i = 1; i < n; i++)
                {
                    x1 = (float)(r * Math.Cos(i * a) + x);
                    y1 = (float)(r * Math.Sin(i * a) + y);
                    arrcircle[i, 0] = x1;
                    arrcircle[i, 1] = y1;
                }            for (int j = 0; j < n; j++)
                {
                    Console.WriteLine("等分点坐标:({0},{1})", arrcircle[j, 0], arrcircle[j, 1]);
                    Console.WriteLine("\n");
                }
            }
    我改了下,还行。你看看有没问题,我们再交流!
      

  3.   

    结果表明是坐标转化公式有问题,但是我就是不晓得错在哪里?改用x=x+R*Math.cos(a*i)这样的公式就可以得到结果。