I'm doing a method to draw this using OpenGL, the drawing is in 2D.
I know the theory, you can find the definition in the Wikipedia, but I don't know what i'm doing wrong. The problem was when I draw the point using the negative solution of the square root.
//-----------------------------------------
// ESPIRAL DE FERMAT
//-----------------------------------------
// float a --> x-inicio
// float b --> y-inicio
// float thetaStart --> angulo de comienzo
// float thetaEnd --> angulo de fin.
// unsigned int samples --> número de muestras, por defecto 200.
//------------------------------------------------------------------
void glFermatSpiral(float a, float b, float thetaStart, float thetaEnd, unsigned int samples = 200 )
{
glBegin( GL_LINE_STRIP );
float dt = (thetaEnd - thetaStart) / (float)samples;
for( unsigned int i = 0; i <= samples; ++i )
{
// archimedean spiral
float theta = thetaStart + (i * dt);
// Specific to made a Fermat Spiral.
float r = sqrt( theta );
// polar to cartesian
float x = r * cos( theta );
float y = r * sin( theta );
// Square root means two solutions, one positive and other negative. 2 points to be drawn.
glVertex2f( x, y );
x = -r * cos( theta );
y = -r * sin( theta );
glVertex2f( x, y );
}
glEnd();
}
That's the way i call this method and hoy my drawing space is defined.
glFermatSpiral(0.05, 0.2, 1.0, 25.0);
gluOrtho2D(-4, 4, -4, 4); // left, right, bottom, top
That's like the solution would be.
You're using a line strip to draw the points, but you keep bouncing back and forth between the positive and negative side of the spiral.
Unless you want a line to be drawn between these points, you should not put them sequentially in a strip.
I suggest drawing one line strip of all the positive solutions, then start a new line strip with all the negative solutions. You need to draw the lines separately.