SlideShare une entreprise Scribd logo
1  sur  16
1 Clipping/fill algorithms
//Graphics Point Clipping C Program
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
int tlx,tly,brx,bry,px,py;
void point_clip()
{ int wxmin,wymin,wxmax,wymax;
wxmin=tlx;
wxmax=brx;
wymin=tly;
wymax=bry;
if(px>=wxmin&&px<=wxmax)
if(py>=wymin&&py<=wymax)
putpixel(px,py,RED);
getch();
closegraph();
}
void main(void)
{ int gd=DETECT,gm,xc,yc,r;
clrscr();
printf("Enter the top left coordinate");
scanf("%d%d",&tlx,&tly);
printf("Enter the bottom right coordinate");
scanf("%d%d",&brx,&bry);
printf("n Enter the point");
scanf("%d%d",&px,&py);
initgraph(&gd,&gm,"c:tcbgi"); /*Sometimes it may be
"C:TCBGI" , It depends machine to mac..*/
setbkcolor(YELLOW);
setcolor(RED);
rectangle(tlx,tly,brx,bry);
point_clip();
}
2 Clipping/fill algorithms
//Sutherland-Hodgeman Polygon clipping Algorithm
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void clip(float,float,float);
int i,j=0,n;
int rx1,rx2,ry1,ry2;
float x1[8],y1[8];
void main()
{
int gd=DETECT,gm;
int i,n;
float x[8],y[8],m;
clrscr();
initgraph(&gd,&gm,"");
printf("coordinates for rectangle : ");
scanf("%d%d%d%d",&rx1,&ry1,&rx2,&ry2);
printf("no. of sides for polygon : ");
scanf("%d",&n);
printf("coordinates : ");
for(i=0;i<n;i++)
{
scanf("%f%f",&x[i],&y[i]);
}
cleardevice();
outtextxy(10,10,"Before clipping");
outtextxy(10,470,"Press any key....");
rectangle(rx1,ry1,rx2,ry2);
for(i=0;i<n-1;i++)
line(x[i],y[i],x[i+1],y[i+1]);
line(x[i],y[i],x[0],y[0]);
getch();
cleardevice();
3 Clipping/fill algorithms
for(i=0;i<n-1;i++)
{
m=(y[i+1]-y[i])/(x[i+1]-x[i]);
clip(x[i],y[i],m);
}
clip(x[0],y[0],m);
outtextxy(10,10,"After clipping");
outtextxy(10,470,"Press any key....");
rectangle(rx1,ry1,rx2,ry2);
for(i=0;i<j-1;i++)
line(x1[i],y1[i],x1[i+1],y1[i+1]);
getch();
}
void clip(float e,float f,float m)
{
while(e<rx1 e>rx2 f<ry1 f>ry2)
{
if(e<rx1)
{
f+=m*(rx1-e);
e=rx1;
}
else if(e>rx2)
{
f+=m*(rx2-e);
e=rx1;
}
if(f<ry1)
{
e+=(ry1-f)/m;
f=ry1;
}
else if(f>ry2)
4 Clipping/fill algorithms
{
e+=(ry2-f)/m;
f=ry2;
}
x1[j]=e;
y1[j]=f;
j++;
}
}
OUTPUT
Enter the x1 & y1 coordinates:
X1 : 70
Y1 : 80
Enter the x2 & y2 coordinates:
X2 : 250
Y2 : 280
5 Clipping/fill algorithms
//polygon clipping
#include<graphics.h>
#include<dos.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int gd, gm ;
int x1 , y1 , x2 , y2 ;
int wxmin,wymin,wxmax, wymax ;
float u1 = 0.0,u2 = 1.0 ;
int p1 , q1 , p2 , q2 , p3 , q3 , p4 ,q4 ;
float r1 , r2 , r3 , r4 ;
int x11 , y11 , x22 , y22 ;
clrscr();
printf("Enter the windows left xmin , top boundry yminn");
scanf("%d%d",&wxmin,&wymin);
printf("Enter the windows right xmax ,bottom boundry
ymaxn");
scanf("%d%d",&wxmax,&wymax);
printf("Enter line x1 , y1 co-ordinaten");
scanf("%d%d",&x1,&y1);
printf("Enter line x2 , y2 co-ordinaten");
scanf("%d%d",&x2,&y2);
printf("liang barsky express these 4 inequalities using
lpk<=qpkn");
p1 = -(x2 - x1 ); q1 = x1 - wxmin ;
p2 = ( x2 - x1 ) ; q2 = wxmax - x1 ;
p3 = - ( y2 - y1 ) ; q3 = y1 - wymin ;
6 Clipping/fill algorithms
p4 = ( y2 - y1 ) ; q4 = wymax - y1 ;
printf("p1=0 line is parallel to left clippingn");
printf("p2=0 line is parallel to right clippingn");
printf("p3=0 line is parallel to bottom clippingn");
printf("p4=0 line is parallel to top clippingn");
if( ( ( p1 == 0.0 ) && ( q1 < 0.0 ) ) ||
( ( p2 == 0.0 ) && ( q2 < 0.0 ) ) ||
( ( p3 == 0.0 ) && ( q3 < 0.0 ) ) ||
( ( p4 == 0.0 ) && ( q4 < 0.0 ) ) )
{
printf("Line is rejectedn");
getch();
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:tcbgi");
setcolor(RED);
rectangle(wxmin,wymax,wxmax,wymin);
setcolor(BLUE);
line(x1,y1,x2,y2);
getch();
setcolor(WHITE);
line(x1,y1,x2,y2);
getch();
}
else
{
if( p1 != 0.0 )
{
r1 =(float) q1 /p1 ;
if( p1 < 0 )
u1 = max(r1 , u1 );
7 Clipping/fill algorithms
else
u2 = min(r1 , u2 );
}
if( p2 != 0.0 )
{
r2 = (float ) q2 /p2 ;
if( p2 < 0 )
u1 = max(r2 , u1 );
else
u2 = min(r2 , u2 );
}
if( p3 != 0.0 )
{
r3 = (float )q3 /p3 ;
if( p3 < 0 )
u1 = max(r3 , u1 );
else
u2 = min(r3 , u2 );
}
if( p4 != 0.0 )
{
r4 = (float )q4 /p4 ;
if( p4 < 0 )
u1 = max(r4 , u1 );
else
u2 = min(r4 , u2 );
}
if( u1 > u2 )
printf("line rejectedn");
else
8 Clipping/fill algorithms
{
x11 = x1 + u1 * ( x2 - x1 ) ;
y11 = y1 + u1 * ( y2 - y1 ) ;
x22 = x1 + u2 * ( x2 - x1 );
y22 = y1 + u2 * ( y2 - y1 );
printf("Original line cordinatesn");
printf("x1 = %d , y1 = %d, x2 = %d, y2 = %dn",x1,y1,x2,y2);
printf("Windows coordinate are n");
printf("wxmin = %d, wymin = %d,wxmax = %d , wymax = %d
",wxmin,wymin,wxmax,wymax);
printf("New coordinates are n");
printf("x1 = %d, y1 = %d,x2 = %d , y2 =
%dn",x11,y11,x22,y22);
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"C:TCBGI");
setcolor(2);
rectangle(wxmin,wymax,wxmax,wymin);
setcolor(1);
line(x1,y1,x2,y2);
getch();
setcolor(0);
line(x1,y1,x2,y2);
setcolor(3);
line(x11,y11,x22,y22);
getch();
}
}
}
9 Clipping/fill algorithms
//C Program For Oblique projection of a 3D object
#include<stdio.h>
#include<math.h>
#include<graphics.h>
main()
{
int x1,y1,x2,y2,gd,gm;
int ymax,a[4][8];
float par[4][4],b[4][8];
int i,j,k,m,n,p;
double L1,phi;
a[0][0] = 100; a[1][0] = 100; a[2][0] = 100;
a[0][1] = 200; a[1][1] = 100; a[2][1] = 100;
a[0][2] = 200; a[1][2] = 200; a[2][2] = 100;
a[0][3] = 100; a[1][3] = 200; a[2][3] = 100;
a[0][4] = 100; a[1][4] = 100; a[2][4] = 200;
a[0][5] = 200; a[1][5] = 100; a[2][5] = 200;
a[0][6] = 200; a[1][6] = 200; a[2][6] = 200;
a[0][7] = 100; a[1][7] = 200; a[2][7] = 200;
phi = (double) (3.14*45.0)/180 ;
L1 = 0.5;
par[0][0] = 1; par[0][1] = 0;
par[0][2] = L1*cos(phi); par[0][3] = 0;
10 Clipping/fill algorithms
par[1][0] = 0; par[1][1] = 1;
par[1][2] = L1*sin(phi); par[1][3] = 0;
par[2][0] = 0; par[2][1] = 0;
par[2][2] = 0; par[2][3] = 0;
par[3][0] = 0; par[3][1] = 0;
par[3][2] = 0; par[3][3] = 1;
m=4; n=4; p=8;
for(i=0; i<m; i++)
for(k=0; k<p; k++)
b[i][k] = 0;
for(i=0; i<m; i++)
for(k=0; k<p; k++)
for(j=0; j<n; j++)
b[i][k] += (float)par[i][j] * a[j][k];
detectgraph(&gd,&gm);
initgraph(&gd,&gm, "c:tcbgi");
ymax = getmaxy();
/*- front plane display -*/
for(j=0;j<3;j++)
{
x1=(int) b[0][j]; y1=(int) b[1][j];
x2=(int) b[0][j+1]; y2=(int) b[1][j+1];
line( x1,ymax-y1,x2,ymax-y2);
11 Clipping/fill algorithms
}
x1=(int) b[0][3]; y1=(int) b[1][3];
x2=(int) b[0][0]; y2=(int) b[1][0];
line( x1,ymax-y1,x2,ymax-y2);
/*- back plane display -*/
setcolor(11);
for(j=4;j<7;j++)
{
x1=(int) b[0][j]; y1=(int) b[1][j];
x2=(int) b[0][j+1]; y2=(int) b[1][j+1];
line( x1,ymax-y1,x2,ymax-y2);
}
x1=(int) b[0][7]; y1=(int) b[1][7];
x2=(int) b[0][4]; y2=(int) b[1][4];
line( x1,ymax-y1,x2,ymax-y2);
setcolor(13);
for(i=0;i<4;i++)
{
x1=(int) b[0][i]; y1=(int) b[1][i];
x2=(int) b[0][4+i]; y2=(int) b[1][4+i];
line( x1,ymax-y1,x2,ymax-y2);
}
getch(); getch();
}
12 Clipping/fill algorithms
C Program to implement Boundary Fill Algorithm
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void fill_right(x,y)
int x , y ;
{
if((getpixel(x,y) != WHITE)&&(getpixel(x,y) != RED))
{
putpixel(x,y,RED);
fill_right(++x,y);
x = x - 1 ;
fill_right(x,y-1);
fill_right(x,y+1);
}
delay(1);
}
void fill_left(x,y)
int x , y ;
{
if((getpixel(x,y) != WHITE)&&(getpixel(x,y) != RED))
{
putpixel(x,y,RED);
fill_left(--x,y);
x = x + 1 ;
fill_left(x,y-1);
13 Clipping/fill algorithms
fill_left(x,y+1);
}
delay(1);
}
void main()
{
int x,y,n,i;
int gd=DETECT,gm;
clrscr();
initgraph(&gd,&gm,"c:tcbgi");
/*- draw object -*/
line (50,50,200,50);
line (200,50,200,300);
line (200,300,50,300);
line (50,300,50,50);
/*- set seed point -*/
x = 100; y = 100;
fill_right(x,y);
fill_left(x-1,y);
getch();
}
14 Clipping/fill algorithms
//C Program to Implement Flood Fill Algorithm
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
void fill_right(x,y)
int x , y ;
{
if(getpixel(x,y) == 0)
{
putpixel(x,y,RED);
fill_right(++x,y);
x = x - 1 ;
fill_right(x,y-1);
fill_right(x,y+1);
}
}
void fill_left(x,y)
int x , y ;
{
if(getpixel(x,y) == 0)
{
putpixel(x,y,RED);
fill_left(--x,y);
x = x + 1 ;
fill_left(x,y-1);
fill_left(x,y+1);
15 Clipping/fill algorithms
}
}
void main()
{
int x , y ,a[10][10];
int gd, gm ,n,i;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:tcbgi");
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];
printf("nntEnter the seed pt. : ");
scanf("%d%d",&x,&y);
cleardevice();
setcolor(WHITE);
for(i=0;i<n;i++) /*- draw poly -*/
{
16 Clipping/fill algorithms
line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]);
}
fill_right(x,y);
fill_left(x-1,y);
getch();
}
/*SAMPLE INPUT*/
/*Enter the number of edges of polygon 4
X0 Y0 = 50 50
X1 Y1 = 200 50
X2 Y2 = 200 300
X3 Y3 = 50 300
Enter the seed point 100 100*/

