38
CS475/CS675 - Computer Graphics 2D Transformations

CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Computer Graphics

2D Transformations

Page 2: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 2

Transformations● What is a transformation?

– P' = T P● Why is it useful?

– Modelling● Specify object position, orientation, size in the world.● Create multiple instances of template shapes.● Specify hierarchical models.

– Viewing● Makes viewing window and device independent● Synthetic Camera Model

Page 3: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 3

Model n

The Modeling-Viewing pipeline

Model 1

Model 2 3D World

M1

M2

M3

Model/Object Coordinates

Modeling Transformations

WorldCoordinates

Page 4: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 4

Model n

The Modeling-Viewing pipeline

Model 1

Model 2 3D World

M1

M2

M3

V 3D Scene

ViewingTransformation

Modeling Transformations

WorldCoordinates

Model/ObjectCoordinates

CameraCoordinates

Page 5: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 5

Model n

The Modeling-Viewing pipeline

Model 1

Model 2 3D World

M1

M2

M3

V 3D Scene

P2D Scene Rasterize& Clip

Final 2D Image

Modeling Transformations

ViewingTransformation

Projection

Model/Object Coordinates

WorldCoordinates

CameraCoordinates

Page 6: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 6

2D Transformations - Scaling

X

YS=[S x 00S y]

P '=S P

P=[ xy ] P '=[ x 'y ' ]

[ x 'y ' ]=[ sx 00 s y][xy ]

x '=s x . xy '=s y . y

X

Y

Page 7: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 7

2D Transformations - Scaling

X

YS=[S x 00S y]P=[ xy ] P '=[ x 'y ' ]

x '=s x . xy '=s y . y

X

Y

s x=s y

Uniform or Isotropic Scaling

x '=s x . xy '=s y . y

P '=S . P

[ x 'y ' ]=[ sx 00 s y] . [xy ]

Page 8: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 8

2D Transformations - Scaling

X

YS=[S x 00S y]

P '=S . P

P=[ xy ] P '=[ x 'y ' ]

[ x 'y ' ]=[ sx 00 s y] . [xy ]

x '=s x . xy '=s y . y

X

Y

s x≠s y

Nonuniform or Anisotropic Scaling

x '=s x . xy '=s y . y

Page 9: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 9

2D Transformations - Rotation

X

YP '=R . P

P=[ xy ]=[r cos

r sin ]P '=[ x 'y ' ]=[r cos

r sin ]=[r coscos −r sin sin

r cossin r sin cos ]

[ x 'y ' ]=[cos −sin

sin cos ] . [xy ]

P '

Pr

rR=R=[cos −sin

sin cos ]

Page 10: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 10

2D Transformations

P '=T P ⇒

T=[ a cbd ]

[ x 'y ' ]=[ a cb d ] . [xy ]

x '=axcyy '=bxdy

P '=[ x 'y ' ]P=[ xy ]

a=1,d=1 b=0, c=0For andi.e. , T=I (Identity Transformation)x '=xy '=y

Page 11: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 11

2D Transformations

P '=T P ⇒

T=[ a cbd ]

[ x 'y ' ]=[ a cb d ] . [xy ]

x '=axcyy '=bxdy

P '=[ x 'y ' ]P=[ xy ]

b=0, c=0Fori.e. , T=S (Scaling Transformation)x '=a.xy '=d.y

Page 12: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 12

2D Transformations

P '=T P ⇒

T=[ a cbd ]

[ x 'y ' ]=[ a cb d ] . [xy ]

x '=axcyy '=bxdy

P '=[ x 'y ' ]P=[ xy ]

a=−1, d=1 b=0, c=0For andi.e. , T=Rf (Reflection Transformation)

x '=−xy '= y

Reflection about the linex=0

Page 13: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 13

2D Transformations - Shear

P '=T P ⇒

T=[1 c0 1]

[ x 'y ' ]=[1 c0 1] . [

xy ]

x '=xcy

P '=[ x 'y ' ]P=[ xy ]

