AIM:
To implement 3D transformation of translation.
ALGORITHM:
1. This operation can be carried out for polygons by multiplying the coordinate values (x, y,z) of each vertex by translation vectors tx, ty and tz to produce the transformed coordinate (x’, y’,z’).
x’=x+tx
y’=y+ty
z’=z+tz
2. The matrix representation
X’ 1 0 tx x
y’ = 0 1 ty + y
z’ 0 0 tz z
OR
P’=T+P
3. Parameters tx, ty, tz specifying translation distances for the coordinate direction x,y,z are assigned to any real values.
4. The matrix representation is equivalent to three equations
X’=x+tx, y’=y+ty, z’=z+tz
SOURCE CODE:
#include
#include
#include
#include
#include
void main()
{
int n,tx,ty,d,p1[10][3],p2[10][3],i,gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("enter the no.of lines");
scanf("%d",&n);
printf("enter the values");
for(i=1;i
{
scanf("%d%d",&p1[i][1],&p2[i][1]);
}
printf("enter the depth");
scanf("%d",&d);
for(i=1;i<=n;i++)
{
p2[i][1]=p1[i][1]=d;
p2[i][2]=p1[i][2]=d;
}
getch();
clrscr();
printf("before translation");
for(i=1;i
{
line(p1[i][1],p1[i][2],p1[i+1][1],p1[i+1][2]);
}
line(p1[1][1],p1[1][2],p1[n][1],p1[n][2]);
for(i=1;i<=n;i++)
{
line(p2[i][1],p2[i][2],p2[i+1][1],p1[i+1][2]);
}
for(i=1;i<=n;i++)
{
line(p1[i][1],p1[i][2],p2[i][1],p2[i][2]);
}
getch();
printf("enter the translation parameters\n enter the values of tx,ty");
scanf("%d%d",&tx,&ty);
for(i=1;i<=n;i++)
{
p1[i][1]=p1[i][1]+tx;
p1[i][2]=p1[i][2]+ty;
p2[i][1]=p2[i][1]+tx;
p2[i][2]=p2[i][2]+ty;
}
getch();
cleardevice();
printf("after translation");
for(i=1;i
{
line(p1[i][1],p1[i][2],p1[i+1][1],p1[i+1][2]);
}
line(p1[1][1],p1[1][2],p1[n][1],p1[n][2]);
for(i=1;i
{
line(p2[i][1],p2[i][2],p2[i+1][1],p1[i+1][2]);
}
line(p2[i][1],p2[i][2],p2[n][1],p2[n][2]);
for(i=1;i<=n;i++)
{
line(p1[i][1],p1[i][2],p2[i][1],p2[i][2]);
}
getch();
}
OUTPUT:
Enter the no of lines: 3
Enter the values: 65 70 65 90 50 85
Enter the depth:
50
Enter the translation values: 42 30
No comments:
Post a Comment