14 23203a0061pdf
14 23203a0061pdf
ENGINEERING
Experiment No 14
Title of Experiment Write a C program for Sutherland Hodgeman Polygon Clipping.
PROGRAM:-
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<math.h>
void bytecode();
void sutherland();
m,xnew,ynew;
float xl = 100, yl = 100, xh = 300, yh = 300,xa =350,ya = 150,xb = 250, yb = 150; void
main()
int gd = DETECT,gm;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
setcolor(5);
line(xa,ya,xb,yb); setcolor(12);
bytecode();
sutherland(); getch();
void bytecode()
a[3] = 0;
if(xa>xh) //10>300
a[2] = 0;
a[1] = 0;
a[0] = 0;
b[3] = 1; //0
else
b[3] = 0;
if(xb>xh) //250>300
b[2] = 0;
else b[1] = 0;
else b[0] = 0;
void sutherland()
getch();
if(a[0] == 0 && a[1] == 0 && a[2] == 0 && a[3] == 0 && b[0] == 0 && b[1] == 0
&& b[2] == 0 && b[3] == 0 )
printf("no clipping");
line(xa,ya,xb,yb);
clrscr();
printf("line discarded");
rectangle(xl,yl,xh,yh);
else
setcolor(12);
rectangle(xl,yl,xh,yh);
setcolor(0);
line(xa,ya,xb,yb); setcolor(15);
line(xl,ynew,xb,yb);
setcolor(12);
rectangle(xl,yl,xh,yh);
setcolor(0);
line(xa,ya,xb,yb); setcolor(15);
line(xh,ynew,xb,yb);
xnew = xa + (yl-ya)/m;
setcolor(0);
line(xa,ya,xb,yb); setcolor(15);
line(xnew,yh,xb,yb);
xnew = xa + (yh-ya)/m;
setcolor(0);
line(xa,ya,xb,yb); setcolor(15);
line(xnew,yh,xb,yb);
}
}
OUTPUT:-
EXERCISE:-
1. Clip the following polygon using Sutherland Hodgeman Polygon Clipping
algorithm.
1. If the first vertex is outside the clipping window and second point is inside the
clipping window, then write which points are added to output vertex list.
When clipping a line segment where the first vertex is outside the clipping window and the
second vertex is inside, the output vertex list will contain the following points:
Intersection Point: This is the point where the line segment intersects with the
boundary of the clipping window.
Second Vertex (Inside Point): This is the second endpoint of the line segment that
is inside the clipping window.
In essence, the output will consist of these two points, allowing for the clipped line segment
to be properly represented within the bounds of the clipping window.