©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540...

36
March 21, 2022 1 ©College of Computer and Information Science, Northeastern University CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11 – January 28, 2009
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    215
  • download

    0

Transcript of ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540...

Page 1: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 1©College of Computer and Information Science, Northeastern University

CS U540Computer Graphics

Prof. Harriet Fell

Spring 2009

Lecture 11 – January 28, 2009

Page 2: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 2©College of Computer and Information Science, Northeastern University

Today’s Topics

• Linear Algebra Review Matrices Transformations

• New Linear Algebra Homogeneous Coordinates

Page 3: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 3©College of Computer and Information Science, Northeastern University

Matrices

11 12 13 1411 12 13

21 22 23 2411 1221 22 23

31 32 33 3421 2231 32 33

41 42 43 44

c c c cb b b

c c c ca aA B b b b C

c c c ca ab b b

c c c c

⎡ ⎤⎡ ⎤ ⎢ ⎥⎡ ⎤ ⎢ ⎥ ⎢ ⎥= = =⎢ ⎥ ⎢ ⎥ ⎢ ⎥⎣ ⎦ ⎢ ⎥ ⎢ ⎥⎣ ⎦

⎣ ⎦

• We use 2x2, 3x3, and 4x4 matrices in computer graphics.

• We’ll start with a review of 2D matrices and transformations.

Page 4: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 4©College of Computer and Information Science, Northeastern University

Basic 2D Linear Transforms

11 12 11 12

21 22 21 22

a a a x a yx

a a a x a yy

+⎡ ⎤ ⎡ ⎤⎡ ⎤=⎢ ⎥ ⎢ ⎥⎢ ⎥ +⎣ ⎦⎣ ⎦ ⎣ ⎦

11 12 11 11 12 12

21 22 21 21 22 22

1 0

0 1

a a a a a a

a a a a a a

⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤⎡ ⎤ ⎡ ⎤= =⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥

⎣ ⎦ ⎣ ⎦⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦

Page 5: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 5©College of Computer and Information Science, Northeastern University

Scale by .5

( )scale .5,.5

.5 0

0 .5

=

⎡ ⎤⎢ ⎥⎣ ⎦

(1, 0) (0.5, 0)

(0, 1)

(0, 0.5)

Page 6: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 6©College of Computer and Information Science, Northeastern University

Scaling by .5

y

x

y

x

0.5 0

0 0.5

⎡ ⎤⎢ ⎥⎣ ⎦

Page 7: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 7©College of Computer and Information Science, Northeastern University

General Scaling

y

x

y

x

0 1

0 0 0x x

y

s s

s

⎡ ⎤⎡ ⎤ ⎡ ⎤=⎢ ⎥⎢ ⎥ ⎢ ⎥

⎣ ⎦ ⎣ ⎦⎣ ⎦0 00

0 1x

y y

s

s s

⎡ ⎤ ⎡ ⎤⎡ ⎤=⎢ ⎥ ⎢ ⎥⎢ ⎥

⎣ ⎦⎣ ⎦ ⎣ ⎦

Page 8: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 8©College of Computer and Information Science, Northeastern University

General Scaling

sx1

1

sy

y

x

y

x

( ),

0

0

x y

x

y

scale s s

s

s

=

⎡ ⎤⎢ ⎥⎣ ⎦

Page 9: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 9©College of Computer and Information Science, Northeastern University

Rotation

sin()

cos()

( )( ) ( )( ) ( )

rot

cos sin

sin cos

φ

φ φ

φ φ

=

−⎡ ⎤⎢ ⎥⎣ ⎦

-sin()

cos()

Page 10: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 10©College of Computer and Information Science, Northeastern University

Rotation

y

x

y

x

( )( ) ( )( ) ( )

rot

cos sin

sin cos

φ

φ φ

φ φ

=

−⎡ ⎤⎢ ⎥⎣ ⎦

Page 11: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 11©College of Computer and Information Science, Northeastern University

Reflection in y-axis

reflect-y

1 0

0 1

=

−⎡ ⎤⎢ ⎥⎣ ⎦

Page 12: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 12©College of Computer and Information Science, Northeastern University

