Docsity

Elemental Transformations - Introduction to Computer Graphics - Lecture Slides, Slides of Computer Graphics

Partial preview of the text

Download Elemental Transformations - Introduction to Computer Graphics - Lecture Slides and more Slides Computer Graphics in PDF only on Docsity!

Lecture 09:

Transform 2

Transformations in Computer Graphics

  • Elemental Transformations:
    • Translation
    • Rotation
    • Scaling
    • Shearing
  • Of the four, three of them are affine and linear:
    • Rotation, Scaling, and Shearing
  • One is affine but non-linear
    • Translation

Definitions of Transformations

โ€ข Definitions:

โ€“ Linear Transform:

  • Preserves parallel lines
  • Acts on a line to yield either a line or a point
  • The vector [0, 0] is always transformed to [0, 0]
  • Examples: scale and rotate

โ€“ Affine Transform:

  • Preserves parallel lines
  • Acts on a line to yield either a line or a point
  • The vector [0, 0] is NOT always transformed to [0, 0]
  • Examples: translate

โ€“ Projective Transform:

  • Does NOT preserve parallel lines
  • Acts on a line to yield either a line or a point
  • Examples: perspective camera (assignment 3)

2D Scaling

โ€ข Component-wise scalar multiplication of vectors

โ€ข Where ๐›ผ is a scalar, and ๐‘ฃ =

and ๐‘ฃ

โ€ข Without using a matrix, we would have:

= ๐›ผ๐‘ฃ๐‘ฅ and ๐‘ฃ๐‘ฆ

โ€ข What would we do with using a matrix?

2D Scaling, An Example

โ€ข Given ๐‘† =

, what happens to the

following 2 vertices of the house?

Y

X

๏ƒบ ๏ƒป ๏ƒน ๏ƒช ๏ƒซ ๏ƒฉ 1 2 ๏ƒบ ๏ƒป ๏ƒน ๏ƒช ๏ƒซ ๏ƒฉ 1 3

y

x

s

s

2D Scaling, An Example

โ€ข Given ๐‘† =

, what happens to the

following?

โ€ข Uhโ€ฆ Something looks wrongโ€ฆ

Y

X

๏ƒบ ๏ƒป ๏ƒน ๏ƒช ๏ƒซ ๏ƒฉ 1 2 ๏ƒบ ๏ƒป ๏ƒน ๏ƒช ๏ƒซ ๏ƒฉ 1 (^3) ๏ƒบ ๏ƒป ๏ƒน ๏ƒช ๏ƒซ ๏ƒฉ 2 6 ๏ƒบ ๏ƒป ๏ƒน ๏ƒช ๏ƒซ ๏ƒฉ 2 9

y

x

s

s

2D Scaling, An Example

โ€ข Now we can rewrite the

scaling process as:

โ€“ where ๐‘ฃ =

and

โ€ฒ , and^ ๐‘† =

Y

X

๏ƒบ๏ƒป ๏ƒน ๏ƒช๏ƒซ ๏ƒฉ 1 2 ๏ƒบ๏ƒป ๏ƒน ๏ƒช๏ƒซ ๏ƒฉ 1 (^3) ๏ƒบ ๏ƒป ๏ƒน ๏ƒช ๏ƒซ ๏ƒฉ 2 6 ๏ƒบ ๏ƒป ๏ƒน ๏ƒช ๏ƒซ ๏ƒฉ 2 9

y x

s

s

2D Rotation

โ€ข Rotation of vectors around an angle q

๐‘ฃ, where ๐‘ฃ =

and ๐‘ฃ

cos ๐œƒ โˆ’ sin ๐œƒ

sin ๐œƒ cos ๐œƒ

, which means

= ๐‘ฃ๐‘ฅ cos ๐œƒ โˆ’ ๐‘ฃ๐‘ฆ sin ๐œƒ

= ๐‘ฃ๐‘ฅ sin ๐œƒ + ๐‘ฃ๐‘ฆ cos ๐œƒ

  • 2D Rotation, Proof

2D Rotation, Proof 2

2. From the triangle EYโ€™P,

โ€ฒ

โ€ฒ

= tan ๐œƒ

3. So โˆ†๐‘ฆ = ๐‘ฆ + ๐‘ฅโ€ฒ tan ๐œƒ

4. Multiply both sides by cos ๐œƒ:

โˆ†๐‘ฆ cos ๐œƒ = ๐‘ฆโ€ฒ cos ๐œƒ + ๐‘ฅโ€ฒ sin ๐œƒ

5. Finally, from the triangle OYE,

= cos ๐œƒ, or ๐‘ฆ = โˆ†๐‘ฆ cos ๐œƒ

6. Therefore: ๐‘ฆ = ๐‘ฅโ€ฒ sin ๐œƒ +

๐‘ฆโ€ฒ cos ๐œƒ

2D Rotation Example

โ€ข Result:

โ€“ Preserves lengths

in objects

โ€“ Preserves angles

between parts of

the objects

โ€“ Rotation is rigid

body

๏ฐ q ๏€ฝ

Y

X

q

Sets of Linear Equations and Matrices

  • To translate, scale, and rotate vectors we need a function to give a new value of x, and a function to give a new value of y
  • Examples:
    • Rotation:
      • ๐‘ฃ๐‘ฅ

= ๐‘ฃ๐‘ฅ cos ๐œƒ โˆ’ ๐‘ฃ๐‘ฆ sin ๐œƒ

  • ๐‘ฃ๐‘ฆ

= ๐‘ฃ๐‘ฅ sin ๐œƒ + ๐‘ฃ๐‘ฆ cos ๐œƒ

  • These are both of the form:
    • ๐‘ฅ

= ๐‘Ž๐‘ฅ + ๐‘๐‘ฆ

  • ๐‘ฆ

= ๐‘๐‘ฅ + ๐‘‘๐‘ฆ

  • Since the transforms are given by a system of linear equations, they are called linear transformations, and is represented by the matrix: ๐‘Ž ๐‘ ๐‘ ๐‘‘

๏ฝ Scaling

๏ฝ ๐‘ฃ๐‘ฅ โ€ฒ = ๐‘ ๐‘ฅ๐‘ฃ๐‘ฅ + 0๐‘ฃ๐‘ฆ ๏ฝ ๐‘ฃ๐‘ฆ โ€ฒ = 0๐‘ฃ๐‘ฅ + ๐‘ ๐‘ฆ๐‘ฃ๐‘ฆ

2D Translation

โ€ข Goal: moving a house from location A to location B:

โ€ข Pretty easyโ€ฆ Just add 5 to x and 3 to y

โ€ข If there are multiple vertices in the house, apply the

addition to each and every vertex

Y

X

R 2

A = (2, 3)

Y

B = (7, 6)

2D Translate

โ€ข In matrix notation, this means:

= ๐‘ฃ + ๐‘ก where ๐‘ฃ

, and ๐‘ก =

โ€“ which means: ๐‘ฅ

= ๐‘ฅ + ๐‘‘๐‘ฅ and ๐‘ฆ

dx = 2

dy = 3

Y

X

๏ฝ Translation:

๏ฝ Preserves lengths

(isometric)

๏ฝ Preserves angles (conformal)