Write Source Code For Windows View Port Mapping

Window View Port Algorithm
1. Input the minimum and maximum coordinates of a window.
2. Input the minimum and maximum coordinates of a view port.
3. Get the coordinates of a point.
4. Display a point using set pixel function.

Source Code Programming Algorithm
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gm,gr,xwmin,ywmin,xwmax,
ywmax,xvmin,yvmin,xvmax,yvmax,xw,yw,xv,yv,sx,sy;
clrscr();
detectgraph(&gm,&gr);
initgraph(&gm,&gr,"d:\\tc\\BGI");
printf("Enter the window min coordinate(xwmin,ywmin):\n");
scanf("%d%d",&xwmin,&ywm+in);
printf("Enter the window max coordinate(xwmax,ywmax):\n");
scanf("%d%d",&xwmax,&ywmax);
rectangle(xwmin,ywmax,xwmax,ywmin);
printf("Enter the viewport min coordinate(xvmin,yvmin):\n");
scanf("%d%d",&xvmin,&yvmin);
printf("Enter the viewport max coordinate(xvmax,yvmax):\n");
scanf("%d%d",&xvmax,&yvmax);
sx=(xvmax-xvmin)/(xwmax-xwmin);
sy=(yvmax-yvmin)/(ywmax-ywmin);
rectangle(xvmin,yvmax,xvmax,yvmin);
printf("Enter the point coordinate(xw,yw) in the window:\n");
scanf("%d%d",&xw,&yw);
putpixel(xw,yw,15);
xv=(sx*(xw-xwmin))+xvmin;
yv=(sy*(yw-ywmin))+yvmin;
putpixel(xv,yv,15);
getch();
}
Example Project OUTPUT Resutl
Enter the window min coordinate(xwmin,ywmin):
150
150

Enter the window max coordinate(xwmax,ywmax):
250
250

Enter the view port min coordinate(xvmin,yvmin):
350
350

Enter the view port max coordinate(xvmax,yvmax):
450
450

Enter the point coordinate(xw,yw) in the window:
200
200

RESULT Thus the c program to implement window to view port mapping was coded and executed successfully.

Related post