2 Dtransform
2 Dtransform
homogeneous coordinates
Dr Nicolas Holzschuch
University of Cape Town
e-mail: [email protected]
Before After
Translations: vector notation
• Use vector for the notation:
– makes things simpler
• A point is a vector: x
y
• A translation is merely a vector sum:
P’ = P + T
Scaling in 2D
• Coordinates multiplied by the scaling
factor:
• x’ = sx x
• y’ = sy y
Before After
Scaling in 2D, matrix notation
• Scaling is a matrix multiplication:
P’ = SP
Before After
Rotating in 2D, matrix notation
• A rotation is a matrix multiplication:
P’=RP
x x wt x
y y wt y
w w
Scaling with homogeneous
x sx
y 0
0 0x
s
x
w
x
x w
sy 0y
y
s
w
0 0 1
w
y
w y w
x sx x
y sy y
w w
Rotation with homogeneous
x cos sin 0x
y sin cos 0y
xw cos wx sin y
w
0 0 1
w
y
w
P’=(-TQ)RTQ P
Beware!
• Matrix multiplication is not commutative
• The order of the transformations is vital
– Rotation followed by translation is very different
from translation followed by rotation
– careful with the order of the matrices!
• Small commutativity:
– rotation commute with rotation, translation with
translation…
From World to Window
• Inside the application:
– application model
– coordinates related to the model
– possibly floating point
• On the screen:
– pixel coordinates
– integer
– restricted viewport: umin/umax, vmin/vmax
From Model to Viewport
ymax
ymin
xmin xmax
From Model to Viewport
• Model is (xmin,ymin)-(xmax,ymax)
• Viewport is (umin,vmin)-(umax,vmax)
• Translate by (-xmin,-ymin)
• Scale by ( xmax-xmin
umax-umin
, vmax-vmin )
ymax-ymin
• Translate by (umin,vmin)
M = T’ST
From Model to Viewport