Friday 27 September 2013

2D Transformation - Rotation | Computer Graphics Lab Manual | IT department | Final Year





#include
#include
#include
#include
void main()
{
int gd=DETECT,gm;
int i=0,j=0,x0,y0,maxx,maxy,x[10],y[10],tx[10],ty[10];
float t;
char q[10],w[10];
initgraph(&gd,&gm,"c:\\tc\\bgi");
maxx=getmaxx();
maxy=getmaxy();
clrscr();
printf("\n\t\t 2D Transformation - Rotation");
printf("\nEnter the vertices of the triangle:");
for(i=0;i<3 i="" p=""> {
printf("\nEnter the vertex V%d(x,y):",i+1);
scanf("%d%d",&x[i],&y[i]);
}
printf("\nEnter theta value:\t");
scanf("%f",&t);
clrscr();
t=t*(3.1416/180.0);
x0=maxx/2;
y0=maxy/2;
line(0,y0,maxx,y0);
outtextxy(maxx-10,y0+5,"x");
outtextxy(0,y0,"-x");
for(j=40;j<=320;j+=40)
{
sprintf(q,"%2d",j);
outtextxy(295+j,240,q);
outtextxy(295-j,240,q);
outtextxy(315-j,240,"-");
}
line(x0,0,x0,maxy);
  outtextxy(x0-10,1,"y");
outtextxy(x0-20,maxy-10,"-y");
for(j=40;j<=240;j+=40)
{
sprintf(w,"%2d",j);
outtextxy(295,240-j,w);
outtextxy(295,240+j,w);
outtextxy(290,240+j,"-");
}
moveto(x0+x[0],y0-y[0]);
for(i=0;i<3 i="" p=""> lineto(x0+x[i],y0-y[i]);
lineto(x0+x[0],y0-y[0]);
for(i=0;i<3 i="" p=""> {
tx[i]=x[i]*cos(t)-y[i]*sin(t);
ty[i]=x[i]*sin(t)+y[i]*cos(t);
}
moveto(x0+tx[0],y0-ty[0]);
for(i=1;i<3 i="" p=""> lineto(x0+tx[i],y0-ty[i]);
lineto(x0+tx[0],y0-ty[0]);
getch();
closegraph();
}




No comments:

Don't You Think this Awesome Post should be shared ??
| 2D Transformation - Rotation | Computer Graphics Lab Manual | IT department | Final Year |
Back To Top Related Posts Plugin for WordPress, Blogger...