#include <stdio.h>

#include <conio.h>

#include <graphics.h>

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<n;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];

detectgraph(&gd,&gm);

initgraph(&gd,&gm,"c:\\tc\\bgi");

/*- draw polygon -*/

for(i=0;i<n;i++)

{

line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]);

}

getch();

for(i=0;i<n;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++)

{

k=0;

for(i=0;i<n;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<k-1;j++) /*- Arrange x-intersections in order -*/

for(i=0;i<k-1;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<k;i+=2)

{

line(xi[i],y,xi[i+1]+1,y);

getch();

}

}

}

## Tuesday, October 13, 2009

### Simple C program for Scan Line Polygon Filling Algorithm

Subscribe to:
Post Comments (Atom)

## 26 comments:

nice one!!!

thanks angad for making this program i was long time looking for it.

I'm glad I could be of some help !

Thank You very much Angad

It was very helpful a day before my exam!

hi angad...v r very thankful to u because ur graphics program helped us a lot...and i compiled all of ur programs in graphics..they r so good... one request:can u send the program for checking the given graph is eulerian or not, by using adjacency matrix.

hi angad, is this program based on DDA polygon drawing, or any different algo.???

thank you for the program..

hi angad,ur program really helped me a lot.i would b grateful if u could explain the logic of this program

thanks dude!

mast ha bhai yaar agar edge list se bana de to bhi achcha hoga

hi angad,

if(dy==0) slope[i]=MAX_INTERGER;

if(dx==0) slope[i]=0;

but

if(dy==0) slope[i]=1.0;

how ??

ur algo is absolutely correct, & thnks 4 dat...

i can't run ur scanfill progm.ur algo is absolutely correct, & thnks 4 dat...

i can't run ur scanfill progm.

help me in adak32@gmail.com

why dy==o then slope=1????

that was nice

hello angad

can u explain me

for(y=0;y< 480;y++)

{

k=0;

for(i=0;iy))||

((a[i][1]>y)&&(a[i+1][1]<=y)))

{

xi[k]=(int)(a[i][0]+slope[i]*(y-a[i][1]));

k++;

}

}

above loop

thank u very much. it helped me a lot :)

thanx a lot this program helped me for my final exam

Appreciation for nice Updates, I found something new and folks can get useful info about BEST ONLINE TRAINING

Appreciation for nice Updates, I found something new and folks can get useful info about BEST ONLINE TRAINING

I planing to write algorithm part of my project work question is following

problem is finding intersection of between two ellipses

(x-x1)^2/a^2+(y-y1)^2/b^2=1,(x-x2)^2/c^2+(y-y2)^2/d^2=1 (x1,y1),(x2,y2) point of ellipse and a,b,c,d are major and minor axis of ellipses

please provide any idea of how to find out intersection of two ellipses

output?

This blog awesome and i learn a lot about programming from here.The best thing about this blog is that you doing from beginning to experts level.

Love from

Can anyone. Explain this please

hello angad

can u explain me

for(y=0;y< 480;y++)

{

k=0;

for(i=0;iy))||

((a[i][1]>y)&&(a[i+1][1]<=y)))

{

xi[k]=(int)(a[i][0]+slope[i]*(y-a[i][1]));

k

Are output nahi aa raha hai

lagta HAI galat hai....

color fill nahi ho raha hai........kisne likha hai ye programmm faltu

Post a Comment