Complex Number Class
A complex number is a number that has two components; the real component and the imaginary component.
a + bi
Arithmetic is defined as follows:
(a + bi) + (c + di) = (a + c) + (b + d)i
(a + bi) - (c + di) = (a - c) + (b - d)i
(a + bi) * (c + di) = (ac - bd) + (ad + bc)i
(a + bi) / (c + di) = (ac + bd) / (c**2+d**2) + [ (bc -ad) /(c**2+d**2)]i
Class Declaration
class complex
{
public:
complex();
complex(double,double);
double getReal() const;
void setReal(double);
complex operator+(complex) const;
complex operator-(complex) const;
complex operator*(complex) const;
complex operator/(complex) const;
private:
double real, imag;
};
complex::complex():real(0),y(0)
{ //default constructor
}
complex :: complex(double r, double im)
{
real = r;
imag = im;
}
complex complex::operator+(complex c) const
{
complex temp;
temp.real = real + c.real;
temp.imag = imag + c.imag;
return temp;
}
complex complex::operator/(complex c) const
{
complex temp;
temp.real = (real*c.real + imag*c.imag)/
( pow(c.real,2) + pow(imag,2) );
temp.imag = (imag*c.real - real*c.imag)/
( pow(c.real,2) + pow(imag,2) );
return temp;
}
complex complex::operator*(complex c) const
{
complex temp;
temp.real = real*c.real – imag*c.imag;
temp.imag = real*c.imag + imag*c.real;
return temp;
}
Wednesday, March 31, 2010
Tuesday, March 30, 2010
Scan line poly fill
#include
#include
#include
main()
{
int n,i,j,k,gd,gm,dy,dx;
int x,y,temp;
int a[20][2],xi[20];
float slope[20];
clrscr();
printf("\n\n\tEnter the no. of edges of polygon : ");
scanf("%d",&n);
printf("\n\n\tEnter the cordinates of polygon :\n\n\n ");
for(i=0;i
{
printf("\tX%d Y%d : ",i,i);
scanf("%d %d",&a[i][0],&a[i][1]);
}
a[n][0]=a[0][0]; // polygon
a[n][1]=a[0][1];
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\bgi");
/*- draw polygon -*/
for(i=0;i
{
line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]);
}
getch();
for(i=0;i
{
dy=a[i+1][1]-a[i][1];
dx=a[i+1][0]-a[i][0];
if(dy==0) slope[i]=1.0;
if(dx==0) slope[i]=0.0;
if((dy!=0)&&(dx!=0)) /*- calculate inverse slope -*/
{
slope[i]=(float) dx/dy;
}
}
for(y=0;y< 480;y++) // find x intersections
{
k =0;
for(i=0;i
{
if( ((a[i][1]<=y)&&(a[i+1][1]>y))
((a[i][1]>y)&&(a[i+1][1]<=y)))
{
xi[k]=(int)(a[i][0]+slope[i]*(y-a[i][1]));
k++;
}
}
for(j=0;j
for(i=0;i
{
if(xi[i]>xi[i+1])
{
temp=xi[i];
xi[i]=xi[i+1];
xi[i+1]=temp;
}
}
setcolor(35);
for(i=0;i
{
line(xi[i],y,xi[i+1]+1,y);
getch();
}
}
return 0;
}
#include
#include
main()
{
int n,i,j,k,gd,gm,dy,dx;
int x,y,temp;
int a[20][2],xi[20];
float slope[20];
clrscr();
printf("\n\n\tEnter the no. of edges of polygon : ");
scanf("%d",&n);
printf("\n\n\tEnter the cordinates of polygon :\n\n\n ");
for(i=0;i
{
printf("\tX%d Y%d : ",i,i);
scanf("%d %d",&a[i][0],&a[i][1]);
}
a[n][0]=a[0][0]; // polygon
a[n][1]=a[0][1];
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\bgi");
/*- draw polygon -*/
for(i=0;i
{
line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]);
}
getch();
for(i=0;i
{
dy=a[i+1][1]-a[i][1];
dx=a[i+1][0]-a[i][0];
if(dy==0) slope[i]=1.0;
if(dx==0) slope[i]=0.0;
if((dy!=0)&&(dx!=0)) /*- calculate inverse slope -*/
{
slope[i]=(float) dx/dy;
}
}
for(y=0;y< 480;y++) // find x intersections
{
k =0;
for(i=0;i
{
if( ((a[i][1]<=y)&&(a[i+1][1]>y))
((a[i][1]>y)&&(a[i+1][1]<=y)))
{
xi[k]=(int)(a[i][0]+slope[i]*(y-a[i][1]));
k++;
}
}
for(j=0;j
for(i=0;i
{
if(xi[i]>xi[i+1])
{
temp=xi[i];
xi[i]=xi[i+1];
xi[i+1]=temp;
}
}
setcolor(35);
for(i=0;i
{
line(xi[i],y,xi[i+1]+1,y);
getch();
}
}
return 0;
}
FTP access
Who deleted SECOMP folder from ftp?
This is very serious!!!
Definately some one from your class....
This is very serious!!!
Definately some one from your class....
Subscribe to:
Posts (Atom)