Contenu connexe

Tendances

2D Transformations(Computer Graphics)
2D Transformations(Computer Graphics)2D Transformations(Computer Graphics)
2D Transformations(Computer Graphics)AditiPatni3
 
3D Graphics & Rendering in Computer Graphics
3D Graphics & Rendering in Computer Graphics3D Graphics & Rendering in Computer Graphics
3D Graphics & Rendering in Computer GraphicsFaraz Akhtar
 
VTU 5TH SEM CSE COMPUTER NETWORKS-1 (DATA COMMUNICATION) SOLVED PAPERS
VTU 5TH SEM CSE COMPUTER NETWORKS-1 (DATA COMMUNICATION)  SOLVED PAPERSVTU 5TH SEM CSE COMPUTER NETWORKS-1 (DATA COMMUNICATION)  SOLVED PAPERS
VTU 5TH SEM CSE COMPUTER NETWORKS-1 (DATA COMMUNICATION) SOLVED PAPERSvtunotesbysree
 
Geographic Routing in WSN
Geographic Routing in WSNGeographic Routing in WSN
Geographic Routing in WSNMahbubur Rahman
 
Wireless transmission
Wireless transmissionWireless transmission
Wireless transmissionSaba Rathinam
 
Csma protocols
Csma protocolsCsma protocols
Csma protocolsManal Shah
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clippingMohd Arif
 
