Professional Documents
Culture Documents
Geometrical Transformation:
Let (A, B) be a straight line segment between the
points A and B.
Let T be a general 2D transformation.
T transforms (A, B) into another straight line segment
(A’, B’), where:
A’=TA and
B’=TB
Translation
• Translate(a, b): (x, y) → (x+a, y+b)
Translate(2, 4)
Scale
• Scale (a, b): (x, y) → (ax, by)
Scale (2, 3)
Scale (2, 3)
Scale
• How can we scale an object without
moving its origin (lower left corner)?
Translate(-1,-1)
Translate(1,1)
Scale(2,3)
Reflection
• Special case of scale
Scale(-1,1)
Scale(1,-1)
Rotation
• Rotate(θ):
(x, y) → (x cos(θ)+y sin(θ), -x sin(θ)+y cos(θ))
Rotate(90)
Rotate(90)
Rotation
• How can we rotate an object without
moving its origin (lower left corner)?
Translate(-1,-1)
Translate(1,1)
Rotate(90)
Shear
• Shear (a, b): (x, y) → (x+ay, y+bx)
Shear(1,0)
Shear(0,2)
Classes of Transformations
• Rigid transformation (distance preserving):
Translation + Rotation
• Similarity transformation (angle preserving):
Translation + Rotation + Uniform Scale
• Affine transformation (parallelism preserving):
Translation + Rotation + Scale + Shear
1 a x x + ay
b =
1 y y + bx
Rotation
• Rotate(θ):
(x, y) → (x cos(θ)+y sin(θ), -x sin(θ)+y cos(θ))
rotate translate
Translation
• Translation (a, b):
x x + a
y → y + b
Problem: Cannot represent translation
using 2x2 matrices
Solution:
Homogeneous Coordinates
Homogeneous Coordinates
Is a mapping from Rn to Rn+1:
( x , y ) → ( X , Y , W ) = ( tx , ty , t )
Inverse mapping:
X Y
( X ,Y ,W ) → ,
W W
Translation
• Translate(a, b):
1 0 a x x + a
0 1 b y = y + b
0 0 1 1 1
X
Example
Rotation about an arbitrary point
(x0,y0)
at ion
s f orm
x Tra
n
Example
• Change of coordinates: Represent P = (xp, yp, 1)
in the (x’, y’) coordinate system
P ' = MP
Where:
cos θ sin θ 0 1 0 − x
0
M = − sin θ cos θ 0 0 1 − y 0
0 0 1 0 0 1
y’ x’
y
θ
(x0, y0)
(xp, yp)
x
Example
• Change of coordinates:
Alternative method: assume x’ = (ux, uy) and
y’ = (vx, vy) in the (x, y) coordinate system
where
P ' = MP
u x u 0 1 0 − x
y
0
M = v x v y 0 0 1 − y 0
0 0 1 0 0 1
y’ x’
y
(vx, vy) (ux, uy)
(x0, y0)
x
Example
Reflection about an arbitrary line
p2
L = p1 + t (p2-p1) = t p2 + (1-t) p1
p1
p ing
m ap
:2 D
3 D
2D:2D mapping
Viewport
Device Coordinates
World to Viewing Coordinates
In order to define the viewing window we have to
specify:
•Windowing-coordinate origin P0 = (x0,y0)
•View vector up v = (vx,vy)
•Using v, we can find u: u = v x (0,0,1)
yv
ie w (vx,vy).
y world
(x0,y0)x v
ie w
(ux,uy).
x world
Transformation from world to viewing coordinates :
ux uy 0 1 0 − x0
M wc − vc = vx vy 0 0 1 − y 0
0
0 1 0 0 1
Window to Viewport Coordinates
(xmax,ymax)
(xmin,ymin)
(umaxn,vmaxn)
(umin,vmin)
1 sin θ x x + y sin θ
− sin θ =
1 y − x sin θ + y
Determinant of a Matrix
a b
= ad − bc
c d
a b c
d e f = aei + bfg + cdh − ceg − afh − bdi
g h i
e f d f d e
= a −b +c
h i g i g h