Académique Documents
Professionnel Documents
Culture Documents
What
Given a 2D object, transformation is to change the
o je t s
How to implement
2 ways
Geometric Transformation
Alter the coordinates descriptions of an object
Coordinate system unchanged
Coordinate transformation
Produce a different coordinate system
2D Geometrical Transformations
Translate
Shear
Rotate
Scale
Translation
A translation moves all points in an object along the
same straight-line path to new positions.
The path is represented by a
vector, called the translation or
shift vector.
We can write the components:
X = X+ tx
Y= Y+ ty
or in matrix form: P' = P + T
x
y
x
y
tx
ty
P =
ty
P (x,y)
tx
, ?
Translation
How to translate an object with multiple
vertices?
Translate individual
vertices
Rotation
Repositioning the object along the circular path.
x = r cos (f)
y = r sin (f)
= r cos (f + q)
= r si f + q)
=
cos(q) y sin(q)
cos(q) + x sin(q)
x cos q
y sinq
sinq x
cos q y
P(x,y)
q
r
f
x
P' = R P
Rotation
Rotate individual
Vertices
Scaling
Changing the size of an object by two scaling factors, Sx and
Sy for the x- and y- coordinates respectively.
X = sx * X
Y = sy * Y
x sx
y 0
0 x
sy y
Combining transformations
We have a general transformation of a point:
P' = M P + A
When we scale or rotate, M
We set
A
Additive identity.
When we translate,
M
Multiplicative identity
A
We set
To combine multiple transformations,
we must explicitly compute each transformed point.
But it d be nicer if we could use the same matrix operation all the
time.
So e d ha e to combine multiplication and addition into a single
operation.
26 August 2014
10
Homogenous Coordinates
y
y
w
x
Homogenous Coordinates
We can always map back to the original 2D point
by dividing by the last coordinate
(15 , 6, 3 )
( 5 , 2).
(60, 40, 10) ?.
Now we use 1 for the last coordinate
x
Point in column-vector:
y
1
Our point now has three coordinates.
So our transformation matrix needs to be 3 x 3
Matrix Representation
Translation :
Rotation :
Scaling :
x 1 0 t x x
y 0 1 t y
y
1 0 0 1 1
x cos q
y sin q
1 0
x s x
y 0
1 0
sin q
cos q
0
0
sy
0
0 x
0 y
1 1
0 x
0 y
1 1
Composite Transformation
We can represent any sequence of transformations
as a single matrix called as composite transformation
matrix .
Composite transformations:
Two successive Translation
Two successive Rotation
Two successive Scaling
Rotate about an arbitrary point
Scale about an arbitrary point
General composite transformation
(according to problem)
P' T (t x 2 , t y 2 ) *T (t x1 , t y1 ) * P
T21
1 0 t x 2 1 0 t x1
0 1 t 0 1 t
y2
y1
0 0 1 0 0 1
T (t x1 , t y1 )
1 0 t x1 + t x 2
0 1 t y1 + t y 2
0 0
1
R21
T (t x 2 , t y 2 )
q2 q
1
cos(q 2 + q1 ) sin(q 2 + q1 ) 0
sin(q 2 + q1 ) cos(q 2 + q1 ) 0
0
0
1
S (sx 2 , s y 2 )
S ( s x1 , s y1 )
sx 2 0 0 sx1 0 0
S 21 0 s y 2 0 0 s y1 0
0 0 1 0 0 1
0
0
sx 2 * sx1
s y 2 * s y1 0
0
0
0
1
Order of operations
So, it does
1.
2.
Translate
Rotate
Rotate
Translate
Reflection
Produce mirror image of the object by rotating the
o je t a out a a is of refle tio
a a gle 8
Reflection axis on x-y
plane
X-Axis
Y- Axis
X=y line
Any line
Reflection axis
perpendicular to x-y
plane
Axis passing through origin
Axis passing through any
pivot point
Reflection
Axis on x-y Plane
1. x-axis
1 0 0
Re fx 0 1 0
0 0 1
2. y-axis
1 0 0
Re fy 0 1 0
0 0 1
Reflection
3. About line x=y
0 1 0
Re fx y 1 0 0
0 0 1
Reflection
Axis perpendicular to x-y Plane
1. At origin
2. At any
pivot point
(px,py)
1 0 Px 1 0 0 1 0 Px
1 0 0
Re fpivot 0 1 Py 0 1 0 0 1 Py
Re forigin 0 1 0
0 0 1 0 0 1 0 0 1
0 0 1
Shear
Distorts the shape such that the transformed shape appears
that the object composed of internal layers that cause to slide
over each other
x-direction
x 1 shx
y 0 1
1 0 0
y-direction
0 x
0 * y
1 1
x 1
y sh
y
1 0
0 0 x
1 0 * y
0 1 1
Coordinate Transformation
Translation
P X ,Y
x
y
tx
ty
P(X,Y)
Ty
X
Tx
Rotation
x = r cos (f)
y = r sin (f)
= r cos (f q)
= r si f q)
=
cos(q) + y sin(q)
cos(q) - x sin(q)
P X ,Y
P(X,Y)
Y
r
f-q
x cos q sin q x
y sin q cos q y
Viewport
Area on the display device to which a window is
mapped
Where it is to be displayed
27
Viewport Transformation
Window-to-Viewport Mapping
Window
wy2
vy2
(wx, wy)
wy1
wx1
Viewport
(vx, vy)
vy1
vx1
wx2
Screen Coordinates
vx2
Image Coordinates
Clipping
Avoid Drawing Parts of Primitives Outside
Window
Points
Lines
Polygons
Circles
etc.
29
Point Clipping
Is Point(x,y) Inside the Clip Window?
wymax
Inside =
(x>=wxmin)
&&
(x<=wxmax)
&&
(y>=wymin)
&&
(y<=wymax);
(x, y)
wymin
wxmin
wxmax
30
Line Clipping
Find the Part of a Line Inside the Clip Window
P7
P1
P4
P8
P3
P2
P6
P5
P10
P9
Before Clipping
31
Line Clipping
Find the Part of a Line Inside the Clip Window
P7
P4
P3
P6
P5
After Clipping
32
P8
P8
P3
P2
P6
P10
P5
P9
33
0000
P3
P2
P8
0010
P6
0101
Bit 4
P5
P10
0100
34
P9
0110
Bit 3
Bit 2
0000
P3
P2
P8
0010
P6
0101
Bit 4
P5
P10
0100
35
P9
0110
Bit 3
Bit 2
P8
0010
0000
P3
P6
0101
Bit 4
P5
P10
0100
36
P9
0110
Bit 3
Bit 2
P8
0010
0000
P3
P6
0101
Bit 4
P5
P10
0100
37
P9
0110
Bit 3
Bit 2
P8
0010
0000
P3
P6
0101
Bit 4
P5
P10
0100
38
P9
0110
Bit 3
Bit 2
P8
0010
0000
P3
P6
P5
0101
P10
0100
Bit 4
39
P9
0110
Bit 3
Bit 2
P8
0010
0000
P3
P6
P5
0101
P10
0100
Bit 4
40
P9
0110
Bit 3
Bit 2
P8
0010
0000
P3
P6
P5
0101
P10
0100
Bit 4
41
P9
0110
Bit 3
Bit 2
P8
0010
0000
P3
P6
P5
0101
P10
0100
Bit 4
42
P9
0110
Bit 3
Bit 2
P8
0010
0000
P3
P6
P5
0101
P10
0100
Bit 4
43
P9
0110
Bit 3
Bit 2
P8
0010
0000
P3
P6
P5
0101
P10
0100
Bit 4
44
P9
0110
Bit 3
Bit 2
0000
P3
P8
0010
P6
P5
0101
P10
0100
Bit 4
45
P9
0110
Bit 3
Bit 2
0000
P3
P8
0010
P6
P5
0101
P10
0100
Bit 4
46
P9
0110
Bit 3
Bit 2
0000
P3
P8
0010
P6
P5
0101
P10
0100
Bit 4
47
P9
0110
Bit 3
Bit 2
0000
P3
P8
0010
P6
P5
0101
P10
0100
Bit 4
48
P9
0110
Bit 3
Bit 2
0000
P3
P8
0010
P6
P5
0101
P10
0100
Bit 4
P90110
Bit 3
49
Bit 2
0000
P3
P8
0010
P6
P5
0101
P10
0100
Bit 4
P90110
Bit 3
50
Bit 2
0000
P3
P8
0010
P6
P5
0101
Bit 2
0100
Bit 4
0110
Bit 3
51
Sutherland-Hodgman
Polygon Clipping
outside inside
v2
outside inside
v2
v1
Inside to inside:
Output: v2
v2
v1
v1
Outside to inside:
Output:
a d
outside inside
Inside to outside:
Output:
v1
Outside to outside:
Output: nothing
Sutherland-Hodgman Clipping
Edge from s to p takes one of four cases:
inside
outside
inside
outside
inside
outside
p
p
p output
54
inside
p
s
i output
no output
i output
p output
outside
s
Sutherland-Hodgman Clipping
Basic idea:
Consider each edge of the viewport individually
Clip the polygon against the edge equation
After doing all planes, the polygon is fully clipped
55
Sutherland-Hodgman Clipping
Basic idea:
Consider each edge of the viewport individually
Clip the polygon against the edge equation
After doing all planes, the polygon is fully clipped
56
Sutherland-Hodgman Clipping
Basic idea:
Consider each edge of the viewport individually
Clip the polygon against the edge equation
After doing all planes, the polygon is fully clipped
57
Sutherland-Hodgman Clipping
Basic idea:
Consider each edge of the viewport individually
Clip the polygon against the edge equation
After doing all planes, the polygon is fully clipped
58
Sutherland-Hodgman Clipping
Basic idea:
Consider each edge of the viewport individually
Clip the polygon against the edge equation
After doing all planes, the polygon is fully clipped
59
Sutherland-Hodgman Clipping
Basic idea:
Consider each edge of the viewport individually
Clip the polygon against the edge equation
After doing all planes, the polygon is fully clipped
60
Sutherland-Hodgman Clipping
Basic idea:
Consider each edge of the viewport individually
Clip the polygon against the edge equation
After doing all planes, the polygon is fully clipped
61
Sutherland-Hodgman Clipping
Basic idea:
Consider each edge of the viewport individually
Clip the polygon against the edge equation
After doing all planes, the polygon is fully clipped
62
Sutherland-Hodgman Clipping
Basic idea:
Consider each edge of the viewport individually
Clip the polygon against the edge equation
After doing all planes, the polygon is fully clipped
63
Sutherland-Hodgman Clipping
Basic idea:
Consider each edge of the viewport individually
Clip the polygon against the edge equation
After doing all planes, the polygon is fully clipped
64