scan conversion of point , line and circle
scan conversion of point , line and circlescan conversion of point , line and circle
scan conversion of point , line and circleDivy Kumar Gupta
 
MEDIUM ACCESS CONTROL
MEDIUM ACCESS CONTROLMEDIUM ACCESS CONTROL
MEDIUM ACCESS CONTROLjunnubabu
 
Unit 1 introduction to computer networks
Unit 1  introduction to computer networksUnit 1  introduction to computer networks
Unit 1 introduction to computer networkspavan kumar Thatikonda
 
Two dimensional geometric transformations
Two dimensional geometric transformationsTwo dimensional geometric transformations
Two dimensional geometric transformationsMohammad Sadiq
 
TCP/IP Protocols With All Layer Description
TCP/IP Protocols With All Layer DescriptionTCP/IP Protocols With All Layer Description
TCP/IP Protocols With All Layer DescriptionShubham Khedekar
 
line attributes.pptx
line attributes.pptxline attributes.pptx
line attributes.pptxRubaNagarajan
 
Random scan displays and raster scan displays
Random scan displays and raster scan displaysRandom scan displays and raster scan displays
Random scan displays and raster scan displaysSomya Bagai
 

Tendances (20)

Depth Buffer Method
Depth Buffer MethodDepth Buffer Method
Depth Buffer Method
 