y '=y

X

Y

X

Y

Shearing in X

Page 14: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 14

2D Transformations - Shear

P '=T P ⇒

T=[1 0b 1]

[ x 'y ' ]=[1 0b 1] . [

xy ]

x '=x

P '=[ x 'y ' ]P=[ xy ]

y '=bxy

X

Y

X

Y

Shearing in Y

Page 15: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 15

2D Transformations - Translation

P '=TP ⇒

T=[ t xt y ]

[ x 'y ' ]=[ t xt y ][ xy ]

x '=t xx

P '=[ x 'y ' ]P=[ xy ]

y '=t yy

X

Y

X

Y

Different from other Transformations!

Cannot represent it as a matrix multiplication.

Page 16: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 16

Homogenous CoordinatesPh=[

xy1 ]P=[ xy ] in homogenous coordinates becomes

A general point in homogenous coordinates can be mapped back to usual non-homogenous coordinates as follows by dividing with the homogenous dimension.

Ph=[wxwyw ]~P=[ xy ]

[642 ] , [1284 ] , [321 ] ,Therefore, the homogenous points all respresent the same 2D point [32]

Page 17: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 17

Homogenous Coordinates

X

Y

W

Ph1

P2

Ph2

w=1

Given a homogenous point:

If we plot the point in the XYH coordinate system, then line joining the point with the origin intersects the plane at:

Ph=[ x y w ]T

P=[ x /w y /w 1 ]T

w=1

Note that all points on the line will map to the same point on the plane.w=1

P1

Page 18: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 18

2D TransformationsThe general 2D Transformation matrix now becomes 3x3:

[x 'y 'w ]=[

a c lb d m0 0 1 ] . [

xy1]

x '=axcyl

[a c lb d m0 0 1 ]

y '=bxdym

w=1

i.e.,

Page 19: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 19

2D TransformationsSo we see that for translating a point we use the matrix:

[x 'y 'w ]=[

1 0 l0 1 m0 0 1 ] . [

xy1]

x '=xl

[1 0 l0 1 m0 0 1 ]

y '=ym

Therefore the new transformed points become:

Scaling/Rotation/Shear continue to work as before using the matrix:

[a c 0b d 00 0 1]

Page 20: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 20

Concatenating Transformations

P '=[x 'y 'w ' ]=T 1 . P=[

1 0 l10 1 m10 0 1 ] . [

xy1 ]

T 1=[1 0 l10 1 m10 0 1 ] T 2=[

1 0 l20 1 m20 0 1 ]

P ' '=[x ' 'y ' 'w ' ' ]=T 2 . P '=[

1 0 l20 1 m20 0 1 ] . [

x 'y 'w ' ]

P ' '=T 2 .T 1 .P=[1 0 l10 1 m10 0 1 ] . [

1 0 l20 1 m20 0 1 ] . [

xy1 ]=[

1 0 l1l20 1 m1m20 0 1 ] . [

xy1 ]

Successive Translations are additive.

Page 21: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 21

Concatenating Transformations

P '=[x 'y 'w ' ]=S1 .P=[

sx1 0 00 s y1 00 0 1] . [

xy1]

S1=[s x1 0 00 s y1 00 0 1] S2=[

s x2 0 00 s y2 00 0 1]

P ' '=[x ' 'y ' 'w ' ' ]=S2 .P '=[

s x2 0 00 sy2 00 0 1] . [

x 'y 'w ' ]

P ' '=S2 . S1 . P=[s x1 0 00 sy1 00 0 1] . [

s x2 0 00 s y2 00 0 1 ] . [

xy1]=[

s x1 . sx2 0 00 s y1 . sy2 00 0 1] . [

xy1 ]

Successive Scalings are multiplicative.

Page 22: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 22

Concatenating Transformations

P '=[x 'y 'w ' ]=R . P=[

cos −sin 0sin cos 00 0 1 ] . [

xy1 ]

