Window To Viewport Transformation
C++ Program - Graphics & Multimedia Lab
C++ Program - Graphics & Multimedia Lab
Sourcecode:
#include<graphics.h> #include<iostream> using namespace std; int main() { FILE *ip,*op; float xwmin,xwmax,ywmax,ywmin; float xvmin,xvmax,yvmax,yvmin; float x[10],y[10],yv,xv,sx,sy; int gd=DETECT,gm,i; ip=fopen("w2vinput.txt","r"); op=fopen("w2voutput.txt","w"); fscanf(ip,"%f %f %f %f",&xwmin,&ywmin,&xwmax,&ywmax); fscanf(ip,"%f %f %f %f",&xvmin,&yvmin,&xvmax,&yvmax); for(i=0;i < 3;i++) { fscanf(ip,"%f %f",&x[i],&y[i]); } sx=((xvmax-xvmin)/(xwmax-xwmin)); sy=((yvmax-yvmin)/(ywmax-ywmin)); initgraph(&gd,&gm,NULL); outtextxy(40,10,"Window port"); rectangle(xwmin,ywmin,xwmax,ywmax); for(i=0;i <2;i++) { line(x[i],y[i],x[i+1],y[i+1]); } line(x[2],y[2],x[0],y[0]); getch(); for(i=0;i <3;i++) { x[i]=xvmin+((x[i]-xwmin)*sx); y[i]=yvmin+((y[i]-ywmin)*sy); } outtextxy(190,145,"View port"); rectangle(xvmin,yvmin,xvmax,yvmax); fprintf(op,"%s","Output points:\n"); for(i=0;i <2;i++) { fprintf(op,"x[%d]=%f y[%d]=%f\n",i,x[i],i,y[i]); line(x[i],y[i],x[i+1],y[i+1]); } line(x[2],y[2],x[0],y[0]); fprintf(op,"x[2]=%f y[2]=%f\n",x[2],y[2]); getch(); closegraph(); return 0; }
Output:
"w2vinput.txt"
"w2voutput.txt"
nn@linuxmint ~ $ g++ lab8.cpp -lgraph lab8.cpp: In function ‘int main()’: lab8.cpp:24: warning: deprecated conversion from string constant to ‘char*’ lab8.cpp:38: warning: deprecated conversion from string constant to ‘char*’ nn@linuxmint ~ $ ./a.out
"w2vinput.txt"
22 22 150 150 200 200 350 250 45 45 125 45 125 125
"w2voutput.txt"
Output points: x[0]=226.953125 y[0]=208.984375 x[1]=320.703125 y[1]=208.984375 x[2]=320.703125 y[2]=240.234375
With this tutorial, you will be able to take off graphics from any surface, no matter how long they have been on. window graphics printing
ReplyDeleteThis is quite educational arrange. It has famous breeding about what I rarity to vouch.
ReplyDeleteColossal proverb. This trumpet is a famous tone to nab to troths. Congratulations on a career well achieved.
This arrange is synchronous s informative impolite festivity to pity. I appreciated what you ok extremely here.
Selenium interview questions and answers
Selenium Online training
Selenium training in Pune
selenium training in USA
selenium training in chennai
The article you share enough to help me in searching for assignment related information, thank you .
ReplyDeleteJava training in Chennai
Java training in Bangalore
Java training in Hyderabad
Java Training in Coimbatore
Java Online Training