2D Transformations(Computer Graphics)
2D Transformations(Computer Graphics)2D Transformations(Computer Graphics)
2D Transformations(Computer Graphics)
 
3D Graphics & Rendering in Computer Graphics
3D Graphics & Rendering in Computer Graphics3D Graphics & Rendering in Computer Graphics
3D Graphics & Rendering in Computer Graphics
 
VTU 5TH SEM CSE COMPUTER NETWORKS-1 (DATA COMMUNICATION) SOLVED PAPERS
VTU 5TH SEM CSE COMPUTER NETWORKS-1 (DATA COMMUNICATION)  SOLVED PAPERSVTU 5TH SEM CSE COMPUTER NETWORKS-1 (DATA COMMUNICATION)  SOLVED PAPERS
VTU 5TH SEM CSE COMPUTER NETWORKS-1 (DATA COMMUNICATION) SOLVED PAPERS
 
Geographic Routing in WSN
Geographic Routing in WSNGeographic Routing in WSN
Geographic Routing in WSN
 
Wireless transmission
Wireless transmissionWireless transmission
Wireless transmission
 
Distributed Deadlock Detection.ppt
Distributed Deadlock Detection.pptDistributed Deadlock Detection.ppt
Distributed Deadlock Detection.ppt
 
Csma protocols
Csma protocolsCsma protocols
Csma protocols
 
IT6601 MOBILE COMPUTING
IT6601 MOBILE COMPUTINGIT6601 MOBILE COMPUTING
IT6601 MOBILE COMPUTING
 
Multiplexing
MultiplexingMultiplexing
Multiplexing
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clipping
 
scan conversion of point , line and circle
scan conversion of point , line and circlescan conversion of point , line and circle
scan conversion of point , line and circle
 
MEDIUM ACCESS CONTROL
MEDIUM ACCESS CONTROLMEDIUM ACCESS CONTROL
MEDIUM ACCESS CONTROL
 
Unix Cheat Sheet
Unix Cheat SheetUnix Cheat Sheet
Unix Cheat Sheet
 
Chapter 2 software process models
Chapter 2   software process modelsChapter 2   software process models
Chapter 2 software process models
 
Unit 1 introduction to computer networks
Unit 1  introduction to computer networksUnit 1  introduction to computer networks
Unit 1 introduction to computer networks
 
Two dimensional geometric transformations
Two dimensional geometric transformationsTwo dimensional geometric transformations
Two dimensional geometric transformations
 
TCP/IP Protocols With All Layer Description
TCP/IP Protocols With All Layer DescriptionTCP/IP Protocols With All Layer Description
TCP/IP Protocols With All Layer Description
 
line attributes.pptx
line attributes.pptxline attributes.pptx
line attributes.pptx
 
Random scan displays and raster scan displays
Random scan displays and raster scan displaysRandom scan displays and raster scan displays
Random scan displays and raster scan displays
 

En vedette

Computer Graphics Programes
Computer Graphics ProgramesComputer Graphics Programes
Computer Graphics ProgramesAbhishek Sharma
 
SE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of PuneSE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of PuneBhavesh Shah
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics labPriya Goyal
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsKandarp Tiwari
 
Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics PracticalNeha Sharma
 
Lecture 2d point,curve,text,line clipping
Lecture   2d point,curve,text,line clippingLecture   2d point,curve,text,line clipping
Lecture 2d point,curve,text,line clippingavelraj
 
Developing a research Library position statement on Text and Data Mining in t...
Developing a research Library position statement on Text and Data Mining in t...Developing a research Library position statement on Text and Data Mining in t...
Developing a research Library position statement on Text and Data Mining in t...Danny Kingsley
 
Writing thesis chapters 1-3 guidelines
Writing thesis chapters 1-3 guidelinesWriting thesis chapters 1-3 guidelines
Writing thesis chapters 1-3 guidelinespoleyseugenio
 

En vedette (10)

Computer Graphics Programes
Computer Graphics ProgramesComputer Graphics Programes
Computer Graphics Programes
 
