• Advertisement
Sign in to follow this  

Drawing a Circle with Midpoint Algorithm

This topic is 4865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im trying to draw a circle using the midpoint circle algorithm and it draws a little less than the top half of the circle and the bottom half of the circle but the left and right side are not there. Is there something im missing looking through the Midpoint code that is messing this up? void circleMidPoint(scrPt circCtr, GLint radius) { GLint xc = circCtr.x; GLint yc = circCtr.y; scrPt circPt; GLint p = 1 - radius; circPt.x = 0; circPt.y = radius; circlePlotPoints(xc,yc,circPt); while(circPt.x < circPt.y) { circPt.x++; if(p < 0) p += circPt.x; else { circPt.y--; p += (circPt.x - circPt.y) + 1; } circlePlotPoints(xc,yc,circPt); } } void circlePlotPoints(GLint xc, GLint yc, screenPt circPt) { setPixel(xc + circPt.x, yc + circPt.y); setPixel(xc - circPt.x, yc + circPt.y); setPixel(xc + circPt.x, yc - circPt.y); setPixel(xc - circPt.x, yc - circPt.y); setPixel(xc + circPt.x, yc + circPt.y); setPixel(xc - circPt.x, yc + circPt.y); setPixel(xc + circPt.x, yc - circPt.y); setPixel(xc - circPt.x, yc - circPt.y); }

Share this post


Link to post
Share on other sites
Advertisement
You really shouldn't be using points unless you really need specific points (I assume you're using OpenGL; this is the GL forum). Instead of using points, it is generally better to put your image on a texture and just use one textured quad.

The reason being that a textured quad is two calls to the graphics card (2 triangles), while you could have hundreds of points that each need to be processed by the CPU, transferred to the GPU, and processed by the GPU.

Share this post


Link to post
Share on other sites
ok only a simple mistake by the looks



while (circPt.x < circPt.y) {
circPt.x++;
if (p < 0) {
p += (circPt.x << 1) + 1; // you had p+=circPt.x when its actually 2 * x + 1;
}
else {
circPt.y--;
p += ((circPt.x - circPt.y) << 1) + 1; // you had p += (circPt.x - circPt.y) + 1 when its actually 2 * (x - y) + 1;
}

circlePlotPoints(xc,xy,circPt);
}



Goodluck !

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement