Page 155 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 155
Unit 9: Translation
line(x[i]+tx,y[i]+ty,x[i]+tx+d,y[i]+ty–d); Notes
}
}
void main()
{
int gd=DETECT,gm;
int x[20],y[20],tx=0,ty=0,i,fs,d;
initgraph(&gd,&gm,”“);
printf(“no of sides (front view only) : “);
scanf(“%d”,&fs);
printf(“co-ordinates : “);
for(i=0;i<fs;i++)
{
printf(“(x%d,y%d)”,i,i);
scanf(“%d%d”,&x[i],&y[i]);
}
printf(“Depth :”);
scanf(“%d”,&d);
draw3d(fs,x,y,tx,ty,d);
printf(“translation (x,y)”);
scanf(“%d%d”,&tx,&ty);
draw3d(fs,x,y,tx,ty,d);
getch();
}
9.3 Translating with Matrices
This function obtains as factors an orientation to the matrix that grasps the current state of the
transformation and the X and Y translation values. First, the function loads a local matrix with
the worth that makes a translation matrix, after which it multiplies the translation matrix times,
the main transformation matrix. The effect of the multiplication, accumulated in the local matrix
m2, is then copied into the transformation matrix.
Matrix/Vector Representation of Translations
A translation can also be represented by a pair of numbers, t=(tx, ty) where tx is the change in
the x-coordinate and ty is the modify in y coordinate. To translate the point p by t, we simply
add to obtain the new (translated) point q = p + t
x È ˘ È tx˘ È x + tx ˘
q = p + t = Í ˙ + Í ˙ = Í ˙
y
ty
Î ˚ Î ˚ Î y + ty ˚
APL (form of metrics), designed by Ken Iverson, was the first programming
language to provide array programming capabilities.
LOVELY PROFESSIONAL UNIVERSITY 149