Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Computer Graphics (22318)

Practical No-11: Program for three dimensional transformations


(Rotation)
Practical Significance:

3D Computer graphics are graphics that use a 3D representation of geometric that is stored in the
computer for the purpose of performing calculations and rendering 2D images. To emphasize to
working with the real world problem statements and games 3D transformations are used.

I. Relevant Program Outcomes(POs):

 Basic Knowledge: Apply knowledge of basic mathematics, sciences and basic engineering to solve
the broad-based Computer Engineering related problems.
 Discipline Knowledge: Apply Computer Programming knowledge to solve broad-based computer
 Engineering related problems.
 Experiments Practice: Plan to perform experiments and practices to use the results to solve the
broad-based Computer Engineering related problems.
 Engineering Tools: Apply relevant computer programming technologies and tools with an
understanding of limitations.
 Communication: Communicate effectively in oral and written form.

II. Competency and Practical Skills :


This practical is expected to develop the following skills in you.
Develop 'C' programs to draw basic graphics objects:
1. Write syntax for graphics functions.
2. Write and save simple C program.
3. Setup graphics drivers, graphics mode and directory to run graphics program.
4. Compile the c program using Turbo C.
5. Debug and execute the program.

IV. Relevant course outcome(s):


 Implement standard algorithms to draw various graphics objects using C program.
 Develop programs for 2D and 3D transformations.

III. Practical Outcomes (POs):


Write a program for 3D Rotation.

IV. Relevant Affective domain related Outcome(s):


a. Plan, construct, compile, debug and test programs.
b. Experiment with graphics environment.
c. Follow safety/ethical practices.

1
Computer Graphics (22318)

VII. Minimum Theoretical Background:


Transformation in 3D:-
As, 2D transformations, it has a coordinate system with 3 axes as a basis in this learning
material all reasoning in space is done in a right hand system.
This means that if I put my right hand vertically down, with my fingers along the positive the
X -axis, and bend the hand towards the Y-axis, the thumb will point up along the positive Z- axis.

We use homogeneous coordinates from the beginning. This means that the transformation matrix
Is a 4x4 matrix, and that the general vector from is a column vector with 4 rows.

=M.

X2 m11 m12 m13 m14 x1


Y2 m21 m22 m23 m24 y1
Z2 = m31 m32 m33 m34 . z1
1 m41 m42 m43 m44 1

1. Translation:
Moving of object is called translation.

A translation in space is described by , and .It is easy to see that matrix realizes the equations:
=T.P

X, 1 0 0 tx x
Y, 0 1 0 ty y

2
Computer Graphics (22318)

Z, = 0 1 0 tz . z
1 0 0 0 1 1
This matrix representation is equivalent to following 3 equations:
=X+
=Y+
=Z+

2. Scaling:
Changing the size of an object is called as scaling transformation. In the scaling process, you either
expand or compress the dimensions of the object. Scaling can be achieved by multiplying the original
coordinates of the object with the scaling factor to get the desired result. The following figure shows
the effect of 3D scaling-

In 3D scaling operation, three coordinates are used. Consider that, the original coordinates are (x, y,
z), scaling factor are (Sz, Sy, Sz) respectively, and the product coordinates are (x, , y, ,z,). This can be
mathematically representer in matrix form as below –

Sz 0 0 0
0 Sy 0 0
S= 0 0 Sz 0
0 0 0 1

P, = P.S

[X, Y, Z, 1]=[X Y Z 1] Sz 0 0 0
0 Sy 0 0
0 0 Sz 0
0 0 0 1
= [X. Sz Y.Sy Z.Sz 1]
Scaling in space is described by Sx , Sy and Sz . We see that this matrix realizes the following equations:
X,=X.Sz
Y, =Y.Sy
,
Z =Z.Sz
Procedure:
Step 1: Start the program.
Step 2: Input the object coordinates.
Step 3: For translation
a) Enter the translation factors tx , ty and tz.
b) Move the original coordinates position (x,y, z)to a new position(x1, y1,z1). i.e.
x=x+x1, y=y+x1,z=z+z1.
c) Display the object after translation
Step 4: For scaling
a) Input the scaled factors Sx, Sy and Sz.
b) The transformed coordinates(x1, y1, z1), X1=X.Sx, Y1=Y.Sy and Z1=Z.Sz.

3
Computer Graphics (22318)

c) Display the object after scaling.


Step 5: Stop the program.

VIII. Algorithm

IX. Flow Chart

X. ‘C’ Program code (Attached print):

4
Computer Graphics (22318)

XI. Precautions:
1. Ensure that all C statements must end with a semicolon(;).
2. Use white space in c to describe blanks and tabs.
3. Ensure use of proper graphics function for relevant object.
4. Follow safety / ethical practices.

XII. Resource used:


S.No. Name of resource Specifications
1 Computer system with broad
specifications
2 Software
3 Any other resource used

XIII. Practical related questions

1. Write the transformation matrix for 3D translation.


2. Write the transformation matrix for 3D scaling.
3. Write Z- coordinate indicate in 3D transformations.
4. Explain Homogeneous coordinates.

List of Students/ Team members


1.
2.
3.
4.
Marks obtained Dated signature of Teacher
Process Product Total(25)
Related(10) Related(15)

5
Computer Graphics (22318)

6
Computer Graphics (22318)

You might also like