SE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of PuneSE Computer, Programming Laboratory(210251) University of Pune
SE Computer, Programming Laboratory(210251) University of Pune
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics lab
 
Graphics Programming in C
Graphics Programming in CGraphics Programming in C
Graphics Programming in C
 
Introduction to graphics programming in c
Introduction to graphics programming in cIntroduction to graphics programming in c
Introduction to graphics programming in c
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
 
Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics Practical
 
Lecture 2d point,curve,text,line clipping
Lecture   2d point,curve,text,line clippingLecture   2d point,curve,text,line clipping
Lecture 2d point,curve,text,line clipping
 
Developing a research Library position statement on Text and Data Mining in t...
Developing a research Library position statement on Text and Data Mining in t...Developing a research Library position statement on Text and Data Mining in t...
Developing a research Library position statement on Text and Data Mining in t...
 
Writing thesis chapters 1-3 guidelines
Writing thesis chapters 1-3 guidelinesWriting thesis chapters 1-3 guidelines
Writing thesis chapters 1-3 guidelines
 

Similaire à Graphics point clipping c program

Cg my own programs
Cg my own programsCg my own programs
Cg my own programsAmit Kapoor
 
Computer graphics File for Engineers
Computer graphics File for EngineersComputer graphics File for Engineers
Computer graphics File for Engineersvarun arora
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignmentAbdullah Al Shiam
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualUma mohan
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++Ankit Kumar
 
Numerical Methods in C
Numerical Methods in CNumerical Methods in C
Numerical Methods in CAmbili Baby
 
1. Translation program#includestdio.h#includeconio.h#incl.pdf
1. Translation program#includestdio.h#includeconio.h#incl.pdf1. Translation program#includestdio.h#includeconio.h#incl.pdf
1. Translation program#includestdio.h#includeconio.h#incl.pdfsutharbharat59
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C CodeSyed Ahmed Zaki
 
Program to reflecta triangle
Program to reflecta triangleProgram to reflecta triangle
Program to reflecta triangleTanya Makkar
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graphkinan keshkeh
 
Runge kutta C programme
Runge kutta C programmeRunge kutta C programme
Runge kutta C programmeShah Keval
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignmentashikul akash
 
C tech questions
C tech questionsC tech questions
C tech questionsvijay00791
 
Program for pyramid
Program for pyramidProgram for pyramid
Program for pyramidnayakq
 

Similaire à Graphics point clipping c program (20)

Cg my own programs
Cg my own programsCg my own programs
Cg my own programs
 
Computer graphics File for Engineers
Computer graphics File for EngineersComputer graphics File for Engineers
Computer graphics File for Engineers
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignment
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++
 
Numerical Methods in C
Numerical Methods in CNumerical Methods in C
Numerical Methods in C
 
1. Translation program#includestdio.h#includeconio.h#incl.pdf
1. Translation program#includestdio.h#includeconio.h#incl.pdf1. Translation program#includestdio.h#includeconio.h#incl.pdf
1. Translation program#includestdio.h#includeconio.h#incl.pdf
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
 
Program to reflecta triangle
Program to reflecta triangleProgram to reflecta triangle
Program to reflecta triangle
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
Runge kutta C programme
Runge kutta C programmeRunge kutta C programme
Runge kutta C programme
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignment
 
C tech questions
C tech questionsC tech questions
C tech questions
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
Program for pyramid
Program for pyramidProgram for pyramid
Program for pyramid
 

Plus de Dr.M.Karthika parthasarathy

IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...
IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...
IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...Dr.M.Karthika parthasarathy
 
Unit 1 Introduction to Artificial Intelligence.pptx
Unit 1 Introduction to Artificial Intelligence.pptxUnit 1 Introduction to Artificial Intelligence.pptx
Unit 1 Introduction to Artificial Intelligence.pptxDr.M.Karthika parthasarathy
 

Plus de Dr.M.Karthika parthasarathy (20)

IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...
IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...
IoT Enabled Wireless Technology Based Monitoring and Speed Control of Motor U...
 
Linux Lab Manual.doc
Linux Lab Manual.docLinux Lab Manual.doc
Linux Lab Manual.doc
 
Unit 2 IoT.pdf
Unit 2 IoT.pdfUnit 2 IoT.pdf
Unit 2 IoT.pdf
 
Unit 3 IOT.docx
Unit 3 IOT.docxUnit 3 IOT.docx
Unit 3 IOT.docx
 
Unit 1 Introduction to Artificial Intelligence.pptx
Unit 1 Introduction to Artificial Intelligence.pptxUnit 1 Introduction to Artificial Intelligence.pptx
Unit 1 Introduction to Artificial Intelligence.pptx
 
Unit I What is Artificial Intelligence.docx
Unit I What is Artificial Intelligence.docxUnit I What is Artificial Intelligence.docx
Unit I What is Artificial Intelligence.docx
 
Introduction to IoT - Unit II.pptx
Introduction to IoT - Unit II.pptxIntroduction to IoT - Unit II.pptx
Introduction to IoT - Unit II.pptx
 
