Polygon Clipping

Download as ".c" file http://www.ziddu.com/download/7938911/poly_clipping.zip.html
/* Polygon Clipping*/
#include
#include
int n,p,x,y,i,j;
int xwmin,ywmin,xwmax,ywmax;
int x1,y1,x2,y2,xmax,ymax;
float m;
char flag;
float dy,dx;
main()
{
int gd,gm;
int a[10][10],b[10][10],c[10][10],d[10][10],e[10][10];
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"e:\\tc30\\bgi");
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];
a[n][1]=a[0][1];
printf("\n\tenter the co_ordinates of window :\n ");
printf("\n\txwmin , ywmin : ");
scanf("%d %d",&xwmin,&ywmin);
printf("\n\txwmax , ywmax : ");
scanf("%d %d",&xwmax,&ywmax);
xmax = 640; ymax = 480;
cleardevice();
setcolor(35);
for(i=0;i {
line(a[i][0],ymax-a[i][1],a[i+1][0],ymax-a[i+1][1]);
}
rectangle(xwmin,ymax-ywmin,xwmax,ymax-ywmax);
getch();
setcolor(35);
clip_left(a,b);
clip_right(b,c);
clip_bottom(c,d);
clip_top(d,e);
cleardevice();
setcolor(63);
for(i=0;i {
line(e[i][0],ymax-e[i][1],e[i+1][0],ymax-e[i+1][1]);
}
getch();
}
clip_left(int a[10][10], int b[10][10])
{
p=0;flag=0;m=0;
for(i=0;i {
dy=a[i+1][1]-a[i][1];
dx=a[i+1][0]-a[i][0];
if((dx!=0)&&(dy!=0))
{
m=(dy/dx);
}
if((a[i][0]=xwmin) ) flag=0;
if((a[i][0]>=xwmin)&&(a[i+1][0]>=xwmin)) flag=1;
if((a[i][0]>=xwmin)&&(a[i+1][0] if((a[i][0] switch(flag)
{
case 0 :
x=xwmin;
if(dy!=0)
y=(int)(a[i][1]+m*(x-a[i][0]));
else
y=a[i][1];
b[p][0]=x;
b[p][1]=y;
p++;
b[p][0]=a[i+1][0];
b[p][1]=a[i+1][1];
p++;
break;
case 1 :
b[p][0]=a[i+1][0];
b[p][1]=a[i+1][1];
p++;
break;
case 2 :
x=xwmin;
if(dy!=0)
y=(int)(a[i][1]+m*(x-a[i][0]));
else
y=a[i][1];
b[p][0]=x;
b[p][1]=y;
p++;
}
}
b[p][0]=b[0][0];
b[p][1]=b[0][1];
cleardevice();
setcolor(35);
rectangle(xwmin,ymax-ywmin,xwmax,ymax-ywmax);
setcolor(63);
for(i=0;i {
line(b[i][0],ymax-b[i][1],b[i+1][0],ymax-b[i+1][1]);
getch();
}
getch();
}

clip_right(int b[10][10],int c[10][10])
{
n=p; p=0; m=0;
for(i=0;i {
dy=b[i+1][1]-b[i][1];
dx=b[i+1][0]-b[i][0];
if((dx!=0)&&(dy!=0))
{
m=(dy/dx);
}
if((b[i][0]>xwmax)&&(b[i+1][0]<=xwmax) ) flag=0;
if((b[i][0]<=xwmax)&&(b[i+1][0]<=xwmax) ) flag=1;
if((b[i][0]<=xwmax)&&(b[i+1][0]>xwmax) ) flag=2;
if((b[i][0]>xwmax)&&(b[i+1][0]>xwmax) ) flag=3;
switch(flag)
{
case 0 :
x=xwmax;
if(dy!=0)
y=(int)(b[i][1]+m*(x-b[i][0]));
else
y=b[i][1];
c[p][0]=x;
c[p][1]=y;
p++;
c[p][0]=b[i+1][0];
c[p][1]=b[i+1][1];
p++;
break;
case 1 :
c[p][0]=b[i+1][0];
c[p][1]=b[i+1][1];
p++;
break;

case 2 :
x=xwmax;
if(dy!=0)
y=(int)(b[i][1]+m*(x-b[i][0]));
else
y=b[i][1];
c[p][0]=x;
c[p][1]=y;
p++;
}
}
c[p][0]=c[0][0];
c[p][1]=c[0][1];
cleardevice();
setcolor(35);
rectangle(xwmin,ymax-ywmin,xwmax,ymax-ywmax);
setcolor(63);
for(i=0;i {
line(c[i][0],ymax-c[i][1],c[i+1][0],ymax-c[i+1][1]);
getch();
}
getch();
}

clip_bottom(int c[10][10],int d[10][10])
{
n=p; p=0; m=0;
for(i=0;i {
dy=c[i+1][1]-c[i][1];
dx=c[i+1][0]-c[i][0];
if((dx!=0)&&(dy!=0))
{
m=(dy/dx);
}
if((c[i][1]=ywmin) ) flag=0;
if((c[i][1]>=ywmin)&&(c[i+1][1]>=ywmin) ) flag=1;
if((c[i][1]>=ywmin)&&(c[i+1][1] if((c[i][1] switch(flag)
{
case 0 :
y=ywmin;
if(dx!=0)
x=abs((int)(c[i][0]+(1/m)*(y-c[i][1])));
else
x=c[i][0];
d[p][0]=x;
d[p][1]=y;
p++;
d[p][0]=c[i+1][0];
d[p][1]=c[i+1][1];
p++;
break;
case 1 :
d[p][0]=c[i+1][0];
d[p][1]=c[i+1][1];
p++;
break;
case 2 :
y=ywmin;
if(dx!=0)
x=abs((int)(c[i][0]+(1/m)*(y-c[i][1])));
else
x=c[i][0];
d[p][0]=x;
d[p][1]=y;
p++;
}
}
d[p][0]=d[0][0];
d[p][1]=d[0][1];
cleardevice();
setcolor(35);
rectangle(xwmin,ymax-ywmin,xwmax,ymax-ywmax);
setcolor(63);
for(i=0;i {
line(d[i][0],ymax-d[i][1],d[i+1][0],ymax-d[i+1][1]);
getch();
}
getch();
}

clip_top(int d[10][10],int e[10][10])
{
n=p;
p=0;
for(i=0;i {
dy=d[i+1][1]-d[i][1];
dx=d[i+1][0]-d[i][0];
if((dx!=0)&&(dy!=0))
{
m=(dy/dx);
}
if((d[i][1]>ywmax)&&(d[i+1][1]<=ywmax) ) flag=0;
if((d[i][1]<=ywmax)&&(d[i+1][1]<=ywmax) ) flag=1;
if((d[i][1]<=ywmax)&&(d[i+1][1]>ywmax) ) flag=2;
if((d[i][1]>ywmax)&&(d[i+1][1]>ywmax) ) flag=3;
switch(flag)
{
case 0 :
y=ywmax;
if(dx!=0)
x=abs((int)(d[i][0]+(1/m)*(y-d[i][1])));
else
x=d[i][0];
e[p][0]=x;
e[p][1]=y;
p++;
e[p][0]=d[i+1][0];
e[p][1]=d[i+1][1];
p++;
break;
case 1 :
e[p][0]=d[i+1][0];
e[p][1]=d[i+1][1];
p++;
break;
case 2 :
y=ywmax;
if(dx!=0)
x=abs((int)(d[i][0]+(1/m)*(y-d[i][1])));
else
x=d[i][0];
e[p][0]=x;
e[p][1]=y;
p++;
}
}/*-for()-*/
e[p][0]=e[0][0];
e[p][1]=e[0][1];
cleardevice();
setcolor(35);
rectangle(xwmin,ymax-ywmin,xwmax,ymax-ywmax);
setcolor(63);
for(i=0;i {
line(e[i][0],ymax-e[i][1],e[i+1][0],ymax-e[i+1][1]);
getch();
}
getch();
getch();
}

Download as ".c" file http://www.ziddu.com/download/7938911/poly_clipping.zip.html

Line clipping

Download as ".c" file http://www.ziddu.com/download/7938820/line_clipping.zip.html

/*Line clipping
#include
#include
#include

typedef unsigned int outcode;
enum { TOP=0x1, BOTTOM=0x2, RIGHT=0x4, LEFT=0x8 };

void lineclip(x0,y0,x1,y1,xwmin,ywmin,xwmax,ywmax )
float x0,y0,x1,y1,xwmin,ywmin,xwmax,ywmax;
{

int gd,gm;
outcode code0,code1,codeout;
int accept = 0, done=0;
code0 = calcode(x0,y0,xwmin,ywmin,xwmax,ywmax);
code1 = calcode(x1,y1,xwmin,ywmin,xwmax,ywmax);

do{
if(!(code0 | code1))
{
accept =1 ; done =1;
}
else
if(code0 & code1)
done = 1;
else
{
float x,y;
codeout = code0 ? code0 : code1;
if(codeout & TOP)
{
x = x0 + (x1-x0)*(ywmax-y0)/(y1-y0);
y = ywmax;
}
else
if( codeout & BOTTOM)
{
x = x0 + (x1-x0)*(ywmin-y0)/(y1-y0);
y = ywmin;
}
else
if ( codeout & RIGHT)
{
y = y0+(y1-y0)*(xwmax-x0)/(x1-x0);
x = xwmax;
}
else
{
y = y0 + (y1-y0)*(xwmin-x0)/(x1-x0);
x = xwmin;
}
if( codeout == code0)
{
x0 = x; y0 = y;
code0=calcode(x0,y0,xwmin,ywmin,xwmax,ywmax);
}
else
{
x1 = x; y1 = y;
code1 = calcode(x1,y1,xwmin,ywmin,xwmax,ywmax);
}
}
} while( done == 0);
if(accept) line(x0,y0,x1,y1);
rectangle(xwmin,ywmin,xwmax,ywmax);
getch();

}


int calcode (x,y,xwmin,ywmin,xwmax,ywmax)
float x,y,xwmin,ywmin,xwmax,ywmax;
{
int code =0;
if(y> ywmax)
code |=TOP;
else if( y code |= BOTTOM;
else if(x > xwmax)
code |= RIGHT;
else if ( x< xwmin)
code |= LEFT;
return(code);
}


main()
{

float x2,y2,x1,y1,xwmin,ywmin,xwmax,ywmax;
int gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm,"e:\\tc\\bgi");
printf("\n\n\tEnter the co-ordinates of Line :");
printf("\n\n\tX1 Y1 : ");
scanf("%f %f",&x1,&y1);
printf("\n\n\tX2 Y2 : ");
scanf("%f %f",&x2,&y2);
printf("\n\tEnter the co_ordinates of window :\n ");
printf("\n\txwmin , ywmin : ");
scanf("%f %f",&xwmin,&ywmin);
printf("\n\txwmax , ywmax : ");
scanf("%f %f",&xwmax,&ywmax);
clrscr();
line(x1,y1,x2,y2);
rectangle(xwmin,ywmin,xwmax,ywmax);
getch();
clrscr();
lineclip(x1,y1,x2,y2,xwmin,ywmin,xwmax,ywmax );
getch();
closegraph();

}


Download as ".c" file http://www.ziddu.com/download/7938820/line_clipping.zip.html

Simulation of a fan

Download as ".c" file http://www.ziddu.com/download/7938660/fan.zip.html


/*Simulation of a fan */
#include
#include
#include
#include
#include
const int midx=640/2,midy=480/2;
void drawfin(int angle)
{
setcolor(BLUE);
if(angle==0)
{
pieslice(midx,midy,0,30,35);
}
else
{
pieslice(midx,midy,(angle+30),(angle+30),35);
pieslice(midx,midy,(angle+90),(angle+90+60),35);
pieslice(midx,midy,(angle+270-60),(angle+270),35);
pieslice(midx,midy,(angle+360-60),(angle+360),35);
}
}
void drawfan(int angle)
{
int i;
bar(midx-3,midy,midx+3,midy+60);
bar(midx-35,midy+60,midx+35,midy+80);
bar(midx-30,midy+65,midx+30,midy+75);
for(i=5;i<=40;i+=10)
ellipse(midx,midy,0,360,i,i);
drawfin(angle);
fillellipse(midx,midy,5,5);
for(i=10;i<=40;i+=10)
ellipse(midx,midy,0,360,i,i);
ellipse(midx,midy,0,360,41,41);
}

void main()
{
int angle=0,speed=50,choice;
int gdriver = DETECT, gmode;
initgraph(&gdriver, &gmode, "");
printf("\nELECTRIC FAN");
drawfan(angle);
while(!kbhit())
{
drawfan(angle);
delay(speed);
if(angle==270)
angle=0;
else
angle=angle+90;
cleardevice();
}
closegraph();
}

Download as ".c" file http://www.ziddu.com/download/7938660/fan.zip.html

Familiarization with microprocessor and assembly language programming-David Pager





Professor David Pager
Department of Information and Computer Sciences, University of Hawai`i at Manoa






Website:http://www2.hawaii.edu/~pager/312/





Compilers(Power point presentations) Prof. Kim Hazelwood







Prof. Kim Hazelwood
Computer Science Department
University of Virginia



Website: http://www.cs.virginia.edu/kim/courses/cs671/lectures.html





Posted in Labels: | 0 comments

Formal Languages and Automata(power point presentations)-T. K. Prasad





T. K. Prasad
Department of Computer Science & Engineering
Wright State University


Website:http://www.cs.wright.edu/~tkprasad/courses/cs466/cs466.html





Posted in Labels: | 0 comments

Models of Computation(Power point presentations)-Petros Drineas

Lectures by






Petros Drineas
Associate Professor
Computer Science Department
Rensselaer Polytechnic Institute







Website :http://www.cs.rpi.edu/~drinep/modcomp





Posted in Labels: | 0 comments

Transformations in 2D

Computer Graphics by Dr. Sukhendu das, Dept. of Computer Science and Engineering, IIT Madras

Lecture 1



Download

Lecture 2



Download

Posted in Labels: | 0 comments

CRT Display Devices

Computer Graphics by Dr. Sukhendu das, Dept. of Computer Science and Engineering, IIT Madras

CRT Display Devices- Lecture 1



Download

Lecture 2



Download


Lecture 3



Download


Lecture 4



Download

Posted in Labels: | 0 comments

Computer Graphics -Introduction

Computer Graphics by Dr. Sukhendu das, Dept. of Computer Science and Engineering, IIT Madras.



Download

Posted in Labels: | 0 comments