CG 4

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 22

Unit 4

Three-Dimensional Geometric Transformation


3D computer graphics or three dimensional computer graphics are graphics that use a three-
dimensional representation of geometric data that is stored in the computer for the purpose of
performing calculations and rendering 2D images.
2D is “flat” using the horizontal and vertical (X & Y) dimensions, the image has only two
dimensions. 3D adds the depth (Z) dimension. This third dimension allows for rotation and
visualization from multiple perspectives.
We can perform different transformation by specifying the three dimensional transformation
vector, however the 3D transformation is more complex than 2D transformation.

Q. What are the issue in 3D that makes it more complex than 2D?
When we model and display a three-dimensional scene, there are many more considerations
we must take into account besides just including coordinate value as 2D, some of them are:
- Relatively more coordinates point are necessary.
- Object boundaries can be constructed with various combinations of plane and
curved surfaces.
- Consideration of projection (dimension change with distance) and transparency.
- Many consideration on visible surface detection and remove the hidden surfaces.

 3D Geometric Transformation

 3D Translation
A point is translated from position P(x, y, z) to position P’(x’, y’, z’) with the matrix
y
operation as:
0 𝑡𝑥
𝑥′ 1 𝑥
𝖥 1
𝑦 ′
0 0 [𝑦
P’(x’, y’, z’)

[ ′] 0 𝑡𝑦 𝑧
I ]
=𝑧 I 1 𝑡𝑧 1
x
1
P(x, y, z)

I
I0
0
1 [0 0 0 1]
Parameter 𝑡𝑥, 𝑡𝑦, 𝑡𝑧 specify transition distances for the coordinate
z
directions x, y, z. This matrix representation is equivalent to three equations:
𝑥′ = 𝑥 + 𝑡𝑥
𝑦′ = 𝑦 + 𝑡𝑦
𝑧′ = 𝑧 + 𝑡𝑧
 3D Rotation
Rotation about Z-axis
𝑥′ = 𝑥𝑐𝑜𝑠𝜃 − 𝑦𝑠𝑖𝑛𝜃
𝑦′ = 𝑥𝑠𝑖𝑛𝜃 + 𝑦𝑐𝑜𝑠𝜃
𝑧′ = 𝑧

Rotation about x-axis


𝑥′ = 𝑥
𝑦′ = 𝑦𝑐𝑜𝑠𝜃 − 𝑧𝑠𝑖𝑛𝜃
𝑧′ = 𝑦𝑠𝑖𝑛𝜃 + 𝑧𝑐𝑜𝑠𝜃

Rotation about y-axis


𝑦′ = 𝑦
𝑧′ = 𝑧𝑐𝑜𝑠𝜃 − 𝑥𝑠𝑖𝑛𝜃
𝑥′ = 𝑧𝑠𝑖𝑛𝜃 +
𝑥𝑐𝑜𝑠𝜃
𝑐𝑜𝑠𝜃 0 𝑠𝑖𝑛𝜃 0 𝑥
𝑥
′ 0 1 0 0 𝑦
𝑦

[ ′] = [ ][ ]
𝑧 −𝑠𝑖𝑛𝜃 0 𝑐𝑜𝑠𝜃 0 𝑧
1 0 0 0 1 1

#General 3D rotation (Rotation about any coordinate axis)


 Parallel to any of the co-axis:
When an object is to be rotated about an axis that is parallel to one of the co-ordinate axis,
we need to perform some series of transformation.
1. Translate the object so that the rotation axis coincides with the parallel co-ordinate
axis. T(-a,-b,-c) where, (a, b, c) is any point on the rotation axis.
2. Performed the specified rotation about the axis. Rx(θ )
3. Translate the object so that the rotation axis is moved to its original position. T(a, b,
c). Net transformation= T(a, b, c) Rx(θ). T(-a,-b,-c)

 Not parallel to any of the co-axis:


