kol

9
LECTURE: 13 ELLIPSE ALGORITHMS -I 1

Upload: kulbir-singh

Post on 10-Apr-2016

212 views

Category:

Documents


0 download

DESCRIPTION

KOL

TRANSCRIPT

Page 1: Kol

LECTURE: 13ELLIPSE

ALGORITHMS -I1

Page 2: Kol

#include<iostream.h>#include<conio.h>#include<graphics.h>#include<math.h>int midx,midy;void plot4points(int,int);

void main(){int gdriver=DETECT,gmode,errorcode;float r1,r2,xo,yo,i,x,xe,y;

initgraph(&gdriver,&gmode,” “);printf”\n Enter the length of both axis : “;

cin>>r1>>r2;cout<<”\n Enter the center of ellipse   : “;cin>>xo>>yo;

PROGRAM TO DRAW AN ELLIPSE USING POLYNOMIAL METHOD

Page 3: Kol

cout<<”\n Enter the step size           : “;cin>>i;

midx=getmaxx()/2;midy=getmaxy()/2;

x=0;xe=r1;

//putpixel(xo,yo,RED);while(x<=xe)

{y=r2*(sqrt(1-(x*x)/(r1*r1)));plot4points(x,y);x=x+i;}getch();closegraph();}

PROGRAM TO DRAW AN ELLIPSE USING POLYNOMIAL METHOD

Page 4: Kol

void plot4points(int x,int y){putpixel(midx+(x),midy-(y),RED);putpixel(midx+(-x),midy-(y),RED);putpixel(midx+(-x),midy-(-y),RED);putpixel(midx+(x),midy-(-y),RED);}

PROGRAM TO DRAW AN ELLIPSE USING POLYNOMIAL METHOD

Page 5: Kol

#include<iostream.h>#include<conio.h>#include<graphics.h>#include<math.h>int midx,midy;void plot4points(int,int);

void main(){int gdriver=DETECT,gmode,errorcode;float r1,r2,xo,yo,i,x,xe,y;

initgraph(&gdriver,&gmode,” “); printf”\n Enter the length of both axis : “;

cin>>r1>>r2;cout<<”\n Enter the center of ellipse   : “;cin>>xo>>yo;

PROGRAM TO DRAW AN ELLIPSE USING POLYNOMIAL METHOD

Page 6: Kol

#include<stdio.h>#include<conio.h>#include<graphics.h>#include<math.h>void disp();float x,y;int xc,yc;void main(){int gd=DETECT,gm;int a,b;float p1,p2;clrscr();initgraph(&gd,&gm,"");scanf("%d%d",&xc,&yc);scanf("%d%d",&a,&b);

PROGRAM TO DRAW ELLIPSE USING MID POINT ALGORITHM

 

Page 7: Kol

x=0;y=b;disp();p1=(b*b)-(a*a*b)+(a*a)/4;while((2.0*b*b*x)<=(2.0*a*a*y)){x++;if(p1<=0)p1=p1+(2.0*b*b*x)+(b*b);else{y--;p1=p1+(2.0*b*b*x)+(b*b)-(2.0*a*a*y);}disp();x=-x;disp();

PROGRAM TO DRAW AN ELLIPSE USING  MID POINT METHOD

Page 8: Kol

PROGRAM TO DRAW AN ELLIPSE USING  MID POINT METHOD

x=-x;}x=a;y=0;disp();p2=(a*a)+2.0*(b*b*a)+(b*b)/4;while((2.0*b*b*x)>(2.0*a*a*y)){y++;if(p2>0)p2=p2+(a*a)-(2.0*a*a*y);else{x--;p2=p2+(2.0*b*b*x)-(2.0*a*a*y)+(a*a);}disp();

Page 9: Kol

PROGRAM TO DRAW AN ELLIPSE USING  MID POINT METHOD

y=-y;disp();y=-y;}getch();closegraph();}void disp(){putpixel(xc+x,yc+y,10);putpixel(xc-x,yc+y,10);putpixel(xc+x,yc-y,10);putpixel(xc+x,yc-y,10);}