One of the most common and important tasks in computer graphics is to transform the coordinates (position, orientation, and size) of either objects within the graphical scene or the camera that is viewing the scene. It is also frequently necessary to transform coordinates from one coordinate system to another, (e.g. world coordinates to viewpoint coordinates to screen coordinates.) All of these transformations can be efficiently handled using some simple matrix representations, which are combining multiple transformations into a single composite transform matrix.
Suppose point (x,y) is to be translated by amount tx and ty to a new location (x',x')
x' = tx + x , x' = ty + y
or P' = T + P where P' =
[x`,y`] , T = [tx,ty]
and P= [x,y] #include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
void main()
{
int a[6][6],b[10],t[6][6],d[6][6];
int i,j,r,c,k=1,r1,c1,k1=0;
int gdriver = DETECT, gmode;
clrscr();
initgraph(&gdriver,&gmode,"c:/tc/bgi");
printf("Enter number of rows=");
scanf("%d",&r);
printf("Enter number of column=");
scanf("%d",&c);
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
printf("a[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}
}
printf("\nEnter the row & column of transformation matrix=");
scanf("%d%d",&r1,&c1);
if(c==r1)
{
for(i=1;i<=r1;i++)
{
for(j=1;j<=c1;j++)
{
printf("t[%d][%d]=",i,j);
scanf("%d",&t[i][j]);
}
}
}
else
{
printf("not possible");
// exit(0);
}
for(i=1;i<=r;i++)
{
for(j=1;j<=c1;j++)
{
d[i][j]=0;
for(k1=1;k1<=c;k1++)
d[i][j]+=a[i][k1]*t[k1][j];
}
}
for(i=1;i<=r;i++)
{
for(j=1;j<=c1;j++)
{
printf("\t%d",d[i][j]);
}
printf("\n");
}
getch();
cleardevice();
for(i=1;i<r;i++)
{
for(j=1;j<c;j++)
{
line(a[i][j],a[i][j+1],a[i+1][j],a[i+1][j+1]);
}
printf("\n");
}
line(a[r][c-1],a[r][c],a[1][1],a[1][2]);
for(i=1;i<r;i++)
{
for(j=1;j<c;j++)
{
line(d[i][j],d[i][j+1],d[i+1][j],d[i+1][j+1]);
}
printf("\n");
}
line(d[r][c-1],d[r][c],d[1][1],d[1][2]);
getch();
}
No comments:
Post a Comment