0% found this document useful (0 votes)
59 views33 pages

2D Transforms

This document discusses 2D transformations including translation, rotation, scaling, and shearing. It explains how each transformation can be represented by a 3x3 matrix. Composite transformations are achieved by multiplying the matrices together in the appropriate order. Transforming a point is equivalent to transforming the coordinate frame in the reverse way. Understanding these 2D transformations is important for working with 3D graphics.

Uploaded by

syriluit
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views33 pages

2D Transforms

This document discusses 2D transformations including translation, rotation, scaling, and shearing. It explains how each transformation can be represented by a 3x3 matrix. Composite transformations are achieved by multiplying the matrices together in the appropriate order. Transforming a point is equivalent to transforming the coordinate frame in the reverse way. Understanding these 2D transformations is important for working with 3D graphics.

Uploaded by

syriluit
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 33

Computer Graphics

MSIT

3rd Miniterm, Nov-Dec 2004

Instructor: Kiran Varanasi

kiran@students.iiit.net

Lecture Slides: Prof P.J. Narayanan


IIIT - Hyderabad
Week 1
2D
Transformations3D
Transformations

Graphics Pipeline
Coordinates
� A point is represented by a pair of realnumbers (x, y)
� There are two axes which serve as a
reference for measuring distance of each
point from the origin
� Conventionally the X and Y axes are
perpendicular to each other. But need notbe.
� The coordinates give the length ofprojections of the point onto the two axes
Coordinate Geometry
� The coordinates of the
point depend upon thelocation of the origin andYthe direction of the axes
� Coordinates change not
only when the point movesto a new position, but also
y

when there is a change in


the origin/axes

O x

X
P
Types of Transformation
� Translation
� Rotation
� Scaling
� Shearing
In each case, it can be either the point
or the reference (origin + axes)
Translation of a point
� Translate the pointby (a, b) Y
�(x + a, y +b) arethe y'
coordinates of the b
new point in the old y
(same) coordinate
system.
p' = p + t

X
P
x
P'
x'
a
a b
Translation of Axes
� Translate the axes by
Y

(-a, -b).

Y'

� New coordinates are


(x + a, y+ b).
y

�(x + a, y + b) are the


y'

coordinates of the same


point in new coordinate
system.

X'

x'

a
p' = p + t
Transformations in reverse
� Translating the axes by (a, b) is the
same as translating each point by (-a,
-b)
� Similarly scaling the axes (zooming in)
is the same as zooming out of each
point
� Rotating the axes by an angle .
is the
same as rotating each point by thereverse angle -..
Coordinates under Scaling
�x' = s x,y' = s y.
� s is the scale factor.
Y

� Point undergoes shift whenscaling with respect to theorigin!


� To scale shapes �in place�,
translate to origin, scale,
and translate back.
p' = s p

X
Rotation of a point about Origin
Y x= rcos a, y = r
sin a

y'

x' =r cos (a+ q) =


cos q- r sin a sin
y y'=rsin (a+ q) =
r sin a cos q+ r cos a sin

q
P'
x'
P
a
r cos a
q

q
r
Rotation: Matrix Notation
Y

R(q )

y'

x' cos q -sin q x


=

y' sin q cos q y

xx

NewCoords = Matrix * OldCoord

p' = M p

q
P'
'
P
a
Rotation of Coordinate Axes
x' = r cos (a -q )=

'

r cos a cos q + r sin a sin q


= r sin (a -q ) =
- r cos a sin q + r sin a cos q
'

y' x'
q
Xy y'P
P
a
Y
R(-q )

x x' cos q sin q x


=

y' -sin q cos q y


Opposite Rotation of Axes
Y

Y'
y'
q
P
x' = r cos a
X
xy
a
cos q -r sin a sin q
y' = r cos a sin q + r sin a cos q

R(q )

X'

x'

x' cos q -sin q

y' sin q cos q y


Equivalent Matrices
X'
Y'
y'
x'
q
P
X
Y
x
y
a
cos q -sin q
cos qsin q
x
y
x'
y' =
X
Y
q
P' y'
x'
P
a
x
y
Multiple Transformations
� Translation followed by rotation of a point
p. = R(p + t)

