SlideShare a Scribd company logo
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*/
Ad

More Related Content

What's hot (20)

2.Problems Problem Spaces and Search.ppt
2.Problems Problem Spaces and Search.ppt2.Problems Problem Spaces and Search.ppt
2.Problems Problem Spaces and Search.ppt
Dr. Naushad Varish
 
Rehashing
RehashingRehashing
Rehashing
rajshreemuthiah
 
Object oriented-systems-development-life-cycle ppt
Object oriented-systems-development-life-cycle pptObject oriented-systems-development-life-cycle ppt
Object oriented-systems-development-life-cycle ppt
Kunal Kishor Nirala
 
Data warehouse physical design
Data warehouse physical designData warehouse physical design
Data warehouse physical design
Er. Nawaraj Bhandari
 
First and follow set
First and follow setFirst and follow set
First and follow set
Dawood Faheem Abbasi
 
Lecture 06 production system
Lecture 06 production systemLecture 06 production system
Lecture 06 production system
Hema Kashyap
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
Akshaya Arunan
 
Code generation
Code generationCode generation
Code generation
Aparna Nayak
 
Distributed DBMS - Unit 6 - Query Processing
Distributed DBMS - Unit 6 - Query ProcessingDistributed DBMS - Unit 6 - Query Processing
Distributed DBMS - Unit 6 - Query Processing
Gyanmanjari Institute Of Technology
 
Selfish thread
Selfish threadSelfish thread
Selfish thread
अङ्किता त्रिपाठी
 
Control Strategies in AI
Control Strategies in AIControl Strategies in AI
Control Strategies in AI
Amey Kerkar
 
Water jug problem ai part 6
Water jug problem ai part 6Water jug problem ai part 6
Water jug problem ai part 6
Kirti Verma
 
Closest pair problems (Divide and Conquer)
Closest pair problems (Divide and Conquer)Closest pair problems (Divide and Conquer)
Closest pair problems (Divide and Conquer)
Gem WeBlog
 
Eucalyptus: Open Source for Cloud Computing
Eucalyptus: Open Source for Cloud ComputingEucalyptus: Open Source for Cloud Computing
Eucalyptus: Open Source for Cloud Computing
clive boulton
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysis
raosir123
 
Database ,7 query localization
Database ,7 query localizationDatabase ,7 query localization
Database ,7 query localization
Ali Usman
 
Processes in unix
Processes in unixProcesses in unix
Processes in unix
miau_max
 
Hash table
Hash tableHash table
Hash table
Rajendran
 
Simulation-Language.pptx
Simulation-Language.pptxSimulation-Language.pptx
Simulation-Language.pptx
skknowledge
 
Binary Search Tree (BST)
Binary Search Tree (BST)Binary Search Tree (BST)
Binary Search Tree (BST)
M Sajid R
 
2.Problems Problem Spaces and Search.ppt
2.Problems Problem Spaces and Search.ppt2.Problems Problem Spaces and Search.ppt
2.Problems Problem Spaces and Search.ppt
Dr. Naushad Varish
 
Object oriented-systems-development-life-cycle ppt
Object oriented-systems-development-life-cycle pptObject oriented-systems-development-life-cycle ppt
Object oriented-systems-development-life-cycle ppt
Kunal Kishor Nirala
 
Lecture 06 production system
Lecture 06 production systemLecture 06 production system
Lecture 06 production system
Hema Kashyap
 
Control Strategies in AI
Control Strategies in AIControl Strategies in AI
Control Strategies in AI
Amey Kerkar
 
Water jug problem ai part 6
Water jug problem ai part 6Water jug problem ai part 6
Water jug problem ai part 6
Kirti Verma
 
Closest pair problems (Divide and Conquer)
Closest pair problems (Divide and Conquer)Closest pair problems (Divide and Conquer)
Closest pair problems (Divide and Conquer)
Gem WeBlog
 
Eucalyptus: Open Source for Cloud Computing
Eucalyptus: Open Source for Cloud ComputingEucalyptus: Open Source for Cloud Computing
Eucalyptus: Open Source for Cloud Computing
clive boulton
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysis
raosir123
 
Database ,7 query localization
Database ,7 query localizationDatabase ,7 query localization
Database ,7 query localization
Ali Usman
 
Processes in unix
Processes in unixProcesses in unix
Processes in unix
miau_max
 
Simulation-Language.pptx
Simulation-Language.pptxSimulation-Language.pptx
Simulation-Language.pptx
skknowledge
 
