Geometric Transformations - PowerPoint PPT Presentation

1 / 80
About This Presentation
Title:

Geometric Transformations

Description:

A designer may want to view and object from different vantage points, by ... Whole collections of points may be transformed by the same transformation T, e.g. ... – PowerPoint PPT presentation

Number of Views:2439
Avg rating:3.0/5.0
Slides: 81
Provided by: johndin
Category:

less

Transcript and Presenter's Notes

Title: Geometric Transformations


1
Geometric Transformations
2
Cartesian Coordinates
(10, 12)
10
12
Rene Descartes - 1637
3
Cartesian Coordinates
(13, 15)
Rene Descartes - 1637
4
Cartesian Coordinates
(13, 15)
(3, 3)
Rene Descartes - 1637
5
Co-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

6
Transforming 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

7
Example 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...
8
Transforming 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.

9
Example 2
10
Transforming 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.

11
Example 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

12
Transformations
  • 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

13
Example OBJECT TRANSFORMATION
.4, 2
1,1
Example COORDINATE TRANSFORMATION
(1,1)
(1,1)
14
2D 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)
15
Affine 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)
16
Elementary Transformations
  • Affine transformations are usually combinations
    of four elementary transformations
  • 1 Translation
  • 2 Scaling
  • 3 Rotation
  • 4 Shearing

17
Translation
  • 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
18
Scaling
  • 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
19
Rotation
  • 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
20
Rotation - derivation
1
2
3
4
1
Substituting from 3 and 4
Similarly from 2
21
Shearing
  • 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

22
Shearing
g 0, h0.5
Shear by (g,h)
Original points
Transformed points
g0.5, h0.5
Shear by (g,h)
Original points
Transformed points
23
Transformations Summary
  • 1 Translation
  • 2 Scaling
  • 3 Rotation
  • 4 Shearing

T
T
T
T
(Qx,Qy) (PxhPy, Py)
24
Matrix 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.

25
Matrix Multiplication
1x1
1x3
3x1
2x2
2x2
2x2
3x3
3x1
3x1
26
Matrix Multiplication
1x1
1x3
3x1
2x2
2x2
2x2
3x3
3x1
3x1
27
Matrix Multiplication
1x1
1x3
3x1
2x2
2x2
2x2
3x3
3x1
3x1
28
Matrix Multiplication
1x1
1x3
3x1
2x2
2x2
2x2
3x3
3x1
3x1
29
Matrix Multiplication
1x1
1x3
3x1
2x2
2x2
2x2
3x3
3x1
3x1
30
Matrix Multiplication
1x1
1x3
3x1
2x2
2x2
2x2
3x3
3x1
3x1
31
Matrix Multiplication
1x1
1x3
3x1
2x2
2x2
2x2
3x3
3x1
3x1
32
Matrix Multiplication
1x1
1x3
3x1
2x2
2x2
2x2
3x3
3x1
3x1
33
Matrix Multiplication
1x1
1x3
3x1
2x2
2x2
2x2
3x3
3x1
3x1
34
Matrix Multiplication
1x1
1x3
3x1
2x2
2x2
2x2
3x3
3x1
3x1
35
Matrix Multiplication
1x1
1x3
3x1
2x2
2x2
2x2
3x3
3x1
3x1
36
Matrix Multiplication
e.g.
37
Matrix Multiplication
e.g.
38
Matrix Multiplication
e.g.
39
Matrix Multiplication
e.g.
40
Matrix Multiplication
e.g.
41
Matrix Multiplication
e.g.
42
Matrix Multiplication
e.g.
43
Matrix Multiplication
e.g.
44
Matrix Multiplication
e.g.
45
Matrix Multiplication
e.g.
46
Matrix Multiplication
e.g.
47
Transformations Summ. (2)
Translation
Scaling
Rotation
Shearing
48
Problem
  • 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

49
Homogeneous 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
50
Useful Properties of Affine Transformations
1 Preservation of lines 2 Preservation of
parallelism 3 Preservation of proportional
distances
51
Why 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

52
Multiple 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

53
Rotation 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
54
Pivotal 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)
56
Rotation about a pivot point
57
Coordinate Transforms
x
u
(1,1)
v
Object defined in Local Coordinate System
y
Object after transformation in Global Coordinate
System
58
Identity
59
Translation
u (0, 1, 0)
origin
v (1, 0, 0)
60
Rotation
61
Scaling
62
Composite Transformations
O
v
u
63
Why 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

64
Modeling 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
65


Usually we model individual objects based on a
local cordinate system
This of course shouldnt mean all objects need to
share the same transformations

66




transform
transform
transform
Obviously we want something more versatile

67
Code
  • 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()
68
Current 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

69
Transforming Images
70
Transforming Images
71
Some 3D Transformations
72
Scale
  • all vectors are scaled from the origin

Original
scale all axes
scale Y axis
offset from origin
distance from origin also scales
73
Scale
Or in 3D homogeneous coordinates
74
Rotation
  • Rotations are anti-clockwise about the origin

rotation of 45o about the Z axis
offset from origin rotation
75
Rotation
76
Rotation
  • 2D rotation of q about origin
  • 3D homogeneous rotations

77
Translation
  • Translation only applies to points, we never
    translate vectors.
  • Remember points have homogeneous co-ordinate w
    1

translate along y
78
Screen Co-ordinates
  • Viewport Mapping
  • Clipping

79
Viewing 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

80
Screen 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

81
2-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).

82
The 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
83
Windows 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?
84
Window 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.
85
Example
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
86
Example
  • 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.
Write a Comment
User Comments (0)
About PowerShow.com