-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEllipse using Bresenham
65 lines (63 loc) · 1.29 KB
/
Ellipse using Bresenham
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
AIM:- Draw ellipse using Bresenham Algorithm
CODE:-
#include <GL/glut.h>
#include <math.h>
#include <GL/gl.h>
#include<stdio.h>
void display()
{
float a,rx,b,ry,d1,d2,x,y;
printf("Enter the major axis and minor axis\n");
scanf("%f%f",&rx,&ry);
a=rx;
b=ry;
x=0;
y=b;
d1=(b*b)+(a*a)*(0.25-b);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(0,0,0);
glPointSize(5);
glBegin(GL_POINTS);
while((x*b*b)<=(y*a*a))
{
if(d1<0)
d1= d1+ (b*b) * (2*x+3);
else
{
d1= d1+ (b*b) * (2*x+3) - (a*a) * (2*y-2);
y=y-1;
}
x = x + 1;
glVertex2f(x, y); glVertex2f(x,-y);
glVertex2f(-x, -y); glVertex2f(-x, y);
}
d2=(b*b)((x+0.5)(x+0.5)) + (a*a) * ((y-1)*(y-1)) - (a*a*b*b);
while(y!=0)
{
if(d2<0)
{
d2=d2+ 2* (b*b) * (x+1) - (a*a) * (2*y-3);
x=x+1;
}
else
d2=d2+ (a*a) * (3-2*y);
y=y-1;
glVertex2f(x, y); glVertex2f(x,-y);
glVertex2f(-x, -y); glVertex2f(-x, y);
}
glEnd();
glFlush();
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("Ellipse Mid-Point");
glClearColor(1,1,0,0);
gluOrtho2D(-200.0,200.0,-200.0,200.0);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}