Aim
To write a C program to implement 3D transformations such as translation, rotation and scaling of objects.
Algorithm:
·
Translation
1. Read
the co-ordinates (x, y, z) of the object.
2. Display
the original object.
3. Read
the translation vector (tx, ty, tz).
4. Calculate
the new co-ordinates as follows:
x’ = x + tx
y’ = y + ty
z’ = z + tz
5. Display
the translated object on the screen.
·
Rotation
1. Read
the co-ordinates (x, y, z) of the object.
2. Display
the original object.
3. Read
the rotation angle Ɵ.
4. For
rotation about z-axis, calculate new co-ordinates as follows:
x’ = x * cos(Ɵ) – y * sin(Ɵ)
y’ = x * sin(Ɵ) + y * cos(Ɵ)
z’ = z
5. Display
the object after rotation about z-axis.
6. For
rotation about x-axis, calculate new co-ordinates as follows:
x’ = x
y’ = y * cos(Ɵ) – z * sin(Ɵ)
z’ = y * sin(Ɵ) + z * cos(Ɵ)
7. Display
the object after rotation about x-axis.
8. For
rotation about y-axis, calculate new co-ordinates as follows:
x’ = z * sin(Ɵ) + x * cos(Ɵ)
y’ = y
z’ = z * cos(Ɵ) – x * sin(Ɵ)
9. Display
the object after rotation about y-axis.
10. Stop
·
Scaling
1. Read
the co-ordinates (x, y, z) of the object.
2. Display
the original object.
3. Read
the scaling factors (sx, sy, sz).
4. Calculate
the new co-ordinates as follows:
x’ = x * sx
y’ = y * sy
z’ = z * sz
5. Display the scaled object on the screen.
No comments:
Post a Comment