Browse Groups

• ## File - MIDELLIP.CPP

(187)
• NextPrevious
• # include # include # include # include class Ellipse { private: public: void show_screen( ); void Lines();
Message 1 of 187 , Dec 9 3:37 AM
View Source
# include <iostream.h>
# include <graphics.h>
# include <conio.h>
# include <math.h>

class Ellipse
{
private:

public:
void show_screen( );
void Lines();
void midpoint_ellipse(float,float,float,float);
void angle_ellipse(float,float,float,float);

};

void Ellipse::Lines()
{
setcolor(2);
line(0,240, 640, 240);
line(320,0,320,480);

}

void Ellipse::midpoint_ellipse(float xc, float yc,float a, float b)
{
float color=11;

float aa=(a*a);
float bb=(b*b);
float aa2=(aa*2);
float bb2=(bb*2);

float x=0;
float y=b;

float fx=0;
float fy=(aa2*b);

float p=(float)(bb-(aa*b)+(0.25*aa)+0.5);

putpixel((xc+x),(yc+y),color);
putpixel((xc+x),(yc-y),color);
putpixel((xc-x),(yc-y),color);
putpixel((xc-x),(yc+y),color);

while(fx<fy)
{
x++;
fx+=bb2;

if(p<0)
p+=(fx+bb);

else
{
y--;
fy-=aa2;
p+=(fx+bb-fy);
}

putpixel((xc+x),(yc+y),color);
putpixel((xc+x),(yc-y),color);
putpixel((xc-x),(yc-y),color);
putpixel((xc-x),(yc+y),color);
}

p=(float)((bb*(x+0.5)*(x+0.5))+(aa*(y-1)*(y-1))-(aa*bb)+0.5);

while(y>0)
{
y--;
fy-=aa2;

if(p>=0)
p+=(aa-fy);

else
{
x++;
fx+=bb2;
p+=(fx+aa-fy);
}

putpixel((xc+x),(yc+y),color);
putpixel((xc+x),(yc-y),color);
putpixel((xc-x),(yc-y),color);
putpixel((xc-x),(yc+y),color);
}
}

void Ellipse::angle_ellipse(float x_dash,float y_dash,float a,float b)
{
float color=13;

float aa=(a*a);
float bb=(b*b);
float aa2=(aa*2);
float bb2=(bb*2);

float x=0;
float y=b;

float fx=0;
float fy=(aa2*b);

float p=(float)(bb-(aa*b)+(0.25*aa)+0.5);

putpixel((x_dash+x),(y_dash+y),color);
putpixel((x_dash+x),(y_dash-y),color);
putpixel((x_dash-x),(y_dash-y),color);
putpixel((x_dash-x),(y_dash+y),color);

while(fx<fy)
{
x++;
fx+=bb2;

if(p<0)
p+=(fx+bb);

else
{
y--;
fy-=aa2;
p+=(fx+bb-fy);
}
putpixel((x_dash+x),(y_dash+y),color);
putpixel((x_dash+x),(y_dash-y),color);
putpixel((x_dash-x),(y_dash-y),color);
putpixel((x_dash-x),(y_dash+y),color);

}

p=(float)((bb*(x+0.5)*(x+0.5))+(aa*(y-1)*(y-1))-(aa*bb)+0.5);

while(y>0)
{
y--;
fy-=aa2;

if(p>=0)
p+=(aa-fy);

else
{
x++;
fx+=bb2;
p+=(fx+aa-fy);
}

putpixel((x_dash+x),(y_dash+y),color);
putpixel((x_dash+x),(y_dash-y),color);
putpixel((x_dash-x),(y_dash-y),color);
putpixel((x_dash-x),(y_dash+y),color);
}
}

void Ellipse::show_screen( )
{
restorecrtmode( );
textmode(C4350);

textbackground(1);
cprintf(" MidPoint Ellipse Algorithm ");
textbackground(8);
}

float main( )
{
Ellipse e;
int driver=VGA;
int mode=VGAHI;

double theta;
float xc=0;
float yc=0;
float rx=0;
float ry=0;
float x_dash;
float y_dash;

do
{
e.show_screen( );

gotoxy(8,10);
cout<<"Central Points of the Ellipse : (xc,yc) :";

gotoxy(8,11);
cout<<"�������������������������������������";

gotoxy(12,13);
cout<<"Enter the value of xc = ";
cin>>xc;
xc = xc + 320;
gotoxy(12,14);
cout<<"Enter the value of yc = ";
cin>>yc;
yc = yc + 240;

gotoxy(8,18);
cout<<"Radius of the Ellipse : (rx,ry) :";

gotoxy(8,19);
cout<<"���������������������������������";

gotoxy(12,21);
cout<<"Enter the radius along x-axis : rx = ";
cin>>rx;

gotoxy(12,22);
cout<<"Enter the radius along y-axis : ry = ";
cin>>ry;
gotoxy(12,24);
cout<<"Enter the Angle of the Ellipsea : theta = ";
cin>>theta;
double r = theta * 11/630;

x_dash = xc * cos(r) - yc * sin(r);
y_dash = xc * sin(r) + yc * cos(r);

initgraph(&driver,&mode,"c:/tc/bgi");

setcolor(9);

//-----------calling functions-----------
e.Lines();
e.midpoint_ellipse(xc,yc,rx,ry); //Simple Ellipse
e.angle_ellipse(x_dash,y_dash,rx,ry); //Rotation Ellipse

setcolor(11);
outtextxy(110,460,"Press <any> to continue or Escape key to exit.");

float key=float(getch( ));

if(key==27) break;
}
while(1);

return 0;
}
• # include # include # include # include class Ellipse { private: public: void show_screen( ); void Lines();
Message 187 of 187 , Dec 1 2:04 AM
View Source
# include <iostream.h>
# include <graphics.h>
# include <conio.h>
# include <math.h>

