0

I´m trying to draw a lemiscate. My code isn't drawing the curve correctly. Why does the line start or end at the point 0,0 (left corner)?

enter image description here

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;
}
Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
user1097772
  • 3,499
  • 15
  • 59
  • 95

1 Answers1

1

You should investigate which element of p is (0, 0). You can use the debugger to inspect it or use a loop to look for it and print out which index(es) have (0, 0).

Hint: consider what effect if (r > 0) continue; has on your output.

Gabe
  • 84,912
  • 12
  • 139
  • 238