Binary Search Tree (BST)
Binary Search Tree (BST)Binary Search Tree (BST)
Binary Search Tree (BST)
M Sajid R
 

Viewers also liked (10)

Computer Graphics Programes
Computer Graphics ProgramesComputer Graphics Programes
Computer Graphics Programes
Abhishek 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 Pune
Bhavesh Shah
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics lab
Priya Goyal
 
Graphics Programming in C
Graphics Programming in CGraphics Programming in C
Graphics Programming in C
Kasun Ranga Wijeweera
 
Introduction to graphics programming in c
Introduction to graphics programming in cIntroduction to graphics programming in c
Introduction to graphics programming in c
baabtra.com - No. 1 supplier of quality freshers
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
Kandarp Tiwari
 
Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics Practical
Neha 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 clipping
avelraj
 
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 guidelines
poleyseugenio
 
Computer Graphics Programes
Computer Graphics ProgramesComputer Graphics Programes
Computer Graphics Programes
Abhishek 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 Pune
Bhavesh Shah
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics lab
Priya Goyal
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
Kandarp Tiwari
 
Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics Practical
Neha 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 clipping
avelraj
 
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 guidelines
poleyseugenio
 
Ad

Similar to Graphics point clipping c program (20)

Cg my own programs
Cg my own programsCg my own programs
Cg my own programs
Amit Kapoor
 
Computer graphics File for Engineers
Computer graphics File for EngineersComputer graphics File for Engineers
Computer graphics File for Engineers
varun arora
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignment
Abdullah Al Shiam
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
manoj11manu
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
Uma mohan
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
Prianka Padmanaban
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
Prianka Padmanaban
 
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 C
Ambili 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.pdf
sutharbharat59
 
Cpds lab
Cpds labCpds lab
Cpds lab
praveennallavelly08
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
Syed Ahmed Zaki
 
Program to reflecta triangle
Program to reflecta triangleProgram to reflecta triangle
Program to reflecta triangle
Tanya Makkar
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph
kinan keshkeh
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
Lakshmi Sarvani Videla
 
Runge kutta C programme
Runge kutta C programmeRunge kutta C programme
Runge kutta C programme
Shah Keval
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignment
ashikul akash
 
C tech questions
C tech questionsC tech questions
C tech questions
vijay00791
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
Nithin Kumar,VVCE, Mysuru
 
Program for pyramid
Program for pyramidProgram for pyramid
Program for pyramid
nayakq
 
Cg my own programs
Cg my own programsCg my own programs
Cg my own programs
Amit Kapoor
 
Computer graphics File for Engineers
Computer graphics File for EngineersComputer graphics File for Engineers
Computer graphics File for Engineers
varun arora
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignment
Abdullah Al Shiam
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
Uma 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 C
Ambili 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.pdf
sutharbharat59
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
Syed Ahmed Zaki
 
Program to reflecta triangle
Program to reflecta triangleProgram to reflecta triangle
Program to reflecta triangle
Tanya Makkar
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph
kinan keshkeh
 
Runge kutta C programme
Runge kutta C programmeRunge kutta C programme
Runge kutta C programme
Shah Keval
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignment
ashikul akash
 
C tech questions
C tech questionsC tech questions
C tech questions
vijay00791
 
Program for pyramid
Program for pyramidProgram for pyramid
Program for pyramid
nayakq
 
Ad

More from 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...
Dr.M.Karthika parthasarathy
 
Linux Lab Manual.doc
Linux Lab Manual.docLinux Lab Manual.doc
Linux Lab Manual.doc
Dr.M.Karthika parthasarathy
 
Unit 2 IoT.pdf
Unit 2 IoT.pdfUnit 2 IoT.pdf
Unit 2 IoT.pdf
Dr.M.Karthika parthasarathy
 
Unit 3 IOT.docx
Unit 3 IOT.docxUnit 3 IOT.docx
Unit 3 IOT.docx
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.pptx
Dr.M.Karthika parthasarathy
 
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
Dr.M.Karthika parthasarathy
 
Introduction to IoT - Unit II.pptx
Introduction to IoT - Unit II.pptxIntroduction to IoT - Unit II.pptx
Introduction to IoT - Unit II.pptx
Dr.M.Karthika parthasarathy
 
IoT Unit 2.pdf
IoT Unit 2.pdfIoT Unit 2.pdf
IoT Unit 2.pdf
Dr.M.Karthika parthasarathy
 
