0% found this document useful (0 votes)
29 views2 pages

Ellipse Using Mid Point Algorithm

This document contains the code for drawing an ellipse using the Mid-Point circle algorithm. It includes functions to plot points and the main logic to iterate through the points to draw the ellipse. The algorithm uses incremental calculations to determine the x and y coordinates of points on the ellipse as it moves out from the center.

Uploaded by

sadhanamca1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views2 pages

Ellipse Using Mid Point Algorithm

This document contains the code for drawing an ellipse using the Mid-Point circle algorithm. It includes functions to plot points and the main logic to iterate through the points to draw the ellipse. The algorithm uses incremental calculations to determine the x and y coordinates of points on the ellipse as it moves out from the center.

Uploaded by

sadhanamca1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

www.cglabprograms.

com Dipin Krishna


www.cglabprograms.com Dipin Krishna

Ellipse using Mid-Point Algorithm


#include<graphics.h>
#include<conio.h>
#include<stdio.h>

void plotpoints(int cx, int cy, int x, int y)
{
putpixel(cx + x, cy + y, 4);
putpixel(cx - x, cy + y, 4);
putpixel(cx + x, cy - y, 4);
putpixel(cx - x, cy - y, 4);
}

void main()
{
int cx, cy, rx, ry;

printf("Enter the center ");
scanf("%d%d", &cx, &cy);
printf("x radius : ");
scanf("%d", &rx);
printf("y radius : ");
scanf("%d", &ry);

long rx2 = (long) rx * rx;
long ry2 = (long) ry * ry;
long trx2 = 2 * rx2;
long try2 = 2 * ry2;
long p, x = 0, y = ry;
long px = 0;
long py = trx2 * y;

p = (long) ((ry2 - (rx2 * ry) + (0.25 * rx2)) + 0.5);

int gd = DETECT, gm = DETECT;
initgraph(&gd, &gm, "");
cleardevice();

putpixel(cx, cy, 15);

while (px < py) {
plotpoints(cx, cy, x, y);
x++;
px += try2;
if (p < 0)
p += ry2 + px;
else {
y--;
py -= trx2;
p += ry2 + px - py;
}
}





www.cglabprograms.com Dipin Krishna
www.cglabprograms.com Dipin Krishna





py = trx2 * y;
px = try2 * x;
p = (long) ((ry2 * (x + 0.5) * (x + 0.5) + rx2 * (y - 1) * (y - 1) - rx2 * ry2) +
0.5);
while (y >= 0) {
plotpoints(cx, cy, x, y);
y--;
py -= trx2;
if (p > 0)
p += rx2 - py;
else {
x++;
px += try2;
p += rx2 - py + px;
}
}

getch();
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy