Chapter
Chapter 5 5
Chapter 5. 3D Transformations
5.1 Introductions
5.2 Coordinate systems. Homogenous coordinates
5.3 3D transformation matrices
5.4 Composing transformations
Computer Graphics Chapter 5. 3D Transformations 1
5.1 Introduction
• 3D transformations are common in:
– Object manipulation in 3D space
• Translation, rotating and scaling
– A help when visualizing objects
Computer Graphics Chapter 5. 3D Transformations 2
5.2 Coordinate systems. Homogenous coordinates
– Coordinate systems can be
• Right-handed (the one we are going to use in the transformations)
• Left-handed
Z axis points outside the paper Z axis points inside the paper
left-handed
right-handed
Computer Graphics Chapter 5. 3D Transformations 3
5.2 Coordinate systems. Homogenous coordinates
• As it was done in 2D, homogenous coordinates are used
– A 3D point (x, y, z) is represented by (x, y, z, w) and as column vector
– Transformation matrices will be, therefore, 4x4
– Matrices will pre-multiply the input points
Computer Graphics Chapter 5. 3D Transformations 4
5.3 3D transformation matrices
• Translation • Rotation
– X axis
• Scaling – Y axis
– Z axis
Computer Graphics Chapter 5. 3D Transformations 5
5.3 3D transformation matrices
Example:
Y
0010
Ry(Π/2) = 0100
-1 0 0 0
0001
(1,0,0)
0 1
X
0 0
Π/2 Ry(Π/2) =
1 0
Z 1 1
Computer Graphics Chapter 5. 3D Transformations 6
5.4 Composing transformations
• In order to rotate around an arbitrary axis, the following steps have to be carried out:
– A translation to force the axis to pass through origin
– Rotate the axis in order to match it with one of the main coordinate axes
– Carry out the desired rotation around the main coordinate axis
– Apply the reverse rotations in order to leave the axis to its original orientation
– Apply reverse translation in order to leave the axis to its original position
Y Y Y Y
Eje de rotación
X X X X
Z Z Z
Z
Computer Graphics Chapter 5. 3D Transformations 7
5.4 Composing transformations
Example
Y Y
P3
P3
P2
P1
P1
P2
Z Z
INITIAL POSITION X FINAL POSITION X
Steps:
1. Translate P1 to origin
2. Rotate around Y, so P1P2 is over the plane (Y,Z)
3. Rotate around X, so P1P2 matches Z axis
4. Rotate over Z, so P1P3 is over the plane (Y,Z)
Computer Graphics Chapter 5. 3D Transformations 8
5.4 Composing transformations
• Translating P1 (x1,y1,z1) to origin Y
1 0 0 -x1
P3’
0 1 0 -y1
T= 0 0 1 -z1
0 0 0 1
P2’ (x2’,y2’,z2’)
P1’
θ
D1
Z
X
(x2’,0,z2’)
• Rotate around Y an angle of -(90 - θ)
cos(θ - 90) = senθ = z2’/D1 = (z2 - z1)/D1
sen(θ - 90) = -cosθ = -x2’/D1 = -(x2 - x1)/D1
where
D1 = (z2’)2 + (x2’)2 = (z2 - z1)2 + (x2 - x1)2
Computer Graphics Chapter 5. 3D Transformations 9
5.4 Composing transformations
• Rotating around X Y
y2’’
P2’’
D2
φ P1’’
Z z2’’
X
Y
• Rotating around Z
y3’’’
P3’’’ α
D3
P1’’’ x3’’’
Z P2’’’
X
Computer Graphics Chapter 5. 3D Transformations 10