SlideShare a Scribd company logo
Filled-Area Primitives
Region filling is the process of filling image or region.
• Convex and Concave Polygons
P1
P2
P1
P2
Polygon Drawing
• int Point[10]; OR int Point[ ]={3,12,9,15,17,11,15,4,6,5};
• Point[0]=3
• Point[1]=12
• Point[2]=9
• Point[3]=15
• Point[4]=17
• Point[5]=11
• Point[6]=15
• Point[7]=4
• Point[8]=6
• Point[9]=5
drawpoly(5, Point)
OR
line (3, 12, 9, 15)
line (9, 15, 17, 11)
line (17, 11 15, 4)
line (15, 4, 6, 5)
line (6, 5, 3, 12)
• int a[20][2]
• printf("nntEnter the no. of edges of polygon : ");
• scanf("%d",&n);
• printf("nntEnter the cordinates of polygon :nnn ");
• 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];
• /*- draw polygon -*/
• for(i=0;i<n;i++)
• {
• line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]);
• }
POLYGON FILLING
• Means highlighting all the pixels which lie inside the
polygon.
• Colour other than background colour.
• Polygons are easier to fill.
• There are two basic approaches
1. Seed Fill
i. Boundary Fill Algorithm
ii. Flood Fill Algorithm
2. Scanline Algorithm
1.Seed Fill
(X , Y)
(X , Y - 1)
(X -1 , Y - 1)
(X + 1 , Y + 1)
(X - 1 , Y + 1) (X , Y + 1)
(X , Y - 1)
(X - 1 , Y) (X + 1 , Y)
(X , Y)
(X + 1 , Y - 1)
(X - 1 , Y) (X + 1 , Y)
(X , Y + 1)
• Disadvantage:
• 1. Very slow algorithm
• 2. May be fail for large polygons
• 3. Initial pixel required more knowledge about surrounding pixels.
Scan-Line Method for Filling Polygons
(2 , 9)
(7 , 7)
(13 , 11)
(13 , 5)
(7 , 1)
(2 , 3)
m=(9-7)/(2-7) = -2/5
=> 1/m = -5/2------for EF
• #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("nntEnter the no. of edges of polygon : ");
• scanf("%d",&n);
• printf("nntEnter the cordinates of polygon :nnn ");
• 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:tcbgi");
• /*- 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();
• }
• }
• }
Nonzero Winding Number Rule
>Unsuitable for Line based Z-
Buffer
>These methods can also
apply to any closed curves
>Suitable for Line based Z-
Buffer
>This method is difficult to
apply to any closed curves

More Related Content

Similar to CA301_CG_Filled Area Primitives-New.pptx

Lec23-CS110 Computational Engineering
Lec23-CS110 Computational EngineeringLec23-CS110 Computational Engineering
Lec23-CS110 Computational Engineering
Sri Harsha Pamu
 
Python Fundamentals - Basic
Python Fundamentals - BasicPython Fundamentals - Basic
Python Fundamentals - Basic
Wei-Yuan Chang
 
R
RR
White-Box Testing on Methods
White-Box Testing on MethodsWhite-Box Testing on Methods
White-Box Testing on Methods
Minhas Kamal
 
CS.3.Arrays.pdf
CS.3.Arrays.pdfCS.3.Arrays.pdf
CS.3.Arrays.pdf
YasirAli74993
 
Week7
Week7Week7
Logic development
Logic developmentLogic development
Logic development
Jerin John
 
C arrays
C arraysC arrays
CG OpenGL 3D object representations-course 8
CG OpenGL 3D object representations-course 8CG OpenGL 3D object representations-course 8
CG OpenGL 3D object representations-course 8
fungfung Chen
 
Lec38
Lec38Lec38
Big datacourse
Big datacourseBig datacourse
Big datacourse
Massimiliano Ruocco
 
Graphic Design Lab File.docx
Graphic Design Lab File.docxGraphic Design Lab File.docx
Graphic Design Lab File.docx
PayalJindal19
 
Lesson 5 mappings to graphs
Lesson 5 mappings to graphsLesson 5 mappings to graphs
Lesson 5 mappings to graphs
Angela Phillips
 
Junaid program assignment
Junaid program assignmentJunaid program assignment
Junaid program assignment
Junaid Ahmed
 
Yoyak ScalaDays 2015
Yoyak ScalaDays 2015Yoyak ScalaDays 2015
Yoyak ScalaDays 2015
ihji
 
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docxCOMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
TashiBhutia12
 
Mcs011 solved assignment by divya singh
Mcs011 solved assignment by divya singhMcs011 solved assignment by divya singh
Mcs011 solved assignment by divya singh
DIVYA SINGH
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
Tony Kurishingal
 
โปรแกรมภาษาซีเบื้องต้น
โปรแกรมภาษาซีเบื้องต้นโปรแกรมภาษาซีเบื้องต้น
โปรแกรมภาษาซีเบื้องต้น
เทวัญ ภูพานทอง
 
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
AAKASH KUMAR
 

Similar to CA301_CG_Filled Area Primitives-New.pptx (20)

Lec23-CS110 Computational Engineering
Lec23-CS110 Computational EngineeringLec23-CS110 Computational Engineering
Lec23-CS110 Computational Engineering
 
Python Fundamentals - Basic
Python Fundamentals - BasicPython Fundamentals - Basic
Python Fundamentals - Basic
 
R
RR
R
 
White-Box Testing on Methods
White-Box Testing on MethodsWhite-Box Testing on Methods
White-Box Testing on Methods
 
CS.3.Arrays.pdf
CS.3.Arrays.pdfCS.3.Arrays.pdf
CS.3.Arrays.pdf
 
Week7
Week7Week7
Week7
 
Logic development
Logic developmentLogic development
Logic development
 
C arrays
C arraysC arrays
C arrays
 
CG OpenGL 3D object representations-course 8
CG OpenGL 3D object representations-course 8CG OpenGL 3D object representations-course 8
CG OpenGL 3D object representations-course 8
 
Lec38
Lec38Lec38
Lec38
 
Big datacourse
Big datacourseBig datacourse
Big datacourse
 
Graphic Design Lab File.docx
Graphic Design Lab File.docxGraphic Design Lab File.docx
Graphic Design Lab File.docx
 
Lesson 5 mappings to graphs
Lesson 5 mappings to graphsLesson 5 mappings to graphs
Lesson 5 mappings to graphs
 
Junaid program assignment
Junaid program assignmentJunaid program assignment
Junaid program assignment
 
Yoyak ScalaDays 2015
Yoyak ScalaDays 2015Yoyak ScalaDays 2015
Yoyak ScalaDays 2015
 
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docxCOMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
 
Mcs011 solved assignment by divya singh
Mcs011 solved assignment by divya singhMcs011 solved assignment by divya singh
Mcs011 solved assignment by divya singh
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
 
โปรแกรมภาษาซีเบื้องต้น
โปรแกรมภาษาซีเบื้องต้นโปรแกรมภาษาซีเบื้องต้น
โปรแกรมภาษาซีเบื้องต้น
 
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
 

Recently uploaded

22. Certificate of Appreciation Deepika.
22. Certificate of Appreciation Deepika.22. Certificate of Appreciation Deepika.
22. Certificate of Appreciation Deepika.
Manu Mitra
 
按照学校原版(UofT文凭证书)多伦多大学毕业证快速办理
按照学校原版(UofT文凭证书)多伦多大学毕业证快速办理按照学校原版(UofT文凭证书)多伦多大学毕业证快速办理
按照学校原版(UofT文凭证书)多伦多大学毕业证快速办理
evnum
 
一比一原版(dmu毕业证书)英国德蒙福特大学毕业证如何办理
一比一原版(dmu毕业证书)英国德蒙福特大学毕业证如何办理一比一原版(dmu毕业证书)英国德蒙福特大学毕业证如何办理
一比一原版(dmu毕业证书)英国德蒙福特大学毕业证如何办理
uhynup
 
体育博彩论坛-十大体育博彩论坛-体育博彩论坛|【​网址​🎉ac55.net🎉​】
体育博彩论坛-十大体育博彩论坛-体育博彩论坛|【​网址​🎉ac55.net🎉​】体育博彩论坛-十大体育博彩论坛-体育博彩论坛|【​网址​🎉ac55.net🎉​】
体育博彩论坛-十大体育博彩论坛-体育博彩论坛|【​网址​🎉ac55.net🎉​】
waldorfnorma258
 
一比一原版(EUR毕业证)鹿特丹伊拉斯姆斯大学毕业证如何办理
一比一原版(EUR毕业证)鹿特丹伊拉斯姆斯大学毕业证如何办理一比一原版(EUR毕业证)鹿特丹伊拉斯姆斯大学毕业证如何办理
一比一原版(EUR毕业证)鹿特丹伊拉斯姆斯大学毕业证如何办理
nguqayx
 
NOSE CANCER Yashita lesson plan Health & Cancer Related Topics.pdf
NOSE CANCER Yashita lesson plan Health & Cancer Related Topics.pdfNOSE CANCER Yashita lesson plan Health & Cancer Related Topics.pdf
NOSE CANCER Yashita lesson plan Health & Cancer Related Topics.pdf
SanskariYuvi
 
LinkedIn Strategic Guidelines for June 2024
LinkedIn Strategic Guidelines  for June 2024LinkedIn Strategic Guidelines  for June 2024
LinkedIn Strategic Guidelines for June 2024
Bruce Bennett
 
一比一原版英国伦敦南岸大学毕业证(LSBU学位证)如何办理
一比一原版英国伦敦南岸大学毕业证(LSBU学位证)如何办理一比一原版英国伦敦南岸大学毕业证(LSBU学位证)如何办理
一比一原版英国伦敦南岸大学毕业证(LSBU学位证)如何办理
zqgk8x
 
按照学校原版(ArtEZ文凭证书)ArtEZ艺术学院毕业证快速办理
按照学校原版(ArtEZ文凭证书)ArtEZ艺术学院毕业证快速办理按照学校原版(ArtEZ文凭证书)ArtEZ艺术学院毕业证快速办理
按照学校原版(ArtEZ文凭证书)ArtEZ艺术学院毕业证快速办理
evnum
 
在线办理(UOIT毕业证书)安大略省理工大学毕业证在读证明一模一样
在线办理(UOIT毕业证书)安大略省理工大学毕业证在读证明一模一样在线办理(UOIT毕业证书)安大略省理工大学毕业证在读证明一模一样
在线办理(UOIT毕业证书)安大略省理工大学毕业证在读证明一模一样
yhkox
 
一比一原版美国西北大学毕业证(NWU毕业证书)学历如何办理
一比一原版美国西北大学毕业证(NWU毕业证书)学历如何办理一比一原版美国西北大学毕业证(NWU毕业证书)学历如何办理
一比一原版美国西北大学毕业证(NWU毕业证书)学历如何办理
1wful2fm
 
欧洲杯买球-欧洲杯买球买球推荐-欧洲杯买球买球推荐网站|【​网址​🎉ac10.net🎉​】
欧洲杯买球-欧洲杯买球买球推荐-欧洲杯买球买球推荐网站|【​网址​🎉ac10.net🎉​】欧洲杯买球-欧洲杯买球买球推荐-欧洲杯买球买球推荐网站|【​网址​🎉ac10.net🎉​】
欧洲杯买球-欧洲杯买球买球推荐-欧洲杯买球买球推荐网站|【​网址​🎉ac10.net🎉​】
ahmedendrise81
 
一比一原版(uwm毕业证书)美国威斯康星大学密尔沃基分校毕业证如何办理
一比一原版(uwm毕业证书)美国威斯康星大学密尔沃基分校毕业证如何办理一比一原版(uwm毕业证书)美国威斯康星大学密尔沃基分校毕业证如何办理
一比一原版(uwm毕业证书)美国威斯康星大学密尔沃基分校毕业证如何办理
aweuwyo
 
Community Skills Building Workshop | PMI Silver Spring Chapter | June 12, 2024
Community Skills Building Workshop | PMI Silver Spring Chapter  | June 12, 2024Community Skills Building Workshop | PMI Silver Spring Chapter  | June 12, 2024
Community Skills Building Workshop | PMI Silver Spring Chapter | June 12, 2024
Hector Del Castillo, CPM, CPMM
 
EE1K.pdf/////////////////////////////////////////////
EE1K.pdf/////////////////////////////////////////////EE1K.pdf/////////////////////////////////////////////
EE1K.pdf/////////////////////////////////////////////
khansultana
 
Engeneering Model Traffic Lights Circuit
Engeneering Model Traffic Lights CircuitEngeneering Model Traffic Lights Circuit
Engeneering Model Traffic Lights Circuit
KethavathVenkatesh3
 
Indore ℂall Girl Book 00000000 ℂall Girl Service In Indore
Indore ℂall Girl Book 00000000 ℂall Girl Service In IndoreIndore ℂall Girl Book 00000000 ℂall Girl Service In Indore
Indore ℂall Girl Book 00000000 ℂall Girl Service In Indore
babesbookhot
 
美洲杯投注-美洲杯投注比分-美洲杯投注比分投注|【​网址​🎉ac44.net🎉​】
美洲杯投注-美洲杯投注比分-美洲杯投注比分投注|【​网址​🎉ac44.net🎉​】美洲杯投注-美洲杯投注比分-美洲杯投注比分投注|【​网址​🎉ac44.net🎉​】
美洲杯投注-美洲杯投注比分-美洲杯投注比分投注|【​网址​🎉ac44.net🎉​】
balliuvilla512
 
Tara E Browne, DTM - Administrative Manager (Resume)
Tara E Browne, DTM - Administrative Manager (Resume)Tara E Browne, DTM - Administrative Manager (Resume)
Tara E Browne, DTM - Administrative Manager (Resume)
Tara E. Browne, DTM
 
Untitled presentation.pptx jklyvtguhiohk
Untitled presentation.pptx jklyvtguhiohkUntitled presentation.pptx jklyvtguhiohk
Untitled presentation.pptx jklyvtguhiohk
Excellence Tecnology
 

Recently uploaded (20)

22. Certificate of Appreciation Deepika.
22. Certificate of Appreciation Deepika.22. Certificate of Appreciation Deepika.
22. Certificate of Appreciation Deepika.
 
按照学校原版(UofT文凭证书)多伦多大学毕业证快速办理
按照学校原版(UofT文凭证书)多伦多大学毕业证快速办理按照学校原版(UofT文凭证书)多伦多大学毕业证快速办理
按照学校原版(UofT文凭证书)多伦多大学毕业证快速办理
 
一比一原版(dmu毕业证书)英国德蒙福特大学毕业证如何办理
一比一原版(dmu毕业证书)英国德蒙福特大学毕业证如何办理一比一原版(dmu毕业证书)英国德蒙福特大学毕业证如何办理
一比一原版(dmu毕业证书)英国德蒙福特大学毕业证如何办理
 
体育博彩论坛-十大体育博彩论坛-体育博彩论坛|【​网址​🎉ac55.net🎉​】
体育博彩论坛-十大体育博彩论坛-体育博彩论坛|【​网址​🎉ac55.net🎉​】体育博彩论坛-十大体育博彩论坛-体育博彩论坛|【​网址​🎉ac55.net🎉​】
体育博彩论坛-十大体育博彩论坛-体育博彩论坛|【​网址​🎉ac55.net🎉​】
 
一比一原版(EUR毕业证)鹿特丹伊拉斯姆斯大学毕业证如何办理
一比一原版(EUR毕业证)鹿特丹伊拉斯姆斯大学毕业证如何办理一比一原版(EUR毕业证)鹿特丹伊拉斯姆斯大学毕业证如何办理
一比一原版(EUR毕业证)鹿特丹伊拉斯姆斯大学毕业证如何办理
 
NOSE CANCER Yashita lesson plan Health & Cancer Related Topics.pdf
NOSE CANCER Yashita lesson plan Health & Cancer Related Topics.pdfNOSE CANCER Yashita lesson plan Health & Cancer Related Topics.pdf
NOSE CANCER Yashita lesson plan Health & Cancer Related Topics.pdf
 
LinkedIn Strategic Guidelines for June 2024
LinkedIn Strategic Guidelines  for June 2024LinkedIn Strategic Guidelines  for June 2024
LinkedIn Strategic Guidelines for June 2024
 
一比一原版英国伦敦南岸大学毕业证(LSBU学位证)如何办理
一比一原版英国伦敦南岸大学毕业证(LSBU学位证)如何办理一比一原版英国伦敦南岸大学毕业证(LSBU学位证)如何办理
一比一原版英国伦敦南岸大学毕业证(LSBU学位证)如何办理
 
按照学校原版(ArtEZ文凭证书)ArtEZ艺术学院毕业证快速办理
按照学校原版(ArtEZ文凭证书)ArtEZ艺术学院毕业证快速办理按照学校原版(ArtEZ文凭证书)ArtEZ艺术学院毕业证快速办理
按照学校原版(ArtEZ文凭证书)ArtEZ艺术学院毕业证快速办理
 
在线办理(UOIT毕业证书)安大略省理工大学毕业证在读证明一模一样
在线办理(UOIT毕业证书)安大略省理工大学毕业证在读证明一模一样在线办理(UOIT毕业证书)安大略省理工大学毕业证在读证明一模一样
在线办理(UOIT毕业证书)安大略省理工大学毕业证在读证明一模一样
 
一比一原版美国西北大学毕业证(NWU毕业证书)学历如何办理
一比一原版美国西北大学毕业证(NWU毕业证书)学历如何办理一比一原版美国西北大学毕业证(NWU毕业证书)学历如何办理
一比一原版美国西北大学毕业证(NWU毕业证书)学历如何办理
 
欧洲杯买球-欧洲杯买球买球推荐-欧洲杯买球买球推荐网站|【​网址​🎉ac10.net🎉​】
欧洲杯买球-欧洲杯买球买球推荐-欧洲杯买球买球推荐网站|【​网址​🎉ac10.net🎉​】欧洲杯买球-欧洲杯买球买球推荐-欧洲杯买球买球推荐网站|【​网址​🎉ac10.net🎉​】
欧洲杯买球-欧洲杯买球买球推荐-欧洲杯买球买球推荐网站|【​网址​🎉ac10.net🎉​】
 
一比一原版(uwm毕业证书)美国威斯康星大学密尔沃基分校毕业证如何办理
一比一原版(uwm毕业证书)美国威斯康星大学密尔沃基分校毕业证如何办理一比一原版(uwm毕业证书)美国威斯康星大学密尔沃基分校毕业证如何办理
一比一原版(uwm毕业证书)美国威斯康星大学密尔沃基分校毕业证如何办理
 
Community Skills Building Workshop | PMI Silver Spring Chapter | June 12, 2024
Community Skills Building Workshop | PMI Silver Spring Chapter  | June 12, 2024Community Skills Building Workshop | PMI Silver Spring Chapter  | June 12, 2024
Community Skills Building Workshop | PMI Silver Spring Chapter | June 12, 2024
 
EE1K.pdf/////////////////////////////////////////////
EE1K.pdf/////////////////////////////////////////////EE1K.pdf/////////////////////////////////////////////
EE1K.pdf/////////////////////////////////////////////
 
Engeneering Model Traffic Lights Circuit
Engeneering Model Traffic Lights CircuitEngeneering Model Traffic Lights Circuit
Engeneering Model Traffic Lights Circuit
 
Indore ℂall Girl Book 00000000 ℂall Girl Service In Indore
Indore ℂall Girl Book 00000000 ℂall Girl Service In IndoreIndore ℂall Girl Book 00000000 ℂall Girl Service In Indore
Indore ℂall Girl Book 00000000 ℂall Girl Service In Indore
 
美洲杯投注-美洲杯投注比分-美洲杯投注比分投注|【​网址​🎉ac44.net🎉​】
美洲杯投注-美洲杯投注比分-美洲杯投注比分投注|【​网址​🎉ac44.net🎉​】美洲杯投注-美洲杯投注比分-美洲杯投注比分投注|【​网址​🎉ac44.net🎉​】
美洲杯投注-美洲杯投注比分-美洲杯投注比分投注|【​网址​🎉ac44.net🎉​】
 
Tara E Browne, DTM - Administrative Manager (Resume)
Tara E Browne, DTM - Administrative Manager (Resume)Tara E Browne, DTM - Administrative Manager (Resume)
Tara E Browne, DTM - Administrative Manager (Resume)
 
Untitled presentation.pptx jklyvtguhiohk
Untitled presentation.pptx jklyvtguhiohkUntitled presentation.pptx jklyvtguhiohk
Untitled presentation.pptx jklyvtguhiohk
 

CA301_CG_Filled Area Primitives-New.pptx

  • 1. Filled-Area Primitives Region filling is the process of filling image or region.
  • 2.
  • 3. • Convex and Concave Polygons P1 P2 P1 P2
  • 4.
  • 6. • int Point[10]; OR int Point[ ]={3,12,9,15,17,11,15,4,6,5}; • Point[0]=3 • Point[1]=12 • Point[2]=9 • Point[3]=15 • Point[4]=17 • Point[5]=11 • Point[6]=15 • Point[7]=4 • Point[8]=6 • Point[9]=5 drawpoly(5, Point) OR line (3, 12, 9, 15) line (9, 15, 17, 11) line (17, 11 15, 4) line (15, 4, 6, 5) line (6, 5, 3, 12)
  • 7. • int a[20][2] • printf("nntEnter the no. of edges of polygon : "); • scanf("%d",&n); • printf("nntEnter the cordinates of polygon :nnn "); • 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]; • /*- draw polygon -*/ • for(i=0;i<n;i++) • { • line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]); • }
  • 8. POLYGON FILLING • Means highlighting all the pixels which lie inside the polygon. • Colour other than background colour. • Polygons are easier to fill. • There are two basic approaches 1. Seed Fill i. Boundary Fill Algorithm ii. Flood Fill Algorithm 2. Scanline Algorithm
  • 10.
  • 11. (X , Y) (X , Y - 1) (X -1 , Y - 1) (X + 1 , Y + 1) (X - 1 , Y + 1) (X , Y + 1) (X , Y - 1) (X - 1 , Y) (X + 1 , Y) (X , Y) (X + 1 , Y - 1) (X - 1 , Y) (X + 1 , Y) (X , Y + 1)
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19. • Disadvantage: • 1. Very slow algorithm • 2. May be fail for large polygons • 3. Initial pixel required more knowledge about surrounding pixels.
  • 20. Scan-Line Method for Filling Polygons
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29. (2 , 9) (7 , 7) (13 , 11) (13 , 5) (7 , 1) (2 , 3) m=(9-7)/(2-7) = -2/5 => 1/m = -5/2------for EF
  • 30.
  • 31. • #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("nntEnter the no. of edges of polygon : "); • scanf("%d",&n); • printf("nntEnter the cordinates of polygon :nnn "); • 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:tcbgi"); • /*- draw polygon -*/ • for(i=0;i<n;i++) • { • line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]); • } • getch();
  • 32. • 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; • } • }
  • 33. • setcolor(35); • for(i=0;i<k;i+=2) • { • line(xi[i],y,xi[i+1]+1,y); • getch(); • } • } • }
  • 34.
  • 35.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46. >Unsuitable for Line based Z- Buffer >These methods can also apply to any closed curves >Suitable for Line based Z- Buffer >This method is difficult to apply to any closed curves