Docsity

2D Transforms: Vector Spaces, Transforms in 2D, and Composing Transforms, Slides of Computer Graphics

Partial preview of the text

Download 2D Transforms: Vector Spaces, Transforms in 2D, and Composing Transforms and more Slides Computer Graphics in PDF only on Docsity!

2D Transforms

• Reviewed the math we’re going to

use in this course

• Points

• Vectors

• Matrices

• Linear interpolation

• Rays, planes, etc.

Last Time

Today

• Vector spaces and coordinate frames

• Transforms in 2D

• Composing Transforms

Vector Spaces

• Let’s think for a minute about what x

and y coordinates really mean

y

(x,y)

x

i

j

(u,v)

x

y (^) j i

Vector Spaces

• For illustration, let’s flip things around

i

j

(u,v)

x

y (^) j

i

x

= (-u,v)(x,y) y

Vector Spaces

• Any pair of non-parallel, non-anti-

parallel vectors can define a vector space in 2D

• We’re used to thinking about spaces

defined by orthogonal, normalized, axis-aligned vectors

• But there’s no reason this is the only

way to do things

Vector Space Terms

• Linear Vector Space: Any space made

up of vectors and scalars

• Euclidean Space: Vector space with a

distance metric

• Affine Space: Vector space with an

origin

• The Cartesian plane is both affine and

Euclidean

• We call this type of space a frame

2D Transforms

• What am I talking about when I say

“transforms”?

  • Translation (x,y)

(x’,y’)

  • Scaling
  • Rotation

General Form

• The transformations we consider are of

the following form:

Transformation Matrix

• Remember that the transformation matrix

describes the change in vector space:

x

y

x’

y’

Object vs. World

Space

• Let’s stop and think about why we’re

doing this...

• We can define the points that make up

an object in “object space”

• Whatever is most convenient, often

centered around the origin

• Then, at run time, we can put the

objects where we want them in “world space”

Homogeneous

Coordinates

• We refer to this as a homogeneous

coordinate:

• This mathematical construct allows us to

• Represent affine transforms with a single

matrix

• Do calculations in projective space

(vectors are unique only up to scaling)

Homogeneous

Coordinates

• For points, w must be non-zero

• If w=1, the point is “normalized”

• If w!=1, can normalize by

Vectors in

Homogeneous

Coordinates

• Remember last time, I mentioned that

it would be useful that we could represent points and vectors the same way?

• Here’s the payoff

• Can use homogeneous coordinates to

represent vectors, too

• What is w?

• Remember, vectors don’t have a

“position”

Vectors in

Homogeneous

• Since vectors don’t have a position,Coordinates

they should not be affected by translation

• What about rotation/scaling?

• Set w=0 for vectors:

These have no effect

Summing up

Translation

• We will represent translation with a

matrix of the following form:

u is the x-offset v is the y-offset

Scaling

• Want to stretch or shrink the entire

space in one or more dimensions

• α = stretch in x, β = stretch in y

x

y

Original α=1, β=

x

y

α=2, β=

x

y

α=1, β=

Scaling

• Scaling is centered around the origin

• Points either get pulled toward the

origin or pushed away from it

x

y

x

y

x

y

Scaling

• So, given what we know, how would we

construct a scaling matrix?

• Assume we have an object centered

around the origin, and want to scale it by α in x, and β in y

• x’ = αx

• y’ = βy

Summing up Scaling

• We will represent scaling with a matrix

of the following form:

α is the scale factor in the x-direction β is the scale factor in the y-direction

Rotation

α

α

Rotation

• Like scaling, rotations are centered

about the origin

x

y

x

y

x

y

Rotation

Composing

Transforms

• So why did we go through the trouble to

use homogeneous coordinates for our points, and do our transforms using square transformation matrices?

• To make composing transforms easy!

• Composing 2 transforms is just

multiplying the 2 transform matrices WARNING: The order in which matrix multiplicationstogether are performed may (and usually does) change the result! (i.e. they are not commutative)

Let’s do an example

• Two transforms:

• Scale x and y by a factor of 2

• Translate points (+3, +2)

• Let’s pick a single point in object space

Two Transform Paths

x

y

(2,1)

Translate Then Scale

Two Transform Paths

x

y

(5,3)

Translate Then Scale

Two Transform Paths

x

y

(10, 6)

Translate Then Scale

Two Transform Paths

x

y

(2,1)

Scale Then Translate

Two Transform Paths

x

y

(4,2)

Scale Then Translate

Two Transform Paths

x

y

(7,4)

Scale Then Translate

Composing

Transforms

• Translate then scale

• (x’, y’) = (10, 6)

• Scale then translate

• (x’, y’) = (7, 4)

• Need a standard way to order

transforms!

Transform Matrix

Multiplications

• Always compose from right to left

• Here, transform M 1 is applied first

• Transform M 3 is applied last

Two Transform Paths

Translate then Scale

Two Transform Paths

Scale then Translate