'
3D Transformations
Translation Rotation Scaling Composite transformations Reection and shear Coordinate system transformations OpenGL transformation functions
&
1
'
3D Transformations
All the 2D transformations can be extended to three dimensions Translation and Scaling are extended by adding a third value for the z-direction Rotation in 3D is more complicated Homogeneous coordinates for 3 dimensions require 4 components. Any sequence of transformations can be represented as a composite of the individual transformations.
&
2
'
3D Translation
Represent a 3D translation by a 3-tuple whose components are the shifts in the x, y and z directions. (tx , ty , tz )
x y z
= x + tx = y + ty = z + tz
z (x, y, x)
(x, y, z) T = (tx, ty, tz) x
&
3
'
In matrix form, this is x 1 y 0 = z 0 1 0 or P = TP 0 1 0 0 0 0 1 0 tx x ty y tz z 1 1
&
4
'
3D Rotation
Can rotate about any arbitrary line in space. Easiest to visualize are rotations about one of the coordinate axes 2D rotation is equivalent to a 3D rotation about the z-axis A positive rotation about a coordinate axis is counterclockwise when viewed from the positive direction.
y
&
5
'
Rotation about Coordinate Axis
For a rotation about the z-axis, the x and y coordinates change in the same way as for a 2D rotation and the z coordinate is unchanged. x y z x cos y sin = z 0 1 0 sin cos 0 0 0 0 1 0 0 x 0 y 0 z 1 1 = x cos y sin = x sin + y cos = z
Rotations about other coordinate axes have a similar form. &
6
'
Cyclic Permutations
We can generate the matrices by doing a cyclic permutation of the coordinate parameters. x y z x
y z x
z y y
&
7
'
Rotation about x and y Axes
For a rotation about the x-axis, we get y z x = y cos z sin = y sin + z cos = x
For a rotation about the y-axis, we get z x y = z cos x sin = z sin + x cos = y
As in 2D, the inverse transformation can be obtained by replacing by . As before, R1 = RT &
8
'
Rotation About Line Parallel to Axis
Do this with a composite transformation 1. Translate rotation axis to coordinate axis 2. Rotate 3. Reverse the translation The composite transformation matrix is R() = T1 Rx () T
&
9
'
Transformation Sequence
translate
rot
atio
inverse translation
&
10
'
Rotation about an Arbitrary Line
Use the same general approach but need both a translation and a rotation to align Transformation sequence: 1. Translate rotation axis to intersect the origin 2. Rotate axis of rotation to align with a coordinate axis 3. Do the desired rotation about the coordinate axis 4. Reverse the rotation in step 2 5. Reverse the translation in step 1
&
11
'
Transformation Sequence
P2 P1 P 1 P2 P 2
P 1
P2 P 2 P 1 P1
P 1 P2
&
12
'
Specifying a Rotation Axis
Rotation axis can be dened by two points
Use these points to generate a vector V = = P2 P1 (x2 x1 , y2 y1 , z2 z1 )
P2 u P1
Now construct a unit rotation axis vector
u = = where a = c =
z1 z2 |V |
V |V |
(a, b, c) b =
y1 y2 |V |
x1 x2 |V | ,
and
&
13
'
Translation to the Coordinate Origin
1 0 T = 0 0
0 1 0 0
0 x1 0 1 0
y1 z1 1
&
14
'
Aligning Rotation and Coordinate Axes
In general, need two coordinate axis rotations to accomplish this alignment. One of several possible sequences 1. Rotate rotation axis about x-axis into x-z plane 2. Rotate about y-axis to align with z-axis
u= (0, b, c)
u = (a,b,c)
u z = (0,0,1) u = (a,0,d)
u z = (0,0,1)
&
15
'
Rotation Angles
is the angle between the projection of u onto the y-z plane and the z-axis is the angle between the projection of u onto the x-z plane and the z-axis Use dot and cross products to determine the sin and cos terms needed for the rotation matrices. u v = |u| |v| cos u v = |u| |v| sin 1 0 Rx () = 0 0 0
c d b d
0
b d c d
0 0 1
d 0 a 0 0 1 0 0 Rx () = a 0 d 0 0 0 0 1
where a, b and c are as dened earlier and d = &
16
b2 + c2 %
'
3D Scaling
Similar to those in 2D A 3D scaling matrix sx 0 0 0 s 0 y 0 0 sz 0 0 0
(xf, yf, zf)
translate
0 0 1
(xf, yf, zf)
scale
inverse
Example: Scaling relative to a xed point
translation (xf, yf, zf) (xf, yf, zf)
&
17
'
3D Reection
Reection can be performed relative to a reection axis or relative to a plane Reection relative to a line is eectively a 180 deg rotation about that line Reection relative to a plane is like a rotation in 4D - it is like a conversion between left-handed and right-handed coordinate systems.
y reflection relative to x-y plane z y
x z
&
18
'
3D Shear
Shear transformations are used for modifying shapes and for perspective transformations Similar to shearing in 2D for x and y-axis shears; can also have z-axis shear. A z-axis 1 0 0 0 shearing matrix 0 shzx 1 0 0 shzy 1 0 shzx zref Example: shzx = shzy = 1 and zref = (0, 0, 0)
shzy zref 0 1
shear
&
19
'
Ane Transformation
Transformations of the form x = axx x + axy y + axz z y = z = ayx x + ayy y + ayz z azx x + azy y + azz z
Parallel lines remain parallel. Finite points map to nite points. Any ane transformation can be expressed in terms of translation, rotation, scaling, reection and shear.
&
20
'
Coordinate Transformations
Scene processing in computer graphics involves transformations between different coordinate systems. Conversions between world and device coordinates Objects are often modeled in their own coordinate system Objects that are created from many simpler objects need coordinate transformations to properly orient the components. Two steps to this transformation in 2D 1. Translate the origin of one system to that of the other 2. Rotate to align the x-axes
&
21
'
Specifying a 2D Coordinate System
There are several ways of specifying one coordinate system relative to another one With the position of the origin and the angle between the x and x axes With the position of the origin and a vector in the direction of the y axis With the coordinates of two points
y axis
y s axi
y axis
s axi y s axi x s axi
y axis
s axi y s axi x
V y0 P0 x0
P1 y0 P0 x0
y0 x0 x axis
x axis
x axis
&
22
'
3D Coordinate Transformations
In 3D, need the equivalent of two orthogonal vectors to specify a coordinate system. (The third one is determined by the cross product of the original two.)
uz=u uy ux
Can use a coordinate system whose z-axis is the rotation axis to derive the transformation matrix for rotation about an arbitrary axis. &
23