CG 4
CG 4
CG 4
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
𝑥′ = 𝑥𝑐𝑜𝑠𝜃 − 𝑦𝑠𝑖𝑛𝜃
𝑦′ = 𝑥𝑠𝑖𝑛𝜃 + 𝑦𝑐𝑜𝑠𝜃
𝑧′ = 𝑧
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 y
|𝑣⃗→| ,
u
x
�
�
Where, 𝑑 = √𝑏2 + 𝑐2
z
b) Rotate by angle β about y axis that brings 𝑢⃗→ on z-axis. y
𝛽
x
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)
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
𝑥 𝑧 𝑦 𝑥
𝑦 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
For scaling of point P(x, y, z) w.r.t to fixed point (𝑥𝑓, 𝑦𝑓, 𝑧𝑓) can be represented with the
3D Reflection
In 3D-reflection the reflection takes place about a plane.
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]
𝑥′′ 1 𝑠ℎ𝑥 0 0 𝑥
𝑦 0 1 0 0 𝑦
[ ′] = [ ][ ]
𝑧 0 𝑠ℎ𝑧 1 0 1𝑧
1 0 0 0 1
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)
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
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
𝑃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
[ ] =[ ][ ]
𝑧 ′ 00 1 0 1𝑧
1 0 0 0 1
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
ϕ
𝑥𝑝 = 𝑥 + 𝐿𝑐𝑜𝑠𝜃
𝑦𝑝 = 𝑦 + 𝐿𝑠𝑖𝑛𝜃
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