Reflection in y-axis

y

x

y

x

reflect-y

1 0

0 1

=

−⎡ ⎤⎢ ⎥⎣ ⎦

Page 13: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 13©College of Computer and Information Science, Northeastern University

Reflection in x-axis

reflect-x

1 0

0 1

=

⎡ ⎤⎢ ⎥−⎣ ⎦

Page 14: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 14©College of Computer and Information Science, Northeastern University

Reflection in x-axisy

x

reflect-x

1 0

0 1

=

⎡ ⎤⎢ ⎥−⎣ ⎦

y

x

Page 15: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 15©College of Computer and Information Science, Northeastern University

Shear-x

( )shear-x

1

0 1

s

s

=

⎡ ⎤⎢ ⎥⎣ ⎦

s

Page 16: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 16©College of Computer and Information Science, Northeastern University

Shear x

y

x

y

x

1

0 1

s⎡ ⎤⎢ ⎥⎣ ⎦

Page 17: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 17©College of Computer and Information Science, Northeastern University

Shear-y

( )shear-y

1 0

1

s

s

=

⎡ ⎤⎢ ⎥⎣ ⎦

s

Page 18: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 18©College of Computer and Information Science, Northeastern University

Shear y

y

x

y

x

1 0

1s

⎡ ⎤⎢ ⎥⎣ ⎦

Page 19: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 19©College of Computer and Information Science, Northeastern University

Linear Transformations

• Scale, Reflection, Rotation, and Shear are all linear transformations

• They satisfy: T(au + bv) = aT(u) + bT(v) u and v are vectors a and b are scalars

• If T is a linear transformation T((0, 0)) = (0, 0)

Page 20: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 20©College of Computer and Information Science, Northeastern University

Composing Linear Transformations

• If T1 and T2 are transformations T2 T1(v) =def T2( T1(v))

• If T1 and T2 are linear and are represented by matrices M1 and M2

T2 T1 is represented by M2 M1

T2 T1(v) = T2( T1(v)) = (M2 M1)(v)

Page 21: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 21©College of Computer and Information Science, Northeastern University

Reflection About an Arbitrary Line (through the origin)

y

x

y

x

Page 22: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 22©College of Computer and Information Science, Northeastern University

Reflection as a Composition

y

x

Page 23: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 23©College of Computer and Information Science, Northeastern University

Decomposing Linear Transformations

• Any 2D Linear Transformation can be decomposed into the product of a rotation, a scale, and a rotation if the scale can have negative numbers.

• M = R1SR2

Page 24: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 24©College of Computer and Information Science, Northeastern University

Rotation about an Arbitrary Point

y

x

y

x

This is not a linear transformation. The origin moves.

Page 25: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 25©College of Computer and Information Science, Northeastern University

Translation

y

x

y

x

(a, b)

This is not a linear transformation. The origin moves.

(x, y)(x+a,y+b)

Page 26: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 26©College of Computer and Information Science, Northeastern University

Homogeneous Coordinates

x

x

y

z

y Embed the xy-plane in R3 at z = 1.

(x, y) (x, y, 1)

Page 27: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 27©College of Computer and Information Science, Northeastern University

2D Linear Transformations as 3D Matrices

11 12 11 12

21 22 21 22

a a a x a yx

a a a x a yy

+⎡ ⎤ ⎡ ⎤⎡ ⎤=⎢ ⎥ ⎢ ⎥⎢ ⎥ +⎣ ⎦⎣ ⎦ ⎣ ⎦

Any 2D linear transformation can be represented by a 2x2 matrix

11 12 11 12

21 22 21 22

0

0

0 0 1 1 1

a a x a x a y

a a y a x a y

+⎡ ⎤⎡ ⎤ ⎡ ⎤⎢ ⎥⎢ ⎥ ⎢ ⎥= +⎢ ⎥⎢ ⎥ ⎢ ⎥⎢ ⎥⎢ ⎥ ⎢ ⎥⎣ ⎦⎣ ⎦ ⎣ ⎦

or a 3x3 matrix

Page 28: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 28©College of Computer and Information Science, Northeastern University

