Dark Mode
Image

Scan Converting a Ellipse

The ellipse is also a symmetric figure like a circle but is four-way symmetry rather than eight-way.

Scan Converting a Ellipse

Program to Implement Ellipse Drawing Algorithm:

  1. #include<stdio.h>  
  2. #include<conio.h>  
  3. #include<graphics.h>  
  4. #include<math.h>  
  5. void disp();  
  6. float x,y;  
  7. intxc,yc;  
  8. void main()  
  9. {  
  10.                 intgd=DETECT,gm,a,b;  
  11.                 float p1,p2;  
  12.                 clrscr();  
  13.                 initgraph(&gd,&gm,"c:\\turboc3\\bgi");  
  14.                 printf("*** Ellipse Generating Algorithm ***\n");  
  15.                 printf("Enter the value of Xc\t");  
  16.                 scanf("%d",&xc);  
  17.                 printf("Enter the value of yc\t");  
  18.                 scanf("%d",&yc);  
  19.                 printf("Enter X axis length\t");  
  20.                 scanf("%d",&a);  
  21.                 printf("Enter Y axis length\t");  
  22.                 scanf("%d",&b);  
  23.                 x=0;y=b;  
  24.                 disp();  
  25.                 p1=(b*b)-(a*a*b)+(a*a)/4;  
  26.                 while((2.0*b*b*x)<=(2.0*a*a*y))  
  27.                 {  
  28.                                 x++;  
  29.                                 if(p1<=0)  
  30.                                 p1=p1+(2.0*b*b*x)+(b*b);  
  31.                                 else  
  32.         {  
  33.                                                 y--;  
  34.                                                 p1=p1+(2.0*b*b*x)+(b*b)-(2.0*a*a*y);  
  35.          }  
  36.                                disp();  
  37.                                x=-x;  
  38.                                disp();  
  39.                                x=-x;  
  40.                                delay(50);  
  41.                  }  
  42.                  x=a;  
  43.                  y=0;  
  44.                  disp();  
  45.                  p2=(a*a)+2.0*(b*b*a)+(b*b)/4;  
  46.                  while((2.0*b*b*x)>(2.0*a*a*y))  
  47.                 {  
  48.                                 y++;  
  49.                                 if(p2>0)  
  50.                                 p2=p2+(a*a)-(2.0*a*a*y);  
  51.                                 else  
  52.         {  
  53.                                                 x--;  
  54.                                                 p2=p2+(2.0*b*b*x)-(2.0*a*a*y)+(a*a);  
  55.          }  
  56.                                 disp();  
  57.                                 y=-y;  
  58.                                 disp();  
  59.                                 y=-y;  
  60.                                 delay(50);     
  61.             }  
  62.                 getch();  
  63.                 closegraph();  
  64. }  
  65.  void disp()  
  66. {  
  67.               putpixel(xc+x,yc+y,7);  
  68.                putpixel(xc-x,yc+y,7);  
  69.                putpixel(xc+x,yc-y,7);  
  70.           putpixel(xc+x,yc-y,7);  
  71.   }  

Output:

Scan Converting a Ellipse

There two methods of defining an Ellipse:

Exception Handling in Java - Javatpoint

  1. Polynomial Method of defining an Ellipse
  2. Trigonometric method of defining an Ellipse

Comment / Reply From