You are on page 1of 33

Computer Graphics

Week 1
2D Transformations
3D Transformations
Graphics Pipeline
Coordinates
A point is represented by a pair of real
numbers (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 not be.
The coordinates give the length of projections
of the point onto the two axes
Coordinate Geometry
The coordinates of the
point depend upon the Y
location of the origin and
the direction of the axes
Coordinates change not
only when the point y P
moves to a new position,
but also when there is a x
X
change in the origin/axes O
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 point Y


by (a, b)
y' P'
(x + a, y + b) are the b
a b
coordinates of the y P
new point in the old
a
(same) coordinate x x'
X
system.
p' = p + t
Translation of Axes
Translate the axes by Y
(-a, -b). Y'

New coordinates are y


y' P
(x + a, y + b).
(x + a, y + b) are the a x
X
coordinates of the b
X'
x'
same point in new
coordinate system. 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 the reverse angle -θ.
Coordinates under Scaling
x' = s x, y' = s y.
s is the scale factor. Y

Point undergoes shift


when scaling with
respect to the origin!
To scale shapes “in
place”, translate to X
origin, scale, and p' = s p
translate back.
Rotation of a point about Origin

Y x = r cos y = r sin 


y' P'
x' = r cos 
r cos  cos r sin sin 
y P y' = r sin 
 r
 r sin cos r cos  sin 
x X
x'
Rotation: Matrix Notation

Y
R()
y' P'
x' cos  -sin  x
= y
y' sin  cos 
y P

 X
x' x
NewCoords = Matrix * OldCoord
p' = M p
Rotation of Coordinate Axes
x' = r cos () =
Y' Y r cos  cos  + r sin  sin 
P y' = r sin () =
y P
r cos  sin  + r sin  cos 
X'
y'
 x'
R(-)
 X
x x' cos  sin  x
= y
y' -sin  cos 
Opposite Rotation of Axes
Y Y' x' = r cos  cos  - r sin  sin 
y' P
y' = r cos  sin  + r sin  cos 
X
y
 x

R()
X'
x'
x' cos  -sin  x
= y
y' sin  cos 
Equivalent Matrices
Y
Y
Y'
y' P' y'

y P
y P

 
x X X
x'  x
x' cos  -sin  x x'
= y
y' sin  cos 
X'
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 and multiplications !!
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
p= y = y/w
w 1
Transformations: Uniform Form
x x/w cos  -sin  0
p= y = y/w R() = sin  cos  0
w 1 0 0 1

1 0 a s 0 0
T= 0 1 b S= 0 s 0
0 0 1 0 0 1

p' = M1 M2 M3 p
Shearing Transformation

Add part of X to Y
and vice versa! 1 shx 0
Squares turn into
parallelograms! shy 1 0
May be applied in 0 0 1
one direction only.
Transformations: Uniform Form
x x/w cos  -sin  0
p= y = y/w R() = sin  cos  0
w 1 0 0 1

1 0 a s 0 0 1 shx 0
Sh = shy 1 0
T= 0 1 b S= 0 s 0
0 0 1 0 0 1 0 0 1

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 a


stationary 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 is rolling
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 to the spokes of the
wheel and rotating.
Rolling Wheel

P'' = (-k, 0)
Y'
P' = (k cos , -k sin )
X'' X'
Y

P = (l + k cos , m - k sin )
lm Y'' P
X
L = R ,  = t
l
m
If P starts to move

P' = R(180 - ) P''


Y'
X'' X'
Y P = T(l,m)P'

= T(l,m)R(180 - )P''
lm Y'' P
X
P'' = (-k - vt, 0)
l
m

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


Composite Operations
P' = M1M2M3M4 P
Can think of transforming the coordinate
frame 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  about a
point (a, b)
Y
T(a, b) R() T(-a, -b)
Object brought to
origin, rotated and
moved back.
a
b
X
Example 1b

Rotation by  about a Y
point (a, b)
T(a, b) R() T(-a, -b)
Coordinate frame
moved to (a, b), rotated a
about new origin and b
X
moved to
(-a, -b) of the new
frame.
Example 1c
Y

X
Example 2
In place scaling and
rotation :
T(v) R() S(sx,sy) T(-v)
Rotations: Another View
Y cos  -sin 
Y
sin  cos 
X are unit vectors to which X
and Y axes move
 X
cos  sin 
cos  -sin  0
-sin  cos 
R() = sin  cos  0 are unit vectors which
0 0 1 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 (before rotation) that
will sit on the axes after 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 (a, b)
with the Y axis?
[a' b']T should sit on (c, d)
Y axis. Orthogonal
direction is [-b' a']T. -b' a' 0
They form the rows! a' b' 0
0 0 1
Summary

Rotations, translation, scaling, shearing


represented using a 3x3 matrix.
Composite transformations obtained by
multiplying matrices together.
Transforming a point Vs. transforming the
coordinate frame. (Doing it in reverse)
Understand well. Very important in 3D !
PRESENTED BY :-
NAME:- ARPIT SHRIVASTAVA
SEM:- 5th
BRANCH:- C.S.E-1
ROLL NUM:-0914CS071015
BATCH:- 2007-2011

You might also like