R=[cos −sin 0sin cos 00 0 1] R=[

cos −sin 0sin cos 00 0 1 ]

P ' '=[x ' 'y ' 'w ' ' ]=R . P '=[

cos −sin 0sin cos 00 0 1 ] . [

x 'y 'w ' ]

Page 23: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 23

Concatenating Transformations

P ' '=R . R . P=[cos −sin 0sin cos 00 0 1] . [

cos −sin 0sin cos 00 0 1] . [

xy1]

Successive Rotations are additive.

P ' '=[cos −sin 0sin cos 00 0 1] . [

xy1 ]

Page 24: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 24

Concatenating Transformations

A

Rotation about an arbitrary point A

O

We know how to rotate about the origin O

● Translate to

● Rotate about

● Translate back to

A O

O

A

X

Y

Page 25: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 25

X

YConcatenating Transformations

A

Rotation about an arbitrary point

O

We know how to rotate about the origin

● Translate to

P '=[x 'y 'w ' ]=T 1 . P=[

1 0 l10 1 m10 0 1 ] . [

xy1 ]

A

O

A O

Page 26: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 26

X

YConcatenating Transformations

Rotation about an arbitrary point

O

We know how to rotate about the origin

P ' '=[x ' 'y ' 'w ' ' ]=R . P '=[

cos −sin 0sin cos 00 0 1 ] . [

x 'y 'w ' ]

● Translate to

● Rotate about O

A

O

A O

Page 27: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 27

X

YConcatenating - Transformations

A

O

P ' ' '=[x ' ' 'y ' ' 'w ' ' ' ]=T 2 .P ' '=[

1 0 −l0 1 −m0 0 1 ] . [

x ' 'y ' 'w ' ' ]

Rotation about an arbitrary point

We know how to rotate about the origin

● Translate to

● Rotate about

● Translate back to A

O

A

O

A O

Page 28: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 28

Concatenating TransformationsThe composite transformation is then:

T 2 . R .T 1=[1 0 −l0 1 −m0 0 1 ] . [

cos −sin 0sin cos 00 0 1] . [

1 0 l0 1 m0 0 1 ]

=[cos −sin l cos−m sin −lsin cos l sinmcos−m0 0 1 ]

Page 29: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 29

Concatenating TransformationsReflection about an arbitrary line.

X

Y

O

B

A

C

Page 30: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 30

Concatenating TransformationsReflection about an arbitrary line.

● Translation

X

Y

O

B

A

C

Page 31: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 31

Concatenating TransformationsReflection about an arbitrary line.

C

● Translation

● Rotation

X

Y

O

B

A

Page 32: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 32

Concatenating TransformationsReflection about an arbitrary line.

● Translation

● Rotation

● Reflection

B

A

C X

Y

O

Page 33: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 33

Concatenating TransformationsReflection about an arbitrary line.

● Translation

● Rotation

● Reflection

● Rotation B

A

C

X

Y

O

Page 34: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 34

Concatenating TransformationsReflection about an arbitrary line.

● Translation

● Rotation

● Reflection

● Rotation

● TranslationX

Y

O

B

A

C

Page 35: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 35

Concatenating Transformations

Generally transformation composition is not commutative.T 1 . T 2≠T 2 .T 1

Page 36: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 36

2D TransformationsRigid Transformations

● A square remains a square.

● Preserves lengths and angles.

● Rotations and Translations

T=[r11 r12 lr21 r22 m0 0 1 ]

Page 37: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 37

2D TransformationsAffine Transformations

● Preserves parallelism.

● Rotations, Translations, Scaling and Shears.

T=[a c lb d m0 0 1 ]

Page 38: CS 675 - Lecture 4paragc/teaching/2019/cs475/lectures/04... · CS475/CS675 - Lecture 4 17 Homogenous Coordinates X Y W Ph 1 P2 Ph 2 w=1 Given a homogenous point: If we plot the point

CS475/CS675 - Lecture 4 38

2D TransformationsGeneral 2D Transformation

T=[a c lb d mp q s ]