� Rotation followed by translation of a point


p. = t + Rp

They are not identical

� Rotation followed by translation followed by


scaling
p. = s(t + Rp)

Cumbersome jumble of additions andmultiplications !!


Homogeneous Coordinates
� Represent 2D coordinates using 3-vectors.
� The last number w is sort of a �scaling
constant.�
� Multiple representations for each point.
Multiplying x, y, and w by a non-zero k doesn�t
change the point.
x x/w
y y/w

p =

w
Transformations: Uniform Form
x
y
w
1
0
0
x/w
y/w
1
cos q
sin q
0
0
0
1
a
b
1
s
0
0
0
0
1
Shearing Transformation
�Add partof X to Y
and vice versa!
� Squares turn into
parallelograms!
� May be applied in
one direction only.
1 shx 0
shy 1 0
0 01
Transformations: Uniform Form
x x/w cos q -sin q 0
y y/w R(q ) = sin q cos q

p =
=

0 01

1 shx 0

10a s00

Sh = shy1 0

T = 0 1b S = 0 s0
001 001 001

p' = M1 M2 M3 p
3 Equivalent Viewpoints
p' = M p
Point p gets transformed by M and stays
in the same coordinate frame as p'

Coordinate frame changes by M-1 giving a


stationary point p new coordinates as p'

Coordinate frame changes by M giving astationary point p' new coordinates as


p !!
Why do we want to transform a
coordinate frame ??

� Sometimes we want to think in terms of a


reference frame which is natural to the
problem
� For example, consider a wheel which isrolling on the ground
� There can be 3 coordinate frames. One
fixed to the ground, the second fixed to the
wheel but not rotating, the third fixed tothe spokes of the wheel and rotating.
Rolling Wheel
q
X
Y X'
Y'
P
l
m
X''
Y'' l
P'' = (-k, 0)

P' = (k cos q , -k sin q )

P = (l + k cos q , m - k sin q )

L = R q , q = w t

m
If P starts to move

q
X
Y X'
Y'
P
l
m
X''
Y'' l
P' = R(180 -q ) P''

P = T(l,m)P'
= T(l,m)R(180 -q )P''

P'' = (-k - vt, 0)

We have to think of P in the X''-Y'' frame only.


Composite Operations
P' = M1M2M3M4 P

� Can think of transforming the coordinateframe by M1 followed by M2.


� Point P is transformed by M4 followed by M3
and comes into the above coord frame.
� Take Care: Once M1 is applied, the definition
of X and Y axes are modified. Old axes are
forgotten!
Example 1

� Rotation by q
about a point (a, b)
� T(a, b) R(q ) T(-a, Y
-b)
� Object brought toorigin, rotated andmoved back.
X
a
b
Example 1b

Rotation by q about a
point (a, b)

� T(a, b) R(q ) T(-a, -b)


� Coordinate frame
moved to (a, b),
rotated about new
origin and moved to(-a, -b) of the newframe.
XYabX
Y
a
b
Example 1c
XYabX
Y
a
b
Example 2

In place scaling and

rotation :

T(v) R(q ) S(sx,sy) T(v)


Rotations: Another View
Y

cos q -sin q

sin q cos q

are unit vectors to which X


and Y axes move

cos q sin q

cos q -sin q 0

-sin q cos q

R(q ) = sin q cos q

0 are unit vectors which


0 01

move to X and Y axes


Making Rotation Matrices
� Columns give the vectors to which
the axes will move after rotation.
� Rows give the vectors (beforerotation) that will sit on the axesafter rotation.
� This is alternate way to arrive at the
rotation matrix from what is known.
Example 3
� Given a triangle (0, 0),
(a, b), and (c, d), how to
align the side with the Yaxis?
� [a' b']T should sit on Y
axis. Orthogonaldirection is [-b' a']T.
� They form the rows!
(a, b)
(c, d)
0 0
a' b' 0
1
-b'a' 0
Summary
� Rotations, translation, scaling, shearingrepresented using a 3x3 matrix.
� Composite transformations obtained bymultiplying matrices together.
� Transforming a point Vs. transforming the
coordinate frame. (Doing it in reverse)
� Understand well. Very important in 3D !

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy