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

Followers

Total Pageviews

Blog Archive

Follow by Email

Translate

Sunday, 30 April 2017

Program for 3D transformation-Scaling


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 scaling.

What is scaling?

A scaling transform can be used to make objects bigger or smaller. Mathematically, a scaling transform simply multiplies each x-coordinate by a given amount and each y-coordinate by a given amount. That is, if a point (x,y) is scaled by a factor of a in the x direction and by a factor of d in the y direction, then the resulting point (x1,y1) is given by
                             x1 = a * x 
                             y1 = d * y
a and d are scaling factor.

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 scaling 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 scaling is given below-

#include stdio.h #include graphics.h #include math.h void scale(); //these are left,top,right,bottom parameters for bar3d function int maxx,maxy,midx,midy; void main() { int ch; int gd=DETECT,gm; detectgraph(&gd,&gm); initgraph(&gd,&gm," "); scale(); return 0; } //function for scaling of a 3d object void scale() { int x,y,z,o,x1,x2,y1,y2; midx=200; midy=200; bar3d(midx+50,midy-100,midx+100,midy-50,20,0); printf("before scaling\n"); printf("Enter scaling factors\n"); scanf("%d %d %d", &x,&y,&z); printf("After scaling\n"); bar3d(midx+(x*50),midy-(y*100),midx+(x*100),midy-(y*50),20*z,1); }
 
 
 
OUTPUT-
 
 
 

0 on: "Program for 3D transformation-Scaling"