When an object is to be rotated about an axis that is not parallel to one of the co-ordinate
axes, we need to perform some series of transformation.
1. Translate the object such that rotation axis passes through co-ordinate origin.
2. Rotate the object such that axis of rotation coincides with one of the co-ordinate axis.
3. Perform the specific rotation about selected coordinate axis.
4. Apply inverse rotation to bring the rotation axis back to its original orientation.
5. Apply inverse translation to bring the rotation axis back to its original position.
1) Translate P1 to origin

2) Find transformation that will bring rotation axis P1P2 on z-axis. This will

a) Rotation by angle α about x axis that bring vector 𝑢⃗→ into x-z plane, where,
be accomplished in two steps:

𝑣→ = ⃗𝑝⃗⃗⃗2→ − 𝑝⃗⃗⃗1→ = (𝑥2 − 𝑥1 , 𝑦2 − 𝑦1 , 𝑧2 − 𝑧1 )

Unit vector along 𝑣→ , 𝑢⃗→


= (𝑎, 𝑏, 𝑐) where,
=
𝑣⃗→

|𝑣⃗→|

𝑎 = 𝑏 =|𝑣⃗→| , 𝑐 |𝑣⃗=→|
𝑥2−𝑥1 𝑦2−𝑦1 𝑧2−𝑧1 y
|𝑣⃗→| ,

u
x



Where, 𝑑 = √𝑏2 + 𝑐2
z
b) Rotate by angle β about y axis that brings 𝑢⃗→ on z-axis. y

𝛽
x

3) Rotation about z-axis.


z

4) Find the 𝑅−1(𝛽), 𝑅−1(α), 𝑇−1i.e.


𝑇(𝑥 , 𝑦 , 𝑧 ).
𝑦 𝑥 1 1 1
5) Find composite transformation for general rotation by ‘𝜃’ (anticlockwise).
𝑀 = 𝑇(𝑥1, 𝑦1, 𝑧1). 𝑅−1(𝛼). 𝑅−1(𝛽). 𝑅𝑧(𝜃). 𝑅𝑦(𝛽). 𝑅𝑥(𝛼). 𝑇(−𝑥1, −𝑦1, −𝑧1)
� �

Q. Find the new co-ordinates of a unit cube 90 degree rotated about an axis defined by its
end points A(2, 1, 0) and B(3, 3, 1).

Solution:

y
(1,1, 0)

(1,1,1)

x
(0,0, 0)
(1,0, 1)

Fig: unit cube

Now,

1 0 0 −2
Translating the point (A) to the origin,