Chapter 3 heuristic search techniques
Chapter 3 heuristic search techniquesChapter 3 heuristic search techniques
Chapter 3 heuristic search techniques
Dr.M.Karthika parthasarathy
 
Ai mcq chapter 2
Ai mcq chapter 2Ai mcq chapter 2
Ai mcq chapter 2
Dr.M.Karthika parthasarathy
 
Introduction to IoT unit II
Introduction to IoT  unit IIIntroduction to IoT  unit II
Introduction to IoT unit II
Dr.M.Karthika parthasarathy
 
Introduction to IoT - Unit I
Introduction to IoT - Unit IIntroduction to IoT - Unit I
Introduction to IoT - Unit I
Dr.M.Karthika parthasarathy
 
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
Dr.M.Karthika parthasarathy
 
Unit 1 q&amp;a
Unit  1 q&amp;aUnit  1 q&amp;a
Unit 1 q&amp;a
Dr.M.Karthika parthasarathy
 
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
Dr.M.Karthika parthasarathy
 
Examples in OS synchronization for UG
Examples in OS synchronization for UG Examples in OS synchronization for UG
Examples in OS synchronization for UG
Dr.M.Karthika parthasarathy
 
Process Synchronization - Monitors
Process Synchronization - MonitorsProcess Synchronization - Monitors
Process Synchronization - Monitors
Dr.M.Karthika parthasarathy
 
.net progrmming part4
.net progrmming part4.net progrmming part4
.net progrmming part4
Dr.M.Karthika parthasarathy
 
.net progrmming part3
.net progrmming part3.net progrmming part3
.net progrmming part3
Dr.M.Karthika parthasarathy
 
.net progrmming part1
.net progrmming part1.net progrmming part1
.net progrmming part1
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.pptx
Dr.M.Karthika parthasarathy
 

Recently uploaded (20)

How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
libbys peer assesment.docx..............
libbys peer assesment.docx..............libbys peer assesment.docx..............
libbys peer assesment.docx..............
19lburrell
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
INSULIN.pptx by Arka Das (Bsc. Critical care technology)
INSULIN.pptx by Arka Das (Bsc. Critical care technology)INSULIN.pptx by Arka Das (Bsc. Critical care technology)
INSULIN.pptx by Arka Das (Bsc. Critical care technology)
ArkaDas54
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
How to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 WebsiteHow to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 Website
Celine George
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
GENERAL QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 4 MARCH 2025 .pdf
GENERAL QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 4 MARCH 2025 .pdfGENERAL QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 4 MARCH 2025 .pdf
GENERAL QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 4 MARCH 2025 .pdf
Quiz Club of PSG College of Arts & Science
 
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptxUnit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Mayuri Chavan
 
COPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDFCOPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDF
SONU HEETSON
 
How to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo SlidesHow to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo Slides
Celine George
 
How to Manage Manual Reordering Rule in Odoo 18 Inventory
How to Manage Manual Reordering Rule in Odoo 18 InventoryHow to Manage Manual Reordering Rule in Odoo 18 Inventory
How to Manage Manual Reordering Rule in Odoo 18 Inventory
Celine George
 
IMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERS
IMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERSIMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERS
IMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERS
rajaselviazhagiri1
 
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFAMCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
libbys peer assesment.docx..............
libbys peer assesment.docx..............libbys peer assesment.docx..............
libbys peer assesment.docx..............
19lburrell
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
INSULIN.pptx by Arka Das (Bsc. Critical care technology)
INSULIN.pptx by Arka Das (Bsc. Critical care technology)INSULIN.pptx by Arka Das (Bsc. Critical care technology)
INSULIN.pptx by Arka Das (Bsc. Critical care technology)
ArkaDas54
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
How to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 WebsiteHow to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 Website
Celine George
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptxUnit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Mayuri Chavan
 
COPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDFCOPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDF
SONU HEETSON
 
How to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo SlidesHow to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo Slides
Celine George
 
How to Manage Manual Reordering Rule in Odoo 18 Inventory
How to Manage Manual Reordering Rule in Odoo 18 InventoryHow to Manage Manual Reordering Rule in Odoo 18 Inventory
How to Manage Manual Reordering Rule in Odoo 18 Inventory
Celine George
 
IMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERS
IMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERSIMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERS
IMPACT_OF_SOCIAL-MEDIA- AMONG- TEENAGERS
rajaselviazhagiri1
 
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFAMCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
MCQS (EMERGENCY NURSING) DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 

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*/
  翻译: