【问题标题】:Drawing polar curve Lemiscate bug绘制极坐标曲线 Lemiscate bug
【发布时间】:2012-06-10 14:36:53
【问题描述】:

我正在尝试绘制lemiscate。我的代码没有正确绘制曲线。为什么线在点 0,0(左角)开始或结束?

private void drawLemiscate(Graphics g, int a, int Sx,int Sy) 
{
    int x, y;


    Point[] p = new Point[720];
    for (int phi = 0; phi < 720; phi++)
    {
        int r = (int)(a * Math.Cos(2 * degreeToRadians(phi)));
        if (r > 0)
            continue;
        x = (int)Math.Round((r * Math.Sin(degreeToRadians(phi)) + Sx));
        y = (int)Math.Round((r * Math.Cos(degreeToRadians(phi)) + Sy));
        p[phi] = new Point(x, y);
    }
    Pen pen = new Pen(Color.Red, 1);
    g.DrawLines(pen, p);
    canvas.Invalidate();
}

private double degreeToRadians(double angle)
{
    return Math.PI * angle / 180.0;
}

【问题讨论】:

    标签: c# curve polar-coordinates


    【解决方案1】:

    您应该调查p 的哪个元素是(0, 0)。您可以使用调试器检查它或使用循环来查找它并打印出哪些索引具有 (0, 0)。

    提示:考虑if (r &gt; 0) continue; 对您的输出有何影响。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-21
      • 1970-01-01
      相关资源
      最近更新 更多