Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: N-dependent Radius?

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2004
    Posts
    2

    N-dependent Radius?

    Can anyone find the error?

    Iíve been trying to make a function that draws a spiral based on the following parameter:

    void spiral(int N, float radius, flat step);

    The problem Iím having is that I want to be able to control the size of the spiral by mean of the radius. At this moment I canít see why the figure gets bigger as I increment the N.

    void spiral(int N, float radius, flat step){
    float currRad = step;
    float angle = 360.0 / N;
    float currAngle = 0.0;
    float prevX = currRad, prevY = 0;
    float currX = 0, currY = 0;
    glBegin(GL_LINES);
    for(; currRad < rad; currRad += step){
    currAngle += angle;
    currX = prevX + currRad*cos( PI*currAngle / 180.0);
    currY = prevY + currRad*sin( PI*currAngle / 180.0);
    glVertex2f(prevX, prevY);
    glVertex2f(currX, currY);
    prevX = currX;
    prevY = currY;
    }
    glEnd();
    }

    Ok what is the part of the math Iím missing here?

  2. #2
    Junior Member Newbie
    Join Date
    Mar 2004
    Location
    Sweden
    Posts
    5

    Re: N-dependent Radius?

    A larger N value means that a circle needs more steps to complete, at same time the radius increases with a constant value each step. Thus, larger N = more steps = larger radius.


    LeifÖ

  3. #3
    Intern Contributor
    Join Date
    Feb 2004
    Posts
    98

    Re: N-dependent Radius?

    The points on a circle are defined in polar coordinates, r = radius, theta = angle. and in rectangular coordinates <radius*cos(angle), radius*sin(angle)>.

    A parametric polar definition of a spiral, in terms of t, is r = size*t, theta = phase*t. And converting to rectangular coordinates we get <size*t*cos(phase*t), size*t*sin(phase*t)> for exact coordinates.

    [CODE]
    void DrawSpiral(int subdivision, float size, float phase)
    {
    glBegin(GL_LINE_STRIP);
    while(subdivision--)
    {
    glVertex2f( size * sudivision * cos(phase * subdivision), size * sudivision * sin(phase * sudivision));
    }
    glEnd();
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •