All rights are reserved by Niteesh Kumar.. Theme images by Storman. Powered by Blogger.


Total Pageviews

Blog Archive


Sunday, 9 April 2017

Program to implement 3D transformation-Translation

We require three dimensional geometric and co-ordinate transformation to change the view of a three dimensional object.Three dimensional transformations are extended from two dimensional transformations by considering the 'z' co-ordinate also in the plane.Just like two dimensional transformation in three dimensional transformations are formed by composing three basic transformations of translation, scaling and rotation.

Here we are going to discuss about the translation.

What is translation?

A translation transform simply moves every point by a certain amount horizontally and a certain amount vertically. If (x,y) is the original point and (x1,y1) is the transformed point, then the formula for a translation is-
e and f are translation factors.

In three dimensional co-ordinate system each vertex have (x,y,z). So, each vertex have three translation factors.But if we use this process we need to translate all the co-ordinates of object.For practical purpose we use the technique below.

So, first of all we need to draw a 3D object, here we are going to use bar3d function that is defined in graphics.h library of c.
       void bar3d(left,top,right,bottom,depth,topflag);

bar3d draws a three-dimensional rectangular bar by taking these parameters.
for translation of a rectangular box first we draw it using bar3d function and then will take the translation factor as input and again use bar3d function with the new left,top,right,bottom. 

C program for 3D translation is given below-

#include stdio .h
#include graphics .h
#include math .h

void trans();

//these are left,top,right,bottom parameters for bar3d function
int maxx,maxy,midx,midy;

void main()


            int ch;

            int gd=DETECT,gm;


            initgraph(&gd,&gm," ");
return 0;

//function for translation of a 3d object
void trans()


            int x,y,z,o,x1,x2,y1,y2;



            //function to draw 3D rectangular box  
            printf("Enter translation factor");


            printf("After translation:");


translation factors-(20,20)

1 on: "Program to implement 3D transformation-Translation"