12,399,799 members (48,416 online)
Rate this:
See more:
Hi
How can i draw an Ellipse with Midpoint method in visual-studio c++?
Posted 26-Dec-11 3:00am
z_s936383

Rate this:

Solution 1

One of lot of possibilities...by google "opengl ellipse":
http://stackoverflow.com/questions/5886628/effecient-way-to-draw-ellipse-with-opengl-or-d3d[^]

In the hope language depended differences can be resolved by OP.

Regards.
v2
z_s936 27-Dec-11 11:42am

Thanks but I need to draw an Ellipse with MIDPOINT method in visual-studio c++
Rate this:

Solution 2

```void drawEllipse(float xc, float yc, float x, float y)
{
int p1[] = {(int)xc+x, (int)yc+y};
int p2[] = {(int)xc-x, (int)yc+y};
int p3[] = {(int)xc+x, (int)yc-y};
int p4[] = {(int)xc-x, (int)yc-y};
glVertex2iv(p1);
glVertex2iv(p2);
glVertex2iv(p3);
glVertex2iv(p4);
}

void ellipseMidpoint(float xc, float yc, float rx, float ry)
{
float rxSq = rx * rx;
float rySq = ry * ry;
float x = 0, y = ry, p;
float px = 0, py = 2 * rxSq * y;
drawEllipse(xc, yc, x, y);

p = rySq - (rxSq * ry) + (0.25 * rxSq);
while (px < py)
{
x++;
px = px + 2 * rySq;
if (p < 0)
p = p + rySq + px;
else
{
y--;
py = py - 2 * rxSq;
p = p + rySq + px - py;
}
drawEllipse(xc, yc, x, y);
}

p = rySq*(x+0.5)*(x+0.5) + rxSq*(y-1)*(y-1) - rxSq*rySq;
while (y > 0)
{
y--;
py = py - 2 * rxSq;
if (p > 0)
p = p + rxSq - py;
else
{
x++;
px = px + 2 * rySq;
p = p + rxSq - py + px;
}
drawEllipse(xc, yc, x, y);
}
}```

Top Experts
Last 24hrsThis month
 ppolymorphe 375 OriginalGriff 265 Vincent Maverick Durano 265 0x01AA 195 Karthik Bangalore 155
 OriginalGriff 6,723 ppolymorphe 2,835 Karthik Bangalore 2,707 Richard MacCutchan 2,057 F-ES Sitecore 2,052