PDA

View Full Version : N-dependent Radius?



atorres
03-08-2004, 10:05 AM
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?

Leif
03-10-2004, 02:38 AM
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Ö

chemdog
03-15-2004, 03:49 AM
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();
}