1
Three dimensional transformations
Doron Nussbaum COMP 3501 - 3D transformations 1
Object Manipulation
• Graphics primitives allows us to draw a variety f i t i d hof pictures, images and graphs
• In many application there is a also need to manipulate the displays – Rearranging the display
– Changing the size of the different objects
Doron Nussbaum COMP 3501 - 3D transformations 2
Changing the size of the different objects
• This is accomplished by using geometric transformations
2
Doron Nussbaum COMP 3501 - 3D transformations 3
Rotate right by 90o
Translate to position
Doron Nussbaum COMP 3501 - 3D transformations 4
Scale down to 2/3 of sizeRotate right by 60o
Translate to position
3
Basic Geometric Transformation
• The basic geometric transformation are:– Translation
– Scaling
– Rotation
• Other
Doron Nussbaum COMP 3501 - 3D transformations 5
• Other – Reflection
– Shear
Rotation
• Rotation of an object is repositioning it along a circular path in the xy planecircular path in the xy plane.
• A rotation is specified by a rotation angle and a pivot point (rotation point) p
20
Doron Nussbaum COMP 3501 - 3D transformations 65
10
15
5
201510
p
4
2D Rotation
• The angle is defined in a counter clockwise d d th i torder around the point p (counter clockwise is positive angle
and clockwise is negative angle)
• The rotation can also be viewed as rotation around an axis line perpendicular to the xyplane through the point p
Doron Nussbaum COMP 3501 - 3D transformations 7
• Assuming rotation around the origin (0,0)
(x,y)
(x’,y’)
r
r
Doron Nussbaum COMP 3501 - 3D transformations 8
cossinsincos)sin('
sinsincoscos)cos('
rrry
rrrx
5
cossinsincos)sin('
sinsincoscos)cos('
rrry
rrrx
cossin'
sincos'
obtain we
sin and cos
Since
cossinsincos)sin(
yxy
yxx
ryrx
rrry
Doron Nussbaum COMP 3501 - 3D transformations 9
cossin yxy
cossin
sincos),()','( yxyx
Rotation around point p
coscos x-αrrx
cos)(sin)('
sin)(cos)(
sinsincoscos
)cos('
sin sin
cos cos
y-x-αy
y-x-α
rr
rx
y-rry
x αrrx
(x,y)
(x’,y’)
r
r
( )
Doron Nussbaum COMP 3501 - 3D transformations 10
()
),(cossin
sincos),()','(
yxyx
6
Matrix Transforms
• For "simplicity", we want to represent our t f t i titransforms as matrix operations
• Why is this simple?– single type of operation for all transforms
– IMPORTANT: collection of transforms can be expressed as a single matrix
Doron Nussbaum COMP 3501 - 3D transformations 11
expressed as a single matrix• efficiency
Homogenous CoordinatesMotivation
• In many cases, e.g., animation, we need to combine a number of basic transformations such as a rotationnumber of basic transformations such as a rotation followed by a translation
P’=RP + T
• R is a 3x3 matrix while T is a 3x1 matrix
Doron Nussbaum COMP 3501 - 3D transformations 12
• The rotation operation is multiplication operation while the translation operation is an addition
7
Homogenous Computations
• How to speed up the process and to avoid long i ( ll th t th b th dprocessing (recall that there can be thousands
of vertices in an image)?
• Idea:use a single matrix operation for all types of
Doron Nussbaum COMP 3501 - 3D transformations 13
– use a single matrix operation for all types of transformations (rotation, scaling, translation)
• Instead of using triplet of coordinates (x, y, z) f h t ( ) hfor each vertex use a (xw,yw,zw,w) where
zw
yw
xw
z
y
x
zyx wz
wy
wx www toleads which , ,
Doron Nussbaum COMP 3501 - 3D transformations 14
• There are many choices for w (normally w=1)
w
8
Translation
• Purpose: to move an object along a line from one location to another locationlocation to another location
Doron Nussbaum COMP 3501 - 3D transformations 15
Translation Matrix
0010
0001
• This is a rigid transformation - objects are not d f d
1TTT
0100
0010)1,,,()1,',','(
zyx
zyxzyx
}|{' ptp
Doron Nussbaum COMP 3501 - 3D transformations 16
deformed.
• Enough to translate the vertices (end points)
9
Rotation around point p2D Homogenous Coordinates
coscos x-αrrx
cos)(sin)('
sin)(cos)(
sinsincoscos
)cos('
sin sin
cos cos
y-x-αy
y-x-α
rr
rx
y-rry
x αrrx
Doron Nussbaum COMP 3501 - 3D transformations 17
1
010
001
100
0cossin
0sincos
1
010
001
)1,,()1,','(
yxyx
3D Rotation Matrices
0100
00cossin
00sincos
)1,,()1,','(
yxyxRotation around Z axis
1000
0cos0sin
0010
0sin0cos
)1,,()1,','(
yxyx
1000
0100
Rotation around Y axis
Doron Nussbaum COMP 3501 - 3D transformations 18
1000
0cossin0
0sincos0
0001
)1,,()1,','(
yxyxRotation around X axis
10
Scaling
• A scaling transformation alters the size of an object.
• The operation is accomplished by multiplying each coordinate by scaling factors sx, sy sz :
• When sx (sy, sz) > 1 we enlarge the object
• When sx (sy, sz) < 1 we reduce the object
000xS
Doron Nussbaum COMP 3501 - 3D transformations 19
1000
000
000)1,,()1,','(
z
y
S
Syxyx
3D Matrices
• Pay attention to:Concatenating matrices (e g rotation translation) to– Concatenating matrices (e.g., rotation, translation) to which side you should concatenate.
– Note Direct3D multiplies the vector on the left side (VT*M) vs. open GL which multiplies the vector on the right hand side similar to what is done in mathematics (M*V), where V is a 4x1 vector and M is a 4x4 matrixa 4x4 matrix.
– The difference in the sign before the sin(θ) when the rotation is around the y-axis vs. rotation around the x-axis and z-axis
Doron Nussbaum 3D transformations 20
11
Compound Objects Concatenation
• Done on the board in class
Doron Nussbaum COMP 3501 - 3D transformations 21
Transformation between coordinate systems
• Motivation:– objects are often defined within their own local coordinate– objects are often defined within their own local coordinate
systems which must be converted into a scene coordinate system.
– Often occurs when one buys 3D models from a modeller
• Example– For example a cubical consists of a desk, a workstation and
a chair is defined in a local coordinate system When an
Doron Nussbaum COMP 3501 - 3D transformations 22Doron Nussbaum 22
a chair is defined in a local coordinate system. When an office is designed the layout consists of multiple cubicles which are positioned in the office. The location of the desks, chairs and workstations must be defined using with respect to the office
12
Office Elements
Doron Nussbaum COMP 3501 - 3D transformations 23
Workstation
Office Layout
Office
Y-axis
Workstation
X-axis
Y-axis
X-axis
Y-a
xis
Doron Nussbaum COMP 3501 - 3D transformations 24X-axis
Workstation
X-axis
Y-a
xis Workstation
X-axis
Y-a
xis
13
• We want to know what will be the coordinates of p=(x y z) in the new coordinate systemp=(x,y,z) in the new coordinate system
• In order to accomplish this we need to– translate the new coordinate system to the origin of the
current coordinate system
Rotate the new coordinate system so that the axis overlap
Doron Nussbaum COMP 3501 - 3D transformations 25
– Rotate the new coordinate system so that the axis overlap
– Use the two transformation matrices to transform the object to the new coordinate system
Doron Nussbaum COMP 3501 - 3D transformations 26
Scaling using sx=sy=3
14
• Uniform scaling sx=sy
• Differential scaling sxsy
• Transformed objects using the matrix S are not only scaled but also change their position
Doron Nussbaum COMP 3501 - 3D transformations 27
• Show example
Composite Transformation
• What happens when we combine several t f titransformations (concatenation/composition)
– compute the product of two or more matrices to obtain the final transformation matrix
321 )))(((' MMPMP
Doron Nussbaum COMP 3501 - 3D transformations 2831
321
321
)(
))((
PM
MMP
MMMP
15
Concatenation of Similar Transformations
• Translation
Hence,
100
10
01
100
10
01
100
10
01
21
21
1
1
2
2
yy
xx
y
x
y
x
tt
tt
t
t
t
t
Doron Nussbaum COMP 3501 - 3D transformations 29
),(),(),( 21211122 yyxxyxyx ttttTttTttT
• Rotation
PRR
PRRP
)()(
)()('
12
12
Show a picture of two rotations
Doron Nussbaum COMP 3501 - 3D transformations 30
)()()(
Hence,
1212 RRR
rotations
16
• Scaling
Hence
100
00
00
100
00
00
100
00
00
12
12
1
1
2
2
yy
xx
y
x
y
x
ss
ss
s
s
s
s
Doron Nussbaum COMP 3501 - 3D transformations 31
),(),(),(
Hence,
21211122 yyxxyxyx ssssSssSssS
Pivot Point Rotation
• So far all the transformations assumed that they are done around the origin (0 0)done around the origin (0,0)
• This can be generalized to any arbitrary point as follows– Translate the object to the origin such that the pivot point is
at the origin
– Transform the object around the origin (e g rotation)
Doron Nussbaum COMP 3501 - 3D transformations 32
Transform the object around the origin (e.g., rotation)
– Use inverse translation used in step 1 to move the object back to its original position
17
Example Rotate by 45o around p
p =(x,y) p
Translate to the origin - T(-x,-y)
Doron Nussbaum COMP 3501 - 3D transformations 33
p
Rotate by 45o - R(45)T(-x,-y)
p
Translate back to p - T(x,y) R(45)T(-x,-
Example Rotate by 45o around p
( )p =(x,y)
Translate to the origin - T(-x,-y)
p =(x,y)
Doron Nussbaum COMP 3501 - 3D transformations 34Rotate by 45o - R(45)T(-x,-y) Translate back to p - T(x,y) R(45)T(-x,-y)
p =(x,y) p =(x,y)
18
2D example
010sincos01
i)1(i
100
10
01
100
0cossin
0sincos
100
10
01
r
r
r
r
y
x
y
x
Doron Nussbaum COMP 3501 - 3D transformations 35
100
sin)cos1(cossin
sin)cos1(sincos
rr
rr
xy
yx
Scaling with respect to a fixed point
• Similar procedure is used to scale with respect t fi d i t
100
10
01
100
00
00
100
10
01
r
r
y
x
r
r
y
x
S
S
y
x
to a fixed point
p =(x,y)
Doron Nussbaum COMP 3501 - 3D transformations 36
100
)1(0
)1(0
yrx
xrx
SyS
SxS
Translate to the origin -T(-x,-y)
Rotate by 45o - R(45)T(-x,-y) Translate back to p -T(x,y) R(45)T(-x,-y)
p =(x,y) p =(x,y)
19
General Scaling -scaling with respect to a line
• The scaling matrix allows only scaling along the x-axis and the y-scaling along the x axis and the yaxis.
• How to scale with respect to any line?
y s2
Doron Nussbaum COMP 3501 - 3D transformations 37
x
s1
General Scaling
• We use a similar technique to use any scaling in any direction.– Rotate the object such that the scaling direction coincide with the x-yRotate the object such that the scaling direction coincide with the x y
axis.
– Scale the object
– rotate back
Doron Nussbaum COMP 3501 - 3D transformations 38Scale at = 45o and sx=1 sy=2
20
Transformation are not commutative
Doron Nussbaum COMP 3501 - 3D transformations 39
Translate and then rotate - R()T(x,y)e.g. R(45)T(5,0)
Rotate and then Translate - T(x,y) R()e.g. T(5,0) R(45)
Other Transformations
• Reflection– A transformation that produces a mirror image of
an object
– it is generated by rotating the object 180o around the axis of reflection
Doron Nussbaum COMP 3501 - 3D transformations 40
21
Reflection about the axis(x-axis or y-axis)
• a reflection about the x-axis
• a reflection about the y-axis
100
010
001
Doron Nussbaum COMP 3501 - 3D transformations 41
100
010
001
• Show a picture of reflection about the x-axis d i
Reflection about the origin(x-axis and the y-axis)
and y-axis
100
010
001
Doron Nussbaum COMP 3501 - 3D transformations 42
• This transformation can also be viewed as a rotation where =180o
22
Reflection about lines
• Line y=x
• It can be viewed as
100
001
010
Doron Nussbaum COMP 3501 - 3D transformations 43
– a rotation by -45o (CCW 45o)
– Reflection about the x-axis
– a rotation by 45o (CW 45o)
Reflection about a general line
• Reflection about a general line y=ax+ b is achieved as:– translate the object and the line such that the line passes through thetranslate the object and the line such that the line passes through the
origin - T(0,-b)
– rotate the object and the line such that it coincide with one of the axis
– apply the reflection transformation of that axis
– rotate the object and the line back using the inverse rotation
– translate the object and the line back using inverse transformation
Doron Nussbaum COMP 3501 - 3D transformations 44
23
Shear
• Shear transformation distorts the shape of the bj tobject.
• The effect causes the object to be pushed to one side as if it was constructed of layers that slide on top of each other
Doron Nussbaum COMP 3501 - 3D transformations 45
• (show picture)
• Shearing transformation along the x-axis
• example
yyyshxx'
sh
x
x
'
100
010
01
Doron Nussbaum COMP 3501 - 3D transformations 46
100
010
021 1,1
1
3,12,1
24
• Shearing transformation along the x-axis using a reference line
• example using a shearing along the x-axis of ½ and a reference line y=-1
yyyyshxx
yshsh
refx
refxx
' )('
100
010
1
Doron Nussbaum COMP 3501 - 3D transformations 47
100
010
1 21
21
-1
-1
1,12,11,1
1.5,00.5,0