2d Transforms

  • Uploaded by: api-3799599
  • 0
  • 0
  • July 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View 2d Transforms as PDF for free.

More details

  • Words: 1,453
  • Pages: 32
Computer Graphics MSIT 3rd Miniterm, Nov-Dec 2004 Instructor: Kiran Varanasi [email protected] Lecture Slides: Prof P.J. Narayanan IIIT - Hyderabad

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 location of the origin and the direction of the axes • Coordinates change not only when the point moves to a new position, but also when there is a change in the origin/axes

Y

P

y

O

x

X

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 by (a, b) • (x + a, y + b) are the coordinates of the new point in the old (same) coordinate system.

Y

P'

y' b y P

a b a

x

x'

p' = p + t

X

Translation of Axes • Translate the axes by (-a, -b). Y' New coordinates are • (x + a, y + b). • (x + a, y + b) are the y' coordinates of the same point in new coordinate system.

Y

y

P x

a b x'

p' = p + t

X X'

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. • Point undergoes shift when scaling with respect to the origin! • To scale shapes “in place”, translate to origin, scale, and translate back.

Y

X

p' = s p

Rotation of a point about Origin Y y'

y

P'

θ

α

P

r x'

x

θ

x = r cos α , y=r sin α x' = r cos ( α + θ ) = r cos α cos θ − r sin α sin y' = r sin ( α + θ ) = r sin α cos θ + r cos α sin

θX

Rotation: Matrix Notation Y y'

y

R(θ )

P'

θ

P α

x'

x

cos θ -sin θ x' = y' sin θ cos θ

x y

X

NewCoords = Matrix * OldCoord

p' = M p

Rotation of Coordinate Axes Y'

Y

P

y

x' = r cos (α − θ ) = r cos α cos θ + r sin α sin θ y' = r sin (α − θ ) = − r cos α sin θ + r sin α cos θ

P

X'

y'

x'

α θ

x

R(-θ ) X

cos θ x' = y' -sin θ

sin θ cos θ

x y

Opposite Rotation of Axes Y

x' = r cos α cos θ - r sin α sin θ y' = r cos α sin θ + r sin α cos θ

Y' y'

P

X y

x

α θ

x'

X'

R(θ ) cos θ -sin θ x' = y' sin θ cos θ

x y

Equivalent Matrices Y

Y

Y'

y'

y

P'

θ

y' y

P α

x'

x

X

cos θ -sin θ x' = y' sin θ cos θ

P θ

x y

α

X

x x' 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.

p=

x/w x y = y/w 1 w

Transformations: Uniform Form p=

x/w x y = y/w 1 w

cos θ -sin θ R(θ ) = sin θ cos θ 0 0

1

0

a

s

0

0

T= 0

1 0

b 1

S= 0

s 0

0 1

0

p' = M1 M2 M3 p

0

0 0 1

Shearing Transformation • Add part of X to Y and vice versa! • Squares turn into parallelograms! • May be applied in one direction only.

1

shx

0

shy

1

0

0

0

1

Transformations: Uniform Form p=

cos θ -sin θ R(θ ) = sin θ cos θ 0 0

x/w x y = y/w 1 w

1

0

a

s

0

0

T= 0

1 0

b 1

S= 0

s 0

0 1

0

0

p' = M1 M2 M3 p

0 0 1

1 shx 0 Sh = shy 1 0 0 0 1

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' X''

Y

lm

X' Y''

X l

m

θ P

P' = (k cos θ , -k sin θ ) P = (l + k cos θ , m - k sin θ ) L=Rθ , θ =ω t

If P starts to move P' = R(180 - θ ) P''

Y' X''

Y

lm

X' Y''

X l

θ P

P = T(l,m)P' = T(l,m)R(180 - θ )P'' P'' = (-k - vt, 0)

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) • T(a, b) R(θ ) T(-a, -b) • Object brought to origin, rotated and moved back.

Y

a b

X

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

Y

a b

X

Example 1c Y

a b

X

Example 2 In place scaling and rotation : T(v) R(θ ) S(sx,sy) T(v)

Rotations: Another View Y

Y

X θ cos θ -sin θ R(θ ) = sin θ cos θ 0 0

cos θ

-sin θ

sin θ

cos θ

are unit vectors to which X and Y axes move X 0

cos θ

sin θ

-sin θ

cos θ

0 1

are unit vectors which 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 with the Y axis? • [a' b']T should sit on Y axis. Orthogonal direction is [-b' a']T. • They form the rows!

(a, b) (c, d) -b' a' 0 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 !

Related Documents

2d Transforms
July 2020 5
2d
June 2020 32
2d
April 2020 28
2d
April 2020 22
Affine Transforms
November 2019 15
Formats And Transforms
December 2019 5