Bresenham Algorithms

IT- 601: Computer Graphics
Lecture-09
Three - Dimensional Transformation
Jesmin Akhter
Lecturer,IIT
Jahangirnagar University,
Savar, Dhaka,Bangladesh
3D Point
•
We will consider points as column vectors.
Thus, a typical point with coordinates (x, y, z)
is represented as:
x
 
 y
z 
 
3D Point
• A 3D point P with coordinates (x, y, z) is
represented as:
x
 
 y
P 
z
 
1 
 
3D Transformation
•
3D transformations are represented by 4×4
matrixes:
a b
d e

g h

0 0
c
f
i
0
t

t

t

1
x
y
z
3D Coordinate Systems
• Right Hand
coordinate system:

Left Hand
coordinate system:
Three - Dimensional Transformation
• Manipulation, viewing and construction of three-dimensional
graphic images requires the use of three dimensional
geometric and coordinate transformations.
• These transformations are formed by composing the basic
transformations of translation, scaling and rotation.
• Each of these transformations can be represented as a matrix
transformation.
• Transformations are now represented as 4x4 matrices
• Geometric transformations
• Coordinate transformations
• Composite transformations
• Instance transformations
6
Three - Dimensional Transformation
• Very similar to 2D transformation
• Scaling transformation
 x   s x 0 0
  
 y   0 s y 0
 z    0 0 s
z
  
1 0 0 0
  
0  x 
 
0  y 
0  z 
 
1  1 
7
Geometric transformations
• Object moves
• Coordinate system remains stationary
• Basic transformations are translation, scaling and rotation.
• Translation
V V  D
• Scaling
V   SV
• Rotation
V   RV
Translation
• The amount of the translation is added to or
subtracted from the x, y, and z coordinates
• In general, this is done with the equations:
x  x  Tx
y   y  Ty
z   z  Tz
0 0 Tx   x 
1 0 Ty   y 
0 1 Tz   z 
 
0 0 1  1 
z
p ( x, y , z )
v
y
• This can also be done with the matrix
multiplication:
 x' 1
 y ' 0
 
 z '  0
  
 1  0
p' ( x' , y ' , z ' )
x
Scaling
• In general, this is done with the equations:
xn = sx * x
yn = sy * y
zn = sz * z
• This can also be done with the matrix multiplication:
 xn   s x
y   0
 n  
 zn   0
  
 1  0
0
0
sy
0
0
sz
0
0
0  x 
0  y 
*
0  z 
  
1  1 
III-10
Scaling
• Scaling
V   SV
 x'  S x
 y '  0
 
 z'  0
  
1  0
0
0
Sy
0
0
Sz
0
0
0  x 
0  y 
0  z 
 
1  1 
x  x  Sx
y  y  Sy
z  z  Sz
Rotation
• 3D rotation is done around a rotation axis
• Fundamental rotations – rotate about x, y, or z
axes
• Counter-clockwise rotation is referred to as
positive rotation .
y
z
+
x
12
Rotation
• The matrix form for rotation
– x axis
– y axis
0
 x  1
 y  0 cos 
 n  
 zn  0 sin 
  
0
 1  0
0
 sin 
cos 
0
0  x 
0  y 
*
0  z 
  
1  1 
 xn   cos 
y  0
 
 zn   sin 
  
1
0
,  
0 sin 
1
0
0 cos 
0
0
0  x 
0  y 
*
0  z 
  
1  1 
– z axis
 xn  cos 
 y   sin 
 n  
z  0
  
1  0
 sin 
cos 
0
0
0 0  x 
0 0  y 
*
1 0  z 
  
0 1  1 
x  x cos   y sin 
y  x sin   y cos 
z  z
13
Rotation
• Rotation about z – similar to 2D rotation
x'  x cos   y sin 
y '  x sin   y cos 
z'  z
 x   cos   sin 
  
 y   sin  cos 
 z    0
0
  
1  0
0
  
0 0  x 
 
0 0  y 
1 0  z 
 
0 1  1 
y
z
+
x
14
Rotation
• Rotation about y: z -> y, y -> x, x->z
z '  z cos   x sin 
x'  z sin   x cos 
0 sin 
0  x 
 
1
0
0  y 
0 cos  0  z 
 
0
0
1  1 
y
x
y'  y
 x   cos 
  
 y   0
 z     sin 
  
1  0
  
z
y
z
x
15
Rotation
• Rotation about x (z -> x, y -> z, x->y)
y '  y cos   z sin 
z '  y sin   z cos 
0
 sin 
cos 
0
0  x 
 
0  y 
0  z 
 
1  1 
z
y
x'  x
0
 x   1
  
 y   0 cos 
 z    0 sin 
  
 1  0
0
  
x
y
z
x
16
3D Reflections
About a plane:

A reflection through the
 x  1
 y  0
 
  z  0
  
 1  0

xy plane:
0  x 
1 0 0  y 
 
0  1 0  z 
  
0 0 1  1 
0
0
A reflections through the xz and the
yz planes are defined similarly.
Reflection
• Reflection through the xy-plane:
• Reflection through the yz-plane:
• Reflection through the xz-plane:
III-18
3D Coordinate Transformation
• Moving the observer who views the object
• Keeping the object stationary
19
3D Coordinate Transformation
• Transform object description from ij to ij
j
p
i
j
o ( x' , y' , z ' )
x   x  Tx
y   y  Ty
z   z  Tz
k'
o
i
k
20
Composite 3D Transformation
• Equivalent to matrix multiplication or concatenation.
• A series of transformations on an object can be
applied as a series of matrix multiplications.
21
Composition of transformations
 px 
 ax 
 
 
Rotate q degrees about axis a =  a y  through point p  p y 
 
 
 pz 
 az 
Composite 3D Transformation
• Scaling can be done relative to the object center with
a composite transformation
• Scaling an object centered at (cx, cy, cz) is done with
the matrix multiplication:
 xn  1
 y  0
 n  
 zn  0
  
 w  0
0 0 c x  s x
1 0 c y   0
*
0 1 cz   0
 
0 0 1 0
0
0
sy
0
0
sz
0
0
0  1
0 0
*
0 0
 
1 0
0 0  cx   x 
1 0  c y   y 
*
0 1  cz   z 
  
0 0
1  w 
III-23