IoT Unit 2.pdf
IoT Unit 2.pdfIoT Unit 2.pdf
IoT Unit 2.pdf
 
Chapter 3 heuristic search techniques
Chapter 3 heuristic search techniquesChapter 3 heuristic search techniques
Chapter 3 heuristic search techniques
 
Ai mcq chapter 2
Ai mcq chapter 2Ai mcq chapter 2
Ai mcq chapter 2
 
Introduction to IoT unit II
Introduction to IoT  unit IIIntroduction to IoT  unit II
Introduction to IoT unit II
 
Introduction to IoT - Unit I
Introduction to IoT - Unit IIntroduction to IoT - Unit I
Introduction to IoT - Unit I
 
Internet of things Unit 1 one word
Internet of things Unit 1 one wordInternet of things Unit 1 one word
Internet of things Unit 1 one word
 
Unit 1 q&amp;a
Unit  1 q&amp;aUnit  1 q&amp;a
Unit 1 q&amp;a
 
Overview of Deadlock unit 3 part 1
Overview of Deadlock unit 3 part 1Overview of Deadlock unit 3 part 1
Overview of Deadlock unit 3 part 1
 
Examples in OS synchronization for UG
Examples in OS synchronization for UG Examples in OS synchronization for UG
Examples in OS synchronization for UG
 
Process Synchronization - Monitors
Process Synchronization - MonitorsProcess Synchronization - Monitors
Process Synchronization - Monitors
 
.net progrmming part4
.net progrmming part4.net progrmming part4
.net progrmming part4
 
.net progrmming part3
.net progrmming part3.net progrmming part3
.net progrmming part3
 
.net progrmming part1
.net progrmming part1.net progrmming part1
.net progrmming part1
 

Dernier

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 

Dernier (20)

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 

