CSCE 441 Lecture 8

From Notes
Jump to navigation Jump to search

« previous | Friday, January 31, 2014 | next »


2D Transformations

Coordinates

Depends on choice of origin (0,0) and axes.

Analogous to assembly language:

  • Assembly is a necessary evil for computation
  • But we'd like to think at a higher level

Vector operations

dot product
v⋅w=|v||w|cos⁡θ=vxwx+vywy
commutative
v⋅v=|v|2
2D cross product
v⊥=⟨−vy,vx⟩
Rotates v by π2


Types of Transformations

  1. Conformal
    • Preserves angles
    • Translation, rotation, uniform scaling
  2. Affine
    • Represented by matrix multiplication
    • Translation, rotation, general scaling, shear


Translation

Add vector t→ to point P:

P^=P+t→


Uniform Scaling

origin O about which to scale

Given point P to scale and scaling factor α,

  1. find vector from O to P: P−O
  2. scale that vector by alpha: α(P−O)
  3. add the vector back to O to get final position: O+α(P−O)

Rearranging the terms gives

P^=(1−α)O+αP

Non-Uniform Scaling

Point and vector:

  • origin point O for center of scaling
  • direction of scale v→ (assumed unit length)

Given point P to scale and a scaling factor α,

  1. find vector from O to P: q→=P−O
  2. take vector projection of q→ onto v→: v→∥=projv→(q→)=(v→⋅q→)v→
  3. use projection to find residual vector: v→⊥=q→−q→∥=q→−(v→⋅q→)v→
  4. scale the v→-parallel component of q→: αq→∥=α(v→⋅q→)v→
  5. add residual vector back in and add to origin point O to get final point: O+q→⊥+αq→∥=O+q→−(v→⋅q→)v→+α(v→⋅q→)v→

Substituting definitions and rearranging the formula gives

P^=P+(α−1)(v→⋅(P−O))v→


Rotation

Need center of rotation O and angle θ

Given point P to rotate about point O,

  1. find vector from O to P: q→=P−O
  2. set up a "coordinate system" by taking the 2D cross product q→⊥=⟨−qy,qx⟩
  3. using q→ and q→⊥ as new axes, observe that the rotated point is at position (|q→|cos⁡θ,|q→|sin⁡θ)
  4. hence the vector from O to P^ is given by cos⁡θq→+sin⁡θq→⊥
  5. Add the origin point to get the final position.
P^=cos⁡θq→+sin⁡θq→⊥+O


Shearing

Point O and unit vector v→.

Given point P to shear by amount α,

  1. compute q→=P−O
  2. set up a coordinate system by finding the 2D cross product of v→: v→⊥=⟨−vy,vx⟩
  3. project q→ onto v→ and v→⊥ to get q→∥=(v→⋅q→)v→ and q→⊥=(v→⊥⋅q→)v→⊥, respectively.
  4. the shearing vector scales q→∥ (in the direction of v→ depending on the magnitude of q→⊥ and α: q→⊥+α|q→⊥|v→
  5. Add q→∥ to get the final position

Plugging in definitions and rearranging gives

P^=P+α(v→⊥⋅q→)v→


Transformations as Matrices

  • Compact representation of all affine transformations
  • allows multiple transformatinos to be represented as a single matrix
  • requires coordinates

p^=Mp+t