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
vw=|v||w|cosθ=vxwx+vywy
commutative
vv=|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: PO
  2. scale that vector by alpha: α(PO)
  3. add the vector back to O to get final position: O+α(PO)

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=PO
  2. take vector projection of q onto v: v=projv(q)=(vq)v
  3. use projection to find residual vector: v=qq=q(vq)v
  4. scale the v-parallel component of q: αq=α(vq)v
  5. add residual vector back in and add to origin point O to get final point: O+q+αq=O+q(vq)v+α(vq)v

Substituting definitions and rearranging the formula gives

P^=P+(α1)(v(PO))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=PO
  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=PO
  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=(vq)v and q=(vq)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+α(vq)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