2D Linear Translations as 3D Matrices

Any 2D translation can be represented by a 3x3 matrix.

1 0

0 1

0 0 1 1 1

a x x a

b y y b

+⎡ ⎤⎡ ⎤ ⎡ ⎤⎢ ⎥⎢ ⎥ ⎢ ⎥= +⎢ ⎥⎢ ⎥ ⎢ ⎥⎢ ⎥⎢ ⎥ ⎢ ⎥⎣ ⎦⎣ ⎦ ⎣ ⎦

This is a 3D shear that acts as a translation on the plane z = 1.

Page 29: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 29©College of Computer and Information Science, Northeastern University

Translation as a Shear

x

x

y

z

y

Page 30: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 30©College of Computer and Information Science, Northeastern University

2D Affine Transformations

• An affine transformation is any transformation that preserves co-linearity (i.e., all points lying on a line initially still lie on a line after transformation) and ratios of distances (e.g., the midpoint of a line segment remains the midpoint after transformation).

• With homogeneous coordinates, we can represent all 2D affine transformations as 3D linear transformations.

• We can then use matrix multiplication to transform objects.

Page 31: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 31©College of Computer and Information Science, Northeastern University

y

x

Rotation about an Arbitrary Point

y

x

Page 32: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 32©College of Computer and Information Science, Northeastern University

y

x

Rotation about an Arbitrary Point

T(-cx, -cy)R()T(cx, cy)

Page 33: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 33©College of Computer and Information Science, Northeastern University

Windowing Transforms

(a,b)

(A,B)

(c,d)

(C,D)(C-c,D-d)

(A-a,B-b)translate

scale

translate

Page 34: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 34©College of Computer and Information Science, Northeastern University

3D Transformations

1

xx

yy

zz

⎡ ⎤⎡ ⎤ ⎢ ⎥⎢ ⎥ ⎢ ⎥↔⎢ ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥⎣ ⎦

⎣ ⎦

11 12 1311 12 13

21 22 2221 22 23

31 32 3331 32 33

0

0

0

0 0 0 1

a a aa a a

a a aa a a

a a aa a a

⎡ ⎤⎡ ⎤ ⎢ ⎥⎢ ⎥ ⎢ ⎥↔⎢ ⎥ ⎢ ⎥⎢ ⎥ ⎢ ⎥⎣ ⎦

⎣ ⎦

Remember:

A 3D linear transformation can be represented by a 3x3 matrix.

Page 35: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 35©College of Computer and Information Science, Northeastern University

3D Affine Transformations

( )0 0 0

0 0 0scale , ,

0 0 0

0 0 0 1

x

yx y z

z

s

ss s s

s

⎡ ⎤⎢ ⎥⎢ ⎥=⎢ ⎥⎢ ⎥⎣ ⎦

( )1 0 0

0 1 0translate , ,

0 0 1

0 0 0 1

x

yx y z

z

t

tt t t

t

⎡ ⎤⎢ ⎥⎢ ⎥=⎢ ⎥⎢ ⎥⎣ ⎦

Page 36: ©College of Computer and Information Science, Northeastern UniversityJune 26, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.

April 18, 2023 36©College of Computer and Information Science, Northeastern University

3D Rotations

( ) ( ) ( )( ) ( )x

1 0 0 0

0 cos sin 0rotate

0 sin cos 0

0 0 0 1

θ θθ

θ θ

⎡ ⎤⎢ ⎥−⎢ ⎥=⎢ ⎥⎢ ⎥⎣ ⎦

( )

( ) ( )( ) ( )

z

cos sin 0 0

sin cos 0 0rotate

0 0 1 0

0 0 0 1

θ θ

θ θθ

−⎡ ⎤⎢ ⎥⎢ ⎥=⎢ ⎥⎢ ⎥⎣ ⎦

( )

( ) ( )

( ) ( )y

cos 0 sin 0

0 1 0 0rotate

sin 0 cos 0

0 0 0 1

θ θ

θθ θ

⎡ ⎤⎢ ⎥⎢ ⎥=⎢ ⎥−⎢ ⎥⎣ ⎦