Graphics point clipping c program

  • 1. 1 Clipping/fill algorithms //Graphics Point Clipping C Program #include<stdio.h> #include<conio.h> #include<graphics.h> int tlx,tly,brx,bry,px,py; void point_clip() { int wxmin,wymin,wxmax,wymax; wxmin=tlx; wxmax=brx; wymin=tly; wymax=bry; if(px>=wxmin&&px<=wxmax) if(py>=wymin&&py<=wymax) putpixel(px,py,RED); getch(); closegraph(); } void main(void) { int gd=DETECT,gm,xc,yc,r; clrscr(); printf("Enter the top left coordinate"); scanf("%d%d",&tlx,&tly); printf("Enter the bottom right coordinate"); scanf("%d%d",&brx,&bry); printf("n Enter the point"); scanf("%d%d",&px,&py); initgraph(&gd,&gm,"c:tcbgi"); /*Sometimes it may be "C:TCBGI" , It depends machine to mac..*/ setbkcolor(YELLOW); setcolor(RED); rectangle(tlx,tly,brx,bry); point_clip(); }
  • 2. 2 Clipping/fill algorithms //Sutherland-Hodgeman Polygon clipping Algorithm #include<stdio.h> #include<conio.h> #include<graphics.h> #include<math.h> void clip(float,float,float); int i,j=0,n; int rx1,rx2,ry1,ry2; float x1[8],y1[8]; void main() { int gd=DETECT,gm; int i,n; float x[8],y[8],m; clrscr(); initgraph(&gd,&gm,""); printf("coordinates for rectangle : "); scanf("%d%d%d%d",&rx1,&ry1,&rx2,&ry2); printf("no. of sides for polygon : "); scanf("%d",&n); printf("coordinates : "); for(i=0;i<n;i++) { scanf("%f%f",&x[i],&y[i]); } cleardevice(); outtextxy(10,10,"Before clipping"); outtextxy(10,470,"Press any key...."); rectangle(rx1,ry1,rx2,ry2); for(i=0;i<n-1;i++) line(x[i],y[i],x[i+1],y[i+1]); line(x[i],y[i],x[0],y[0]); getch(); cleardevice();
  • 3. 3 Clipping/fill algorithms for(i=0;i<n-1;i++) { m=(y[i+1]-y[i])/(x[i+1]-x[i]); clip(x[i],y[i],m); } clip(x[0],y[0],m); outtextxy(10,10,"After clipping"); outtextxy(10,470,"Press any key...."); rectangle(rx1,ry1,rx2,ry2); for(i=0;i<j-1;i++) line(x1[i],y1[i],x1[i+1],y1[i+1]); getch(); } void clip(float e,float f,float m) { while(e<rx1 e>rx2 f<ry1 f>ry2) { if(e<rx1) { f+=m*(rx1-e); e=rx1; } else if(e>rx2) { f+=m*(rx2-e); e=rx1; } if(f<ry1) { e+=(ry1-f)/m; f=ry1; } else if(f>ry2)
  • 4. 4 Clipping/fill algorithms { e+=(ry2-f)/m; f=ry2; } x1[j]=e; y1[j]=f; j++; } } OUTPUT Enter the x1 & y1 coordinates: X1 : 70 Y1 : 80 Enter the x2 & y2 coordinates: X2 : 250 Y2 : 280
  • 5. 5 Clipping/fill algorithms //polygon clipping #include<graphics.h> #include<dos.h> #include<conio.h> #include<stdlib.h> void main() { int gd, gm ; int x1 , y1 , x2 , y2 ; int wxmin,wymin,wxmax, wymax ; float u1 = 0.0,u2 = 1.0 ; int p1 , q1 , p2 , q2 , p3 , q3 , p4 ,q4 ; float r1 , r2 , r3 , r4 ; int x11 , y11 , x22 , y22 ; clrscr(); printf("Enter the windows left xmin , top boundry yminn"); scanf("%d%d",&wxmin,&wymin); printf("Enter the windows right xmax ,bottom boundry ymaxn"); scanf("%d%d",&wxmax,&wymax); printf("Enter line x1 , y1 co-ordinaten"); scanf("%d%d",&x1,&y1); printf("Enter line x2 , y2 co-ordinaten"); scanf("%d%d",&x2,&y2); printf("liang barsky express these 4 inequalities using lpk<=qpkn"); p1 = -(x2 - x1 ); q1 = x1 - wxmin ; p2 = ( x2 - x1 ) ; q2 = wxmax - x1 ; p3 = - ( y2 - y1 ) ; q3 = y1 - wymin ;
  • 6. 6 Clipping/fill algorithms p4 = ( y2 - y1 ) ; q4 = wymax - y1 ; printf("p1=0 line is parallel to left clippingn"); printf("p2=0 line is parallel to right clippingn"); printf("p3=0 line is parallel to bottom clippingn"); printf("p4=0 line is parallel to top clippingn"); if( ( ( p1 == 0.0 ) && ( q1 < 0.0 ) ) || ( ( p2 == 0.0 ) && ( q2 < 0.0 ) ) || ( ( p3 == 0.0 ) && ( q3 < 0.0 ) ) || ( ( p4 == 0.0 ) && ( q4 < 0.0 ) ) ) { printf("Line is rejectedn"); getch(); detectgraph(&gd,&gm); initgraph(&gd,&gm,"c:tcbgi"); setcolor(RED); rectangle(wxmin,wymax,wxmax,wymin); setcolor(BLUE); line(x1,y1,x2,y2); getch(); setcolor(WHITE); line(x1,y1,x2,y2); getch(); } else { if( p1 != 0.0 ) { r1 =(float) q1 /p1 ; if( p1 < 0 ) u1 = max(r1 , u1 );
  • 7. 7 Clipping/fill algorithms else u2 = min(r1 , u2 ); } if( p2 != 0.0 ) { r2 = (float ) q2 /p2 ; if( p2 < 0 ) u1 = max(r2 , u1 ); else u2 = min(r2 , u2 ); } if( p3 != 0.0 ) { r3 = (float )q3 /p3 ; if( p3 < 0 ) u1 = max(r3 , u1 ); else u2 = min(r3 , u2 ); } if( p4 != 0.0 ) { r4 = (float )q4 /p4 ; if( p4 < 0 ) u1 = max(r4 , u1 ); else u2 = min(r4 , u2 ); } if( u1 > u2 ) printf("line rejectedn"); else
  • 8. 8 Clipping/fill algorithms { x11 = x1 + u1 * ( x2 - x1 ) ; y11 = y1 + u1 * ( y2 - y1 ) ; x22 = x1 + u2 * ( x2 - x1 ); y22 = y1 + u2 * ( y2 - y1 ); printf("Original line cordinatesn"); printf("x1 = %d , y1 = %d, x2 = %d, y2 = %dn",x1,y1,x2,y2); printf("Windows coordinate are n"); printf("wxmin = %d, wymin = %d,wxmax = %d , wymax = %d ",wxmin,wymin,wxmax,wymax); printf("New coordinates are n"); printf("x1 = %d, y1 = %d,x2 = %d , y2 = %dn",x11,y11,x22,y22); detectgraph(&gd,&gm); initgraph(&gd,&gm,"C:TCBGI"); setcolor(2); rectangle(wxmin,wymax,wxmax,wymin); setcolor(1); line(x1,y1,x2,y2); getch(); setcolor(0); line(x1,y1,x2,y2); setcolor(3); line(x11,y11,x22,y22); getch(); } } }
  • 9. 9 Clipping/fill algorithms //C Program For Oblique projection of a 3D object #include<stdio.h> #include<math.h> #include<graphics.h> main() { int x1,y1,x2,y2,gd,gm; int ymax,a[4][8]; float par[4][4],b[4][8]; int i,j,k,m,n,p; double L1,phi; a[0][0] = 100; a[1][0] = 100; a[2][0] = 100; a[0][1] = 200; a[1][1] = 100; a[2][1] = 100; a[0][2] = 200; a[1][2] = 200; a[2][2] = 100; a[0][3] = 100; a[1][3] = 200; a[2][3] = 100; a[0][4] = 100; a[1][4] = 100; a[2][4] = 200; a[0][5] = 200; a[1][5] = 100; a[2][5] = 200; a[0][6] = 200; a[1][6] = 200; a[2][6] = 200; a[0][7] = 100; a[1][7] = 200; a[2][7] = 200; phi = (double) (3.14*45.0)/180 ; L1 = 0.5; par[0][0] = 1; par[0][1] = 0; par[0][2] = L1*cos(phi); par[0][3] = 0;
  • 10. 10 Clipping/fill algorithms par[1][0] = 0; par[1][1] = 1; par[1][2] = L1*sin(phi); par[1][3] = 0; par[2][0] = 0; par[2][1] = 0; par[2][2] = 0; par[2][3] = 0; par[3][0] = 0; par[3][1] = 0; par[3][2] = 0; par[3][3] = 1; m=4; n=4; p=8; for(i=0; i<m; i++) for(k=0; k<p; k++) b[i][k] = 0; for(i=0; i<m; i++) for(k=0; k<p; k++) for(j=0; j<n; j++) b[i][k] += (float)par[i][j] * a[j][k]; detectgraph(&gd,&gm); initgraph(&gd,&gm, "c:tcbgi"); ymax = getmaxy(); /*- front plane display -*/ for(j=0;j<3;j++) { x1=(int) b[0][j]; y1=(int) b[1][j]; x2=(int) b[0][j+1]; y2=(int) b[1][j+1]; line( x1,ymax-y1,x2,ymax-y2);
  • 11. 11 Clipping/fill algorithms } x1=(int) b[0][3]; y1=(int) b[1][3]; x2=(int) b[0][0]; y2=(int) b[1][0]; line( x1,ymax-y1,x2,ymax-y2); /*- back plane display -*/ setcolor(11); for(j=4;j<7;j++) { x1=(int) b[0][j]; y1=(int) b[1][j]; x2=(int) b[0][j+1]; y2=(int) b[1][j+1]; line( x1,ymax-y1,x2,ymax-y2); } x1=(int) b[0][7]; y1=(int) b[1][7]; x2=(int) b[0][4]; y2=(int) b[1][4]; line( x1,ymax-y1,x2,ymax-y2); setcolor(13); for(i=0;i<4;i++) { x1=(int) b[0][i]; y1=(int) b[1][i]; x2=(int) b[0][4+i]; y2=(int) b[1][4+i]; line( x1,ymax-y1,x2,ymax-y2); } getch(); getch(); }
  • 12. 12 Clipping/fill algorithms C Program to implement Boundary Fill Algorithm #include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> void fill_right(x,y) int x , y ; { if((getpixel(x,y) != WHITE)&&(getpixel(x,y) != RED)) { putpixel(x,y,RED); fill_right(++x,y); x = x - 1 ; fill_right(x,y-1); fill_right(x,y+1); } delay(1); } void fill_left(x,y) int x , y ; { if((getpixel(x,y) != WHITE)&&(getpixel(x,y) != RED)) { putpixel(x,y,RED); fill_left(--x,y); x = x + 1 ; fill_left(x,y-1);
  • 13. 13 Clipping/fill algorithms fill_left(x,y+1); } delay(1); } void main() { int x,y,n,i; int gd=DETECT,gm; clrscr(); initgraph(&gd,&gm,"c:tcbgi"); /*- draw object -*/ line (50,50,200,50); line (200,50,200,300); line (200,300,50,300); line (50,300,50,50); /*- set seed point -*/ x = 100; y = 100; fill_right(x,y); fill_left(x-1,y); getch(); }
  • 14. 14 Clipping/fill algorithms //C Program to Implement Flood Fill Algorithm #include<conio.h> #include<stdio.h> #include<graphics.h> #include<dos.h> void fill_right(x,y) int x , y ; { if(getpixel(x,y) == 0) { putpixel(x,y,RED); fill_right(++x,y); x = x - 1 ; fill_right(x,y-1); fill_right(x,y+1); } } void fill_left(x,y) int x , y ; { if(getpixel(x,y) == 0) { putpixel(x,y,RED); fill_left(--x,y); x = x + 1 ; fill_left(x,y-1); fill_left(x,y+1);
  • 15. 15 Clipping/fill algorithms } } void main() { int x , y ,a[10][10]; int gd, gm ,n,i; detectgraph(&gd,&gm); initgraph(&gd,&gm,"c:tcbgi"); 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]; printf("nntEnter the seed pt. : "); scanf("%d%d",&x,&y); cleardevice(); setcolor(WHITE); for(i=0;i<n;i++) /*- draw poly -*/ {
  • 16. 16 Clipping/fill algorithms line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]); } fill_right(x,y); fill_left(x-1,y); getch(); } /*SAMPLE INPUT*/ /*Enter the number of edges of polygon 4 X0 Y0 = 50 50 X1 Y1 = 200 50 X2 Y2 = 200 300 X3 Y3 = 50 300 Enter the seed point 100 100*/