To write a C program to Implement Point clipping

Algorithm step by step Procedure
1. Get the minimum and maximum coordinates of both window and view port.
2. Get the coordinates for a point.
3. Check whether given input lies between minimum and maximum coordinate of a window.
4. If yes display a point which lies inside the region code window otherwise discard it.
Source Code Programming in C
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gm,gr,xcmin,ycmin,xcmax,ycmax,x,y,c;
clrscr();
detectgraph(&gm,&gr);
initgraph(&gm,&gr,"d:\\tc\\BGI");
printf("Enter the clipmin coordinate :\n");
scanf("%d%d",&xcmin,&ycmin);
printf("Enter the clipmax coordinate :\n");
scanf("%d%d",&xcmax,&ycmax);
rectangle(xcmin,ycmax,xcmax,ycmin);
printf("Enter the coordinate of the point:\n");
scanf("%d%d",&x,&y);
detectgraph(&gm,&gr);
initgraph(&gm,&gr,"d:\\tc\\BGI");
putpixel(x,y,15);
printf("\n1.Point clipping\n2.Exit\nEnter your choice:\n");
scanf("%d",&c);
switch(c)
{
case 1:
detectgraph(&gm,&gr);
initgraph(&gm,&gr,"d:\\tc\\BGI");
rectangle(xcmin,ycmax,xcmax,ycmin);
printf("*******POINT CLIPPING******\n");
if((xcmin<x) && (x<xcmax))
{
if((ycmin<y) && (y<ycmax))
{
printf("The point is inside the clip window\n");
putpixel(x,y,15);
}
}
else
printf("The point is outside the clipwindow \nThe point is clipped\n");
break;
case 2:
exit(0);
}
getch();
}
OUTPUT
Enter the clipmin coordinate :
200
200
Enter the clipmax coordinate :
300
300
Enter the coordinate of the point:
250
250
1.Point clipping
2.Exit
Enter your choice:
1
*******POINT CLIPPING******
The point is inside the clip window
Project Output Result
Thus the c program to implement point clipping was coded and executed successfully.

Related post