class Ellipse
{
private:

public:
void show_screen( );
void Lines();
void midpoint_ellipse(float,float,float,float);
void angle_ellipse(float,float,float,float);

};

void Ellipse::Lines()
{
setcolor(2);
line(0,240, 640, 240);
line(320,0,320,480);

}

void Ellipse::midpoint_ellipse(float xc, float yc,float a, float b)
{
float color=11;

float aa=(a*a);
float bb=(b*b);
float aa2=(aa*2);
float bb2=(bb*2);

float x=0;
float y=b;

float fx=0;
float fy=(aa2*b);

float p=(float)(bb-(aa*b)+(0.25*aa)+0.5);

putpixel((xc+x),(yc+y),color);
putpixel((xc+x),(yc-y),color);
putpixel((xc-x),(yc-y),color);
putpixel((xc-x),(yc+y),color);

while(fx<fy)
{
x++;
fx+=bb2;

if(p<0)
p+=(fx+bb);

else
{
y--;
fy-=aa2;
p+=(fx+bb-fy);
}

putpixel((xc+x),(yc+y),color);
putpixel((xc+x),(yc-y),color);
putpixel((xc-x),(yc-y),color);
putpixel((xc-x),(yc+y),color);
}

p=(float)((bb*(x+0.5)*(x+0.5))+(aa*(y-1)*(y-1))-(aa*bb)+0.5);

while(y>0)
{
y--;
fy-=aa2;

if(p>=0)
p+=(aa-fy);

else
{
x++;
fx+=bb2;
p+=(fx+aa-fy);
}

putpixel((xc+x),(yc+y),color);
putpixel((xc+x),(yc-y),color);
putpixel((xc-x),(yc-y),color);
putpixel((xc-x),(yc+y),color);
}
}

void Ellipse::angle_ellipse(float x_dash,float y_dash,float a,float b)
{
float color=13;

float aa=(a*a);
float bb=(b*b);
float aa2=(aa*2);
float bb2=(bb*2);

float x=0;
float y=b;

float fx=0;
float fy=(aa2*b);

float p=(float)(bb-(aa*b)+(0.25*aa)+0.5);

putpixel((x_dash+x),(y_dash+y),color);
putpixel((x_dash+x),(y_dash-y),color);
putpixel((x_dash-x),(y_dash-y),color);
putpixel((x_dash-x),(y_dash+y),color);

while(fx<fy)
{
x++;
fx+=bb2;

if(p<0)
p+=(fx+bb);

else
{
y--;
fy-=aa2;
p+=(fx+bb-fy);
}
putpixel((x_dash+x),(y_dash+y),color);
putpixel((x_dash+x),(y_dash-y),color);
putpixel((x_dash-x),(y_dash-y),color);
putpixel((x_dash-x),(y_dash+y),color);

}

p=(float)((bb*(x+0.5)*(x+0.5))+(aa*(y-1)*(y-1))-(aa*bb)+0.5);

while(y>0)
{
y--;
fy-=aa2;

if(p>=0)
p+=(aa-fy);

else
{
x++;
fx+=bb2;
p+=(fx+aa-fy);
}

putpixel((x_dash+x),(y_dash+y),color);
putpixel((x_dash+x),(y_dash-y),color);
putpixel((x_dash-x),(y_dash-y),color);
putpixel((x_dash-x),(y_dash+y),color);
}
}

void Ellipse::show_screen( )
{
restorecrtmode( );
textmode(C4350);

textbackground(1);
cprintf(" MidPoint Ellipse Algorithm ");
textbackground(8);
}

float main( )
{
Ellipse e;
int driver=VGA;
int mode=VGAHI;

double theta;
float xc=0;
float yc=0;
float rx=0;
float ry=0;
float x_dash;
float y_dash;

do
{
e.show_screen( );

gotoxy(8,10);
cout<<"Central Points of the Ellipse : (xc,yc) :";

gotoxy(8,11);
cout<<"�������������������������������������";

gotoxy(12,13);
cout<<"Enter the value of xc = ";
cin>>xc;
xc = xc + 320;
gotoxy(12,14);
cout<<"Enter the value of yc = ";
cin>>yc;
yc = yc + 240;

gotoxy(8,18);
cout<<"Radius of the Ellipse : (rx,ry) :";

gotoxy(8,19);
cout<<"���������������������������������";

gotoxy(12,21);
cout<<"Enter the radius along x-axis : rx = ";
cin>>rx;

gotoxy(12,22);
cout<<"Enter the radius along y-axis : ry = ";
cin>>ry;
gotoxy(12,24);
cout<<"Enter the Angle of the Ellipsea : theta = ";
cin>>theta;
double r = theta * 11/630;

x_dash = xc * cos(r) - yc * sin(r);
y_dash = xc * sin(r) + yc * cos(r);

initgraph(&driver,&mode,"c:/tc/bgi");

setcolor(9);

//-----------calling functions-----------
e.Lines();
e.midpoint_ellipse(xc,yc,rx,ry); //Simple Ellipse
e.angle_ellipse(x_dash,y_dash,rx,ry); //Rotation Ellipse

setcolor(11);
outtextxy(110,460,"Press <any> to continue or Escape key to exit.");

float key=float(getch( ));

if(key==27) break;
}
while(1);

return 0;
}
Your message has been successfully submitted and would be delivered to recipients shortly.
• Changes have not been saved
Press OK to abandon changes or Cancel to continue editing
• Your browser is not supported
Kindly note that Groups does not support 7.0 or earlier versions of Internet Explorer. We recommend upgrading to the latest Internet Explorer, Google Chrome, or Firefox. If you are using IE 9 or later, make sure you turn off Compatibility View.