Friday, 27 September 2013

Mid point ellipse



#include <graphics.h>
#include <iostream.h>
#include <math.h>
#include <conio.h>

 void main()
{
   clrscr();
    float rx,ry,xc,yc,x0,y0,x,y;
    float p1,p2;

    int gdriver = DETECT, gmode;
    initgraph(&gdriver, &gmode, "C:\\TURBOC3\\BGI");

    cout<<"enter rx and ry=";
    cin>>rx>>ry;

    cout<<"enter xc and yc=";
    cin>>xc>>yc;

    x0=0;
    y0=ry;
    x=x0;
    y=y0;

    putpixel(xc+x0,yc+y0,RED);
    putpixel(xc+x0,yc-y0,RED);

    p1=(ry*ry)-(rx*rx*ry)+((rx*rx)/4);
    do
    {
    x++;
    if(p1<0)
    {
     p1=p1+(2*ry*ry*x)+(ry*ry);
     }
     else
     {
     y--;
     p1=p1+(2*ry*ry*x)-(2*rx*rx*y)+(ry*ry);
     }

      putpixel(x+xc,y+yc,RED);
      putpixel((-x+xc),(-y+yc),RED);
      putpixel((-x+xc),y+yc,RED);
      putpixel(x+xc,(-y+yc),RED);
     }while(ry*ry*x>=radd titlex*rx*y);


    p2=(ry*ry*(x+0.5)*(x+0.5))+(rx*rx)*(y-1)*(y-1)-(rx*rx)*(ry*ry);

    do
    {
    y--;
    if(p2>0)
    {
    p2=p2-(2*rx*rx*y)+(rx*rx);
    }
    else
    {
    x++;
    p2=p2-(2*rx*rx*y)+(2*ry*ry*x)+(rx*rx);
    }
    putpixel(x+xc,y+yc,RED);
    putpixel((-x+xc),(-y+yc),RED);
    putpixel((-x+xc),y+yc,RED);
    putpixel(x+xc,(-y+yc),RED);
    }while(y!=0||x!=rx);

   getch();
   closegraph();
}
Jerrin Andrei Web Developer

No comments:

Post a Comment

Total Pageviews

DjKiRu Initative. Powered by Blogger.