Title: Geometric Transformations
1Geometric Transformations
2Cartesian Coordinates
(10, 12)
10
12
Rene Descartes - 1637
3Cartesian Coordinates
(13, 15)
Rene Descartes - 1637
4Cartesian Coordinates
(13, 15)
(3, 3)
Rene Descartes - 1637
5Co-ordinate Systems
- Objects in computer graphics are given numerical
descriptions that characterize their shape and
dimensions. - These are in relation to some coordinate system,
most often Cartesian co-ordinates x,y and z
6Transforming Pictures
- Sometimes objects exhibit certain symmetries, so
only a part of it needs to be described, and the
rest constructed by reflecting, rotating and
translating the original part
7Example 1
- Object parts defined in a local co-ordinate
system - Larger objects are then assembled by
duplicating and transforming each of the
constituent parts
etc...
8Transforming Pictures
- Sometimes objects exhibit certain symmetries, so
only a part of it needs to be described, and the
rest constructed by reflecting, rotating and
translating the original part - A designer may want to view and object from
different vantage points, by rotating the object,
or by moving a synthetic camera viewpoint.
9Example 2
10Transforming Pictures
- Sometimes objects exhibit certain symmetries, so
only a part of it needs to be described, and the
rest constructed by reflecting, rotating and
translating the original part - A designer may want to view and object from
different vantage points, by rotating the object,
or by moving a synthetic camera viewpoint. - In animation, one or more objects must move
relative to one another, so that their local
co-ordinate systems must be shifted and rotated
as the animation proceeds.
11Example 3
5 steps of a rotating cube animation
- At each frame of the animation, the object is
transformed, in this case by a rotation. - It could also be transformed by changing its size
(scaling), or its shape (deforming), or its
location (translation). - Further animation effects can be achieved by not
changing the object, but the way it is viewed
zooming and panning the viewing window
12Transformations
- A transformation on an object is an operation
that changes how the object is finally drawn to
screen - There are two ways of understanding a
transformation - An Object Transformation alters the coordinates
of each point according to some rule, leaving the
underlying coordinate system unchanged - A Coordinate Transformation produces a different
coordinate system, and then represents all
original points in this new system - Both ways have advantages, and are closely
related to one another
13Example OBJECT TRANSFORMATION
.4, 2
1,1
Example COORDINATE TRANSFORMATION
(1,1)
(1,1)
142D Object Transformations
- A 2D object transformation alters each point P
into a new point Q using a specific formula or
algorithm. - It therefore alters the co-ordinates of P (Px,Py)
into new values which specify point Q (Qx,Qy) - This can be expressed using some function T, that
maps co-ordinate pairs into new co-ordinate
pairs - T (Px,Py) (Qx,Qy)
- sometimes simply denoted as T(P) Q
- e.g P is the point (2, 2), T is a transform that
scales by a factor of 2. Then T(P) T(2, 2)
(4,4)
P (Px, Py)
??? DO SOMETHING ???
Q (Qx, Qy)
P (2, 2)
Scale by 2
Q (4, 4)
15Affine Transformations
- Whole collections of points may be transformed by
the same transformation T, e.g. lines or circles - The image of a line, L, under T, is the set of
all images of the individual points of L. - For most mappings of interest, this image is
still a connected curve of some shape - For some mappings, the image of a line may no
longer be a line - Affine Transformations, however, do preserve
lines, and are the most commonly-used
transformations in computer graphics
P1 (0, 2)
P2 (2, 2)
P3 (2, 0)
P0 (0, 0)
Q1 (0, 4)
Q2 (4, 4)
Q0 (0, 0)
Q3 (4, 0)
16Elementary Transformations
- Affine transformations are usually combinations
of four elementary transformations - 1 Translation
- 2 Scaling
- 3 Rotation
- 4 Shearing
17Translation
- A translation moves an object into a different
position in a scene - This is achieved by adding an offset/translation
vector - So in Vector notation
t
Translate by t
Original points
Transformed points
18Scaling
- A scaling changes the size of an object with two
scale factors, Sx and Sy
Sx, Sy
Scale by Sx, Sy
Original points
Transformed points
19Rotation
- Using the trigonometric relations, a point
rotated by an angle q about the origin is given
by the following equations - So
q
Rotate by q
Original points
Transformed points
20Rotation - derivation
1
2
3
4
1
Substituting from 3 and 4
Similarly from 2
21Shearing
- A shearing shears an object in a particular
direction, (in 2D, its either in the x or in the
y direction - So, a shear in the x direction would be as
follows -
- The quantity h specifies what fraction of the
y-coordinate should be added to the x-coordinate,
and may be positive or negative - More generally a simultaneous shear in both the
x and y directions would be
22Shearing
g 0, h0.5
Shear by (g,h)
Original points
Transformed points
g0.5, h0.5
Shear by (g,h)
Original points
Transformed points
23Transformations Summary
- 1 Translation
- 2 Scaling
- 3 Rotation
- 4 Shearing
T
T
T
T
(Qx,Qy) (PxhPy, Py)
24Matrix Representation
- All affine transformations in 2D can be
generically described in terms of two generic
equations as follows -
-
- where a, b, c, d, tx and ty are all constants,
and ad bc - This can be represented with matrices as follows
- i.e.
25Matrix Multiplication
1x1
1x3
3x1
2x2
2x2
2x2
3x3
3x1
3x1
26Matrix Multiplication
1x1
1x3
3x1
2x2
2x2
2x2
3x3
3x1
3x1
27Matrix Multiplication
1x1
1x3
3x1
2x2
2x2
2x2
3x3
3x1
3x1
28Matrix Multiplication
1x1
1x3
3x1
2x2
2x2
2x2
3x3
3x1
3x1
29Matrix Multiplication
1x1
1x3
3x1
2x2
2x2
2x2
3x3
3x1
3x1
30Matrix Multiplication
1x1
1x3
3x1
2x2
2x2
2x2
3x3
3x1
3x1
31Matrix Multiplication
1x1
1x3
3x1
2x2
2x2
2x2
3x3
3x1
3x1
32Matrix Multiplication
1x1
1x3
3x1
2x2
2x2
2x2
3x3
3x1
3x1
33Matrix Multiplication
1x1
1x3
3x1
2x2
2x2
2x2
3x3
3x1
3x1
34Matrix Multiplication
1x1
1x3
3x1
2x2
2x2
2x2
3x3
3x1
3x1
35Matrix Multiplication
1x1
1x3
3x1
2x2
2x2
2x2
3x3
3x1
3x1
36Matrix Multiplication
e.g.
37Matrix Multiplication
e.g.
38Matrix Multiplication
e.g.
39Matrix Multiplication
e.g.
40Matrix Multiplication
e.g.
41Matrix Multiplication
e.g.
42Matrix Multiplication
e.g.
43Matrix Multiplication
e.g.
44Matrix Multiplication
e.g.
45Matrix Multiplication
e.g.
46Matrix Multiplication
e.g.
47Transformations Summ. (2)
Translation
Scaling
Rotation
Shearing
48Problem
- An affine transformation is composed of a linear
combination followed by a translation - Unfortunately, the translation portion is not a
matrix multiplication but must instead be added
as an extra term, or vector this is
inconvenient - What we need is a trick, so that translations
can be represented in matrix multiplication form - We will see (later) that this then means that
they can be easily composed with other
transformations, by simply multiplying the
matrices together
49Homogeneous Coordinates
- The trick we use is to add an additional
component 1 to both P and Q, and also a third row
and column to M, consisting of zeros and a 1 - i.e.
Rotate by q
Translation by (tx, ty)
Scale by Sx, Sy
Shear by g, h
50Useful Properties of Affine Transformations
1 Preservation of lines 2 Preservation of
parallelism 3 Preservation of proportional
distances
51Why are they useful?
- They preserve lines, so the image of a straight
line is another straight line. - This vastly simplifies drawing transformed line
segments. - We need only compute the image of the two
endpoints of the original line and then draw a
straight line between them - Preservation of co-linearity guarantees that
polygons will transform into polygons - Preservation of parallelism guarantees that
parallelograms will transform into parallelograms - Preservation of proportional distances means that
mid-points of lines remain mid-points
52Multiple Transformations
- It is rare that we want to perform just one
elementary transformation. - Usually an application requires that we build a
complex transformation out of several elementary
ones - e.g. translate an object, rotate it, and scale
it, all in one move - These individual transformations combine into one
overall transformation - This is called the composition of
transformations. - The composition of two or more affine
transformations is also an affine transformation
53Rotation and Scaling
- The simple versions of rotation and scaling have
been based around the origin. - This means that when we rotate or scale, the
object will also move, with respect to the origin
Not only is the object rotated, but it also moves
around the origin
54Pivotal points
- Often we wish to rotate or scale with respect to
some pivotal point, not the origin - Most significantly, we often wish to rotate or
scale an object about its centre, or midpoint - In this way, the objects location does not
change - To do this, we relate the rotation or scaling
about the pivotal point V, to an elementary
rotation or scaling about the origin - We first translate all points so that V coincides
with the origin - We then rotate or about the origin
- then all points are translated back, so that V is
restored to its original location
55(x1,y1)
(0,0)
56Rotation about a pivot point
57Coordinate Transforms
x
u
(1,1)
v
Object defined in Local Coordinate System
y
Object after transformation in Global Coordinate
System
58Identity
59Translation
u (0, 1, 0)
origin
v (1, 0, 0)
60Rotation
61Scaling
62Composite Transformations
O
v
u
63Why composition?
- One of the main reasons for composing
transformations is computational efficiency - Suppose you want to apply two affine
transformations to the N vertices of a polygonal
object - It requires 12 multiplications to compose the
transformations, and 4 multiplications to apply a
transformation to a point - So, compose-then-apply requires 4N12
multiplications - (PM1Tr1)M2 Tr2
- 8N multiplications are required if each
transformation is applied seperately - For models with any significant number of
vertices (which will be most), 4N12 is much less
than 8N
64Modeling Transformations
- To make full use of the computational
optimisation made possible by composite
transforms, we only want to apply the
transformations to points at the very end - i.e. the transformation operation (multiplying
point p by transform matrix is the very last
thing we do in the modelling phase)
Specify Transformations (composite if necessary)
Specify points in local coords
Send to Pipeline
65Usually we model individual objects based on a
local cordinate system
This of course shouldnt mean all objects need to
share the same transformations
66transform
transform
transform
Obviously we want something more versatile
67Code
- We probably want code that looks something like
this
scale (sxM, syM) translate (txM,
tyM) drawMan() scale (sxH, syH) translate
(txH, tyH) drawHouse() scale (sxS,
syS) translate (txS, tyS) drawSun()
68Current Transformation Matrix
- One way to do this is by using a single object to
represent the CURRENT TRANSFORMATION MATRIX (CTM) - All transformation functions affect only the CTM
- When a draw procedure is finally called it draws
based on the CTM - The CTM might be seen as representing the
current coordinate frame for drawing - Next 3D Transformations and OpenGL
69Transforming Images
70Transforming Images
71Some 3D Transformations
72Scale
- all vectors are scaled from the origin
Original
scale all axes
scale Y axis
offset from origin
distance from origin also scales
73Scale
Or in 3D homogeneous coordinates
74Rotation
- Rotations are anti-clockwise about the origin
rotation of 45o about the Z axis
offset from origin rotation
75Rotation
76Rotation
- 2D rotation of q about origin
- 3D homogeneous rotations
77Translation
- Translation only applies to points, we never
translate vectors. - Remember points have homogeneous co-ordinate w
1
translate along y
78Screen Co-ordinates
- Viewport Mapping
- Clipping
79Viewing Issues
- A Rasterization Issue
- How much of the projected data should be drawn?
- Where should it appear on the display?
- e.g We could have a model of a whole room, full
of objects such as chairs, tables, and students.
We may want to view the whole room in one go, or
zoom in on one single object in the room. We may
want to display the object or scene on the full
screen, or we may only want to display it on a
portion of the screen
80Screen Co-ordinates
- In our final display, i.e. the frame buffer,
images are specified in terms of pixels (screen
coordinates defined with integer values) where as
our original data is in real-number coordinates
(modelling coordinates) - We need to apply transform to convert from
Modelling co-ordinates to Screen Coordinates - We can scale dimensions to change the resulting
view - We can even achieve a zooming in and out effect
without changing the model by scaling dimensions
proportionally
812-Dimensional Views
- A 2-dimensional view is defined by two rectangles
we will refer to them as - A Window given in real world co-ordinates, e.g.
meters, feet etc defining the portion of model
(scene) to be drawn - A Viewport given in screen co-ordinates, pixels,
defining the portion of the screen which will be
used to display the contents of the window - Note that confusingly, some textbooks sometimes
use these terms interchangeably to describe the
original rectangle (the window).
82The Viewport
- We need to associate the 2D viewport co-ordinate
system with the screen co-ordinate system in
order to determine the correct pixel associated
with each vertex.
Real-world co-ordinates
screen co-ordinates
83Windows and Viewports
(wxmax,wymax)
(vxmax,vymax)
(vx,vy)
(wx,wy)
(vxmin,vymin)
(wxmin,wymin)
For any point (wx, wy) in the real-world window,
what is the corresponding pixel position?
84Window to Viewport Mapping
Preservation of horizontal ratios implies that
- wx - wxmin vx - vxmin
- wxmax - wxmin vxmax - vxmin
-
So, solving for vx
vx (wx - wx min) vxmax - vxmin
vxmin wxmax - wxmin
vy can be solved for similarly.
85Example
0.4
0.3
-0.4
-0.2
- Say we want to map this to a 640x480 viewport
- Where is the black point mapped in screen
coordinates?
480
640
86Example
- Vxmax640
- Vxmin-0.4
- Vymax0
- Vymin480
- Wx-.2
- Wy.3
- Wxmax0
- Wxmin-0.4
- Wymax0.4
- Wymin0
- Vx (-.2-(-0.4))(640-0) 0 320
- 0-(-0.4)
- Vy (.3-0)(0-480) 480 120
- 0-(-0.4)
320
120
Repeat this for all vertices and then rasterize.