Friday, May 14, 2010

3 Dimensional Translation in C program | CS1355-Graphics & Multimedia Lab

3 dimensional transformation it has three axis x,y,z.Depandting upon there coordinate it will perform there Translation ,Rotaion,Scaling, The translation can be performed by changing the sign of the translation components Tx, Ty, and Tz.

Source code programming
#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++)
{
line(x[i]+tx,y[i]+ty,x[i]+tx+d,y[i]+ty-d);
}
}
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();
}

 


3D TRANSFORMATION in c program |  computer graphics lab

3D TRANSFORMATION in c program |  computer graphics lab

3D TRANSFORMATION in c program |  computer graphics lab

3D TRANSFORMATION in c program |  computer graphics lab

3D TRANSFORMATION in c program |  computer graphics lab

3D TRANSFORMATION in c program |  computer graphics lab


3D TRANSFORMATION in c program computer graphics lab
---------------------------------------------------
1.Translation
2.Rotation
3.Scaling
4.Exit
Enter your Choice :1
Enter the points 01: 288
Enter the points 10: 288
Enter the points 10: 258
Enter the points 11: 288
Enter the points 20: 258
Enter the points 21: 258
Enter the points 30: 288

Flag counter

free counters