[go: up one dir, main page]

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

Midpoint Ellipse

This C++ program uses OpenGL to draw an ellipse by plotting points. It initializes OpenGL settings, defines functions for display and initialization, then contains a main loop that calculates x and y coordinates to draw points on the ellipse. Based on the value of p, it increments or decrements x and y, and updates fx and fy values in each iteration. User input is taken for the ellipse center and axis values, which are then used to plot the points and display the ellipse shape.

Uploaded by

Prapta Chowdhury
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)
52 views2 pages

Midpoint Ellipse

This C++ program uses OpenGL to draw an ellipse by plotting points. It initializes OpenGL settings, defines functions for display and initialization, then contains a main loop that calculates x and y coordinates to draw points on the ellipse. Based on the value of p, it increments or decrements x and y, and updates fx and fy values in each iteration. User input is taken for the ellipse center and axis values, which are then used to plot the points and display the ellipse shape.

Uploaded by

Prapta Chowdhury
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

1 2

#include<windows.h> x++;

#include<GL/glut.h> }

#include<stdlib.h> else

#include<stdio.h> {

float h,k,a,b,x,y,fx,fy,p; fx=fx+2*b*b;

void display(void) x++;

{ x=0; y--;

y=b; fy=fy-2*a*a;

fx=0; p=p+fx+b*b-fy;

fy=2*a*a*b; }

p=(b*b)-(a*a*b)+(0.25*a*a); }

while(fx<fy) p=(b*b)*(x+.5)*(x+.5)+(a*a)*(y-1)*(y-1)-
(a*a)*(b*b);
{
while(y>=0)
glBegin(GL_POINTS);
{
glVertex2f(h+x,k+y);
glBegin(GL_POINTS);
glEnd();
glVertex2f(h+x,k+y);
glBegin(GL_POINTS);
glEnd();
glVertex2f(h-x,k+y);
glBegin(GL_POINTS);
glEnd();
glVertex2f(h-x,k+y);
glBegin(GL_POINTS);
glEnd();
glVertex2f(h-x,k-y);
glBegin(GL_POINTS);
glEnd();
glVertex2f(h-x,k-y);
glBegin(GL_POINTS);
glEnd();
glVertex2f(h+x,k-y);
glBegin(GL_POINTS);
glEnd();
glVertex2f(h+x,k-y);
if(p<0)
glEnd();
{
if(p>=0)
fx=fx+2*b*b;
{
p=p+fx+b*b;
3 4
y--; scanf("%f",&a);

fy=fy-2*a*a; printf("Enter the value of minor axis :");

p=p-fy+a*a; scanf("%f",&b);

} glutInit(&argc, argv);

else if(p<0){ glutInitDisplayMode(GLUT_SINGLE |


GLUT_RGB);
y--;
glutInitWindowSize(500,500);
x++;
glutInitWindowPosition(100,100);
fy=fy-2*a*a;
glutCreateWindow("ellipse");
fx=fx+2*b*b;
init();
p=p+fx-fy+a*a;
glutDisplayFunc(display);
}
glutMainLoop();
}
return 0;
glBegin(GL_POINTS);
}
glEnd();
OUTPUT
glFlush();

void init(void)

glClear(GL_COLOR_BUFFER_BIT);

glClearColor(0,0,0,0);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluOrtho2D(-100,100,-100,100);

int main(int argc, char** argv)

printf("Enter the value of the center: ");

scanf("%f %f", &h,&k);

printf("Enter the value of major axis :");

You might also like