Page 154 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 154
Lab on Computer Graphics
Notes draw2d(fs, x, y, tx, ty);
getch();
}
void draw2d(int fs, int x[20], int y[20], int tx, int ty)
{
int i;
for(i=0;i<fs;i++)
{
if(i!=(fs–1))
line(x[i] + tx, y[i]+ty, x[i+1]+tx, y[i+1]+ty);
else
line(x[i]+tx, y[i]+ty, x[0]+tx, y[0]+ty);
}
}
9.2 3–Dimensional Translation in C program
3Dimensional transformation it has three axis x, y, z depending upon their coordinate it will
execute their translation, rotation, scaling. The translation can be performed by changing the
symbol of the translation components Tx, Ty, and Tz.
Program
#include <stdio.h>
#include <stdlib.h>
#include<graphics.h>
#include<conio.h>
void draw3d(int fs, int x[20], int y[20], int tx, int ty, int d);
void draw3d(int fs, int x[20], int y[20], int tx, int ty, int d);
{
int i,j,k=0;
for(j=0;j<2;j++)
{
for(i=0;i<fs;i++)
{
if(i!=fs–1)
line(x[i]+tx+k, y[i]+ty–k, x[i+1]+tx+k, y[i+1]+ty–k);
else
line(x[i]+tx+k,y[i]+ty–k,x[0]+tx+k,y[0]+ty–k);
}
k=d;
}
for(i=0;i<fs;i++)
{
148 LOVELY PROFESSIONAL UNIVERSITY