• Create Account

## Drawing a Circle with Midpoint Algorithm

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1Nightshot  Members

122
Like
0Likes
Like

Posted 25 September 2004 - 10:20 AM

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); }

### #2nagromo  Members

676
Like
0Likes
Like

Posted 25 September 2004 - 07:19 PM

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.

### #3lubby  Members

290
Like
0Likes
Like

Posted 25 September 2004 - 07:47 PM

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 !

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.