0 1 0 −1
𝑇 =[
0 1 0 ]
0 0 1
0
0
Now, rotate the 𝐴′ 𝐵′ about x-axis by angle 𝛼 until vector 𝑢⃗→ lies on xz-plane. Where,
𝑣→ = 𝐵⃗→ - 𝐴→ =(3, 3, 1)-(2, 1, 0)=(1, 2, 1)
Unit vector along 𝑣→, 𝑢⃗→ ,
1
) = (a, b, c) (say)
=2 =(
(1, 2, 1) 1
=
𝑣⃗→

|𝑣⃗→| √6 √6 √6 √6
,

And, 𝑑 = √𝑏 + 𝑐 =
2 2


5

6
10 0 0 1 0 0 0 1 0 0 0
( ) 0 0 1/ −2/√5 0
𝑅 𝛼 = 𝑐𝑜𝑠 −𝑠𝑖𝑛 ]= 𝑐/ −𝑏/ ]=
0 0 0 ]
[ 𝛼 𝛼 [ 𝑑 𝑑 [ √5
𝑥 𝑠𝑖𝑛 𝑐𝑜𝑠𝛼 0 0 𝑏/𝑑 𝑐/𝑑 0 0 1/√5 0
0 𝛼 2/√5
0 1 0 0 0 1 1
0
0 0 0 0

Again, rotating 𝐴′𝐵′ about y-axis by angle 𝛽 until it coincides with z-axis.
𝑐𝑜𝑠𝛽 0 𝑠𝑖𝑛𝛽 0 𝑑 −𝑎 0 𝖥√5/6 0 −1/√6 01
0
0 0 0 0
𝑅 𝑦( 𝛽) = [ 1 0 0] = [0 ]=I 0 1 0I
1
−𝑠𝑖𝑛𝛽 0 𝑎 0 𝑑
0
I01/√6 √5/6 0I
𝑐𝑜𝑠𝛽 0
0 0 0 0 0 0 1]
[ 0 0
1 1 0

𝑐𝑜𝑠9 −𝑠𝑖𝑛900 0 0 −1 0 0
Rotating the unit cube 90 degree about z-axis.

0 0
0
(9000) =
𝑅𝑠𝑖𝑛90 𝑐𝑜𝑠900 0 0] = [1 0 0]
[ 0
𝑧
0 0 1 0 0 1 0
0 0 0 0 0 1
0 0
1

𝑅(−1𝜃) = 𝑇−1𝑅−1(𝛼). (900). (𝛽). (𝛼). 𝑇


𝑅 (𝛽). 𝑅 𝑅 𝑅
The combined transformation rotation matrix about the arbitrary axis becomes,

𝑥 𝑧 𝑦 𝑥
𝑦 0 0 0 01 −1 0 0
1 0 0 2 𝖥
0 √5/6 1/√6 0
1
0 1 1/ 2/
𝑅(𝜃) = [ 1] 0] I 0 1 0 0I 0 0 0]
0 √5 √5
[0 0 0 [1
0
0 0 1 1/ 0I 0 1 0
0 −2/√5 √5 I−1/√6 √5/6 0
0 0 0 10 0 1 [ 0 0 1] 0 0 0 1
0 0
01 𝖥1 0
𝖥√5/6 0 0
01 1 0 0 −2
−1/√6
I 0 0 0I 1/ −2/ 0I 1 0 −1]
1 √5 √5
I0 [0
I1/√6 √5/ 00I 2/ 1/ 0I 0 0 1 0
0 6 I √5 √5
[ 0 0 1 ] [ 0 1] 0 0 0 1
0 0
0.11 −0.07 0.98
6 5 3 0
1.742
∴ 𝑅(𝜃) = [ 0.66 0.07 −1.151
0.742 7 5 ]
0.560
−0.65 0.74 0.16 1
0 1 7
0 0 0
Now, multiplying 𝑅(𝜃) by the matrix of original unit cube;
𝑃′ = 𝑅(𝜃). 𝑃
0.11 −0.07 0.98 1.742 0 0 1 0 0 1 1
6 5 3 1
𝑃′ = 0.74 0.667 0.07 −1.151][1 1 1 0 0 0 0
[ 2 5 1 1 0 0 1]
0.560 1 0 0 1 1 1 1 1
1 1 1 1 1

2.65 1.66 1.83 2.81 2.752 1.74 1.90 2.891


0 7 4 6 5 2 9 −0.483]
𝑃 =
′ −0.48 0.25 0.18 −1.22 −1.15 −0.40
1.46 4 1.30 80.6504 5 0.72 2 0.56 9−0.09 0.07
[−0.558 7 1 0.817 6 6 1 6
 3D Scaling
Matrix representation for scaling transformation of a position 𝑃 = (𝑥, 𝑦, 𝑧) relative to
the coordinate origin can be written as;

For scaling of point P(x, y, z) w.r.t to fixed point (𝑥𝑓, 𝑦𝑓, 𝑧𝑓) can be represented with the

1. Translate the fixed point to the origin. 𝑇(−𝑥𝑓, −𝑦𝑓, −𝑧𝑓)


following transformation.

2. Apply scaling w.r.to origin. 𝑆(𝑠𝑥, 𝑠𝑦, 𝑠𝑧)


3. Translate the fixed point back to its original position. 𝑇(𝑥𝑓, 𝑦𝑓, 𝑧𝑓)

 3D Reflection
In 3D-reflection the reflection takes place about a plane.

(a) About xy-plane (z-axis)


This transformation changes the sign of the z coordinates, leaving the x and y
coordinate values unchanged.

(b) About xz-plane (y-axis)


This transformation changes the sign of the y coordinates, leaving the x and z
coordinate values unchanged.
(c) About yz-plane (x-axis)
This transformation changes the sign of the x coordinates, leaving the y and z
coordinate values unchanged.

About any plane:


Step-1: Translate the plane such that it passes through origin i.e. normal vector passes
through origin.
Step-2: Rotate the plane such that normal vector lies on one of the co-ordinate axis.
Step-3: Perform reflection about the plane whose normal vector is one of the co-ordinate axis.
Step-4: Rotate back the plane such that normal vector takes its original orientation.
Step-5: Translate back the plane to its original position.

 3D Shearing
Shearing transformations are used to modify objects shape.
(a) Z-axis shearing
This transformation alters x and y coordinates values by amount that is proportional to the z

𝑥′ = 𝑥 + 𝑠ℎ𝑥𝑧
values while leaving z coordinate unchanged.

𝑦′ = 𝑦 + 𝑠ℎ𝑦𝑧
𝑧′ = 𝑧

𝑥′ 1 0 𝑠ℎ 0 𝑥
𝑦′ 𝑥
[ ′] = 0 [ 1 𝑠ℎ 0] 𝑦]
𝑧
1 𝑦
0 0 1 0 [
(b) X-axis shearing
This transformation alters y and z coordinates values by amount that is proportional to the x

𝑥′ = 𝑥
values while leaving x- coordinate unchanged.

𝑦′ = 𝑦 + 𝑠ℎ𝑦𝑥
𝑧′ = 𝑧 + 𝑠ℎ𝑧𝑥
1 0 0 𝑥
𝑥
′ 0 01 𝑦
0
𝑦 𝖥
′ 𝑠ℎ𝑦

1
[ ] =
𝑧′ I 𝑠ℎ𝑧 [ ]
1 0I 𝑧

0
[0 1
1 0 0 1]

(c) Y- axis shearing


This transformation alters x and z coordinates values by amount that is proportional to the y
values while leaving y- coordinate unchanged.
𝑥′ = 𝑥 + 𝑠ℎ𝑥𝑦
𝑦′ = 𝑦
𝑧′ = 𝑧 + 𝑠ℎ𝑧𝑦

𝑥′′ 1 𝑠ℎ𝑥 0 0 𝑥
𝑦 0 1 0 0 𝑦
[ ′] = [ ][ ]
𝑧 0 𝑠ℎ𝑧 1 0 1𝑧
1 0 0 0 1

Q. A homogenous coordinate point P(3, 2, 1) is translated in x, y, z direction by -2, -2 & -2


unit respectively followed by successive rotation of 600 about x- axis. Find the final
position of homogenous coordinate.

Solution:

𝑡𝑥 = −2
Here,

𝑡𝑦 = −2
𝑡𝑧 = −2

1 0 −2
0 −2
0 1 −2 ]
0
1
𝑇 =[
0
0
0 0 0 1
1 0 0 0
1
1 0 0 0 𝖥 − √3
0
0
1
0 𝑐𝑜𝑠6 −𝑠𝑖𝑛6 0 =I I
𝑅 (600) =
2 2
0 0 0 ] I
0I
1
𝑥 [ 0 0 0 01 I0
2
𝑠𝑖𝑛6 𝑐𝑜𝑠60
√3
2
[0 0 0
1]
1 0 0 0 0 −2
Composite transformation

1 0
𝖥 1 1 0 𝖥 −1 + √31
− 0 −
1
0 √3 √3
0 0
1
−2 ] I
( 0
) I 2 I 0 0 −2 I 2 2 I
I
2

𝑅𝑥 1[ I
60 .𝑇 =I 0 0 1 −2 −√3 − 1
0 0
√3 1
I 02
√3
1
2
I I I
0 0 0 1
2 2
Now, [0 0 0 1] [0 0 0 1 ]

1 0 0 −2
𝖥

1 −1 + √31 3
0I √3
2 I 2
𝑃 = 𝑀. 𝑃 = I[ 1] =
′ 2

I −√3 − 1
I 0 2
√3 1
2 I 1
[0 0 0 1 ]
77 Computer Graphics (Reference Note) BSc.CSIT

principal axis. If the cube is to be rotated about z-axis by an angle of 450 in counter
Q. A cube of length 10 units having one of its corner at origin (0, 0, 0) & three edges
clockwise direction, calculate the new position of point.
y
Solution: C(10,10,0)

G(10,10,10)

A(0,0,0) x
F(10,0,10)

𝑐𝑜𝑠45 −𝑠𝑖𝑛45 0 0 0.707 −0.707 0 0


𝑠𝑖𝑛45 0 0] = 0.707
[ 0.707 0 0]
𝑅 (
𝑐𝑜𝑠45450)
= [
𝑧 0 0 1 0 0 0 1 0
0 0 0 1 0 0 0 1
Now,

A B C D E F G H
0.707 −0.707 0 0 0 10 10 0 0 10 10 0
[ 0.707 0.707 0 0 ] 0 0 10 10 0 0 10 10] =
0 0 [
1 0 0 0 0 0 10 10 10 10
0 0 0 1 1 1 1 1 1 1 1
1
(Complete yourself)

 3D Viewing
In 3D viewing, we specify a view volume in the world, a projection onto a projection plane,
and a viewport on the view surface. Conceptually, objects in 3D world are clipped against the
3D view volume and are then projected. The contents of the projection of the view volume
onto the projection plane, called the window, are then transformed (mapped) into the
viewport for display.
Viewing in 3D involves the following considerations:
- We can view an object from any spatial position. E.g. In front of an object,
Behind the object, In the middle of a group of the objects, Inside an object.
- 3D descriptions of objects must be projected onto the flat viewing surface of
the output device.
- The clipping boundaries enclose a volume of space.
3D Viewing Pipeline

Modeling transformation and viewing transformation can be done by 3D transformations.


The viewing-coordinate system is used in graphics package as a reference for specifying the
observer viewing position and the position of the projection plane. Projection operations
convert the viewing-coordinate description (3D) to coordinate position on the projection
plane (2D). (Usually combined with clipping, visual-surface identification, and surface
rendering). Normalization transformation & clipping and view port transformation maps the
coordinate positions on the projection plane to the output device.

 Projection

- Projection is any method of mapping three dimensional (3D) objects into two
dimensional (2D) view plane (screen). In general, projection transforms a N-
dimension points to N-1 dimensions.
- Two types of projection:
a) Parallel projection:
In parallel projection, coordinate positions are transformed to view plane along
parallel line.
- A parallel projection preserves relative proportion of objects so that
accurate views of various sides of an object are obtained but doesn’t give
realistic representation of the 3D objects.
- Can be used for exact measurement so parallel lines remain parallel.
View plane

𝑃′(𝑥′
2 2 , 𝑦′
2 )

𝑃′(𝑥′
1 1 , 𝑦′)
1

Fig: Parallel projection of an object to the view plane


b) Perspective projection:
In perspective projection, objects positions are transformed to the view plane along
lines that converge to point behind view plane.
- A perspective projection produces realistic views but does not preserve
relative proportions. Projections of distance objects from view plane are
smaller than the projections of objects of the same size that are closer to the
projection place.

𝑃2

𝑃1
View plane

𝑃′2

𝑃′1

Convergence
point
Fig: Perspective projection of an object to the view plane
 Parallel projection
On the basis of angle made by projection line with view plane, there are two types of parallel
projection.
i. Orthographic parallel projection
ii. Oblique parallel projection

i. Orthographic parallel projection


- When the projection lines are perpendicular to view plane, the projection
is orthographic parallel projection.
𝑦

Here, after projection of 𝑃(𝑥, 𝑦, 𝑧) on XY-plane we get 𝑃′(𝑥′, 𝑦′) where,


𝑥′ = 𝑥, 𝑦′ = 𝑦 & z=0

In homogenous coordinate form,


𝑥 1 0 0 0 𝑥

0 1 0 0 𝑦
𝑦

[ ] =[ ][ ]
𝑧 ′ 00 1 0 1𝑧
1 0 0 0 1

ii. Oblique parallel projection


- Here, projection lines make certain angle to view plane.
- Oblique projection is specified with two angle ‘α’ & ‘ϕ’ where ‘α’ is the angle

oblique projected point 𝑃′(𝑥𝑝, 𝑦𝑝) and orthogonal projected point 𝑃′′(𝑥, 𝑦)
made by projection line with view plane line (L) which is formed by joining

on point (x, y) on view plane & ‘ϕ’ is the angle between ‘L’ & horizontal
direction of view plane.
𝑦

𝑥
L
ϕ

The projected point 𝑃′(𝑥𝑝, 𝑦𝑝) on XY plane is given by,


z

𝑥𝑝 = 𝑥 + 𝐿𝑐𝑜𝑠𝜃

𝑦𝑝 = 𝑦 + 𝐿𝑠𝑖𝑛𝜃

Since 𝑡𝑎𝑛 𝖺=
𝑍

∴ 𝑥𝑝 = 𝑥 + 𝑧𝑐𝑜𝑡𝛼 𝑐𝑜𝑠ϕ

𝑦𝑝 = 𝑦 + 𝑧𝑐𝑜𝑡𝛼 𝑠𝑖𝑛ϕ
In homogenous matrix form
𝑥𝑝
𝑦𝑝 1 10 𝑐𝑜𝑡𝛼 𝑐𝑜𝑠ϕ 0
0 𝑥
[ ]=[ 𝑐𝑜𝑡𝛼 0 𝑦
𝑠𝑖𝑛ϕ ]
𝑧𝑝 0 1 [ ]
0 𝑧
0 1 1
1 0 1
0
 Perspective projection
Let 𝑃(𝑥, 𝑦, 𝑧) be projected on X-Y view plane by perspective projection at 𝑃′(𝑥′, 𝑦′, 𝑧′)
& projected line converges point ‘y’ an z-axis at is distance ‘d’ from XY view plane.

View
A plane

Convergence
point
𝑦
Y
𝑧 𝑑
M O
-z

𝑥 𝑥′
C

We have to find the value of 𝑃’(𝑥’, 𝑦’, 𝑧’) from similar triangle NMY & COY.
x

𝑁𝑀 𝐶𝑂
=
𝑀𝑌 𝑂𝑌
𝑥 𝑥′
=
𝑧+𝑑 𝑑
𝑑
∴ 𝑥′ = 𝑥
𝑧+𝑑
Similarly, from similar triangle AMY & BOY
𝐴𝑀 𝐵𝑂
=
𝑀𝑌 𝐵𝑌
𝑦 𝑦′
=
𝑧+𝑑 𝑑
𝑑
∴ 𝑦′ = 𝑦
𝑧+𝑑
Difference between Parallel and Perspective Projection
Parallel Projection Perspective Projection
Coordinate position of object are transferred Coordinate positions are transferred into view
into view plane along parallel line. plane along lines that converges to a point
called convergence point.
Relative proportion of object are maintained. Relative position not maintained.
It gives accurate view of object. If view plane is nearest to object image appear
larger & if view plane is farther image
appear smaller.
It doesn’t give realistic view of object. It gives more realistic view of object as perceived
by human eye.
Used in engineering and architectural Used in building design, rail track design, whose
drawing. realistic view is needed.

References
- Donald Hearne and M.Pauline Baker, “Computer Graphics, C Versions.”
Prentice Hall

You might also like