2d geometrical transformations - cs brandeis educs155/lecture_06.pdf · 2d geometrical...

34
2D Geometrical Transformations Foley & Van Dam, Chapter 5

Upload: vothuy

Post on 05-Mar-2018

221 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

2D Geometrical TransformationsFoley & Van Dam, Chapter 5

Page 2: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

2D Geometrical Transformations

• Translation• Scaling• Rotation • Shear• Matrix notation• Compositions• Homogeneous coordinates

Page 3: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

2D Geometrical TransformationsAssumption: Objects consist of points and lines.A point is represented by its Cartesian coordinates:

P = (x, y)

Geometrical Transformation: Let (A, B) be a straight line segment between the points A and B. Let T be a general 2D transformation.T transforms (A, B) into another straight line segment (A’, B’), where:

A’=TA and B’=TB

Page 4: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Translation

• Translate(a, b): (x, y) → (x+a, y+b)

Translate(2, 4)

Page 5: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Scale

• Scale (a, b): (x, y) → (ax, by)

Scale (2, 3)

Scale (2, 3)

Page 6: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Scale• How can we scale an object without moving its origin (lower left corner)?

Translate(-1,-1)

Translate(1,1) Scale(2,3)

Page 7: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Reflection

• Special case of scale

Scale(-1,1)

Scale(1,-1)

Page 8: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Rotation• Rotate(θ):(x, y) → (x cos(θ)+y sin(θ), -x sin(θ)+y cos(θ))

Rotate(90)

Rotate(90)

Page 9: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Rotation• How can we rotate an object without moving its origin (lower left corner)?

Translate(-1,-1)

Translate(1,1)Rotate(90)

Page 10: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Shear• Shear (a, b): (x, y) → (x+ay, y+bx)

Shear(1,0)

Shear(0,2)

Page 11: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Classes of Transformations• Rigid transformation (distance preserving):

Translation + Rotation• Similarity transformation (angle preserving):

Translation + Rotation + Uniform Scale• Affine transformation (parallelism preserving):

Translation + Rotation + Scale + Shear

All above transformations are groups where

Rigid ⊂ Similarity ⊂ Affine Rigid

Affine

Similarity

Page 12: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Matrix Notation• Let’s treat a point (x, y) as a 2x1 matrix (column vector):

• What happens when this vector is multiplied by a 2x2 matrix?

yx

++

=

dycxbyax

yx

dcba

Page 13: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

2D Transformations• 2D object is represented by points and lines that join them

• Transformations can be applied only to the thepoints defining the lines

• A point (x, y) is represented by a 2x1 column vector, so we can represent 2D transformations by using 2x2 matrices:

=

yx

dcba

yx''

Page 14: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Scale

• Scale (a, b): (x, y) → (ax, by)

•If a or b are negative, we get reflection

• Inverse: S-1(a,b) = S(1/a, 1/b)

=

byax

yx

ba0

0

Page 15: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Reflection• Reflection through the y axis:

• Reflection through the x axis:

• Reflection through y = x:

• Reflection through y = -x:

−1001

− 1001

0110

−0110

Page 16: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Shear• Shear (a, b): (x, y) → (x+ay, y+bx)

++

=

bxyayx

yx

ba1

1

Page 17: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Rotation• Rotate(θ):(x, y) → (x cos(θ)+y sin(θ), -x sin(θ)+y cos(θ))

• Inverse: R-1(q) = RT(q) = R(-q)

+−+

=

− θθ

θθθθθθ

cossinsincos

cossinsincos

yxyx

yx

Page 18: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Composition of Transformations• A sequence of transformations can be collapsed into a single matrix:

•Note: Order of transformations is important!

[ ][ ][ ] [ ]

=

yx

Dyx

CBA

translate rotate

rotate translate

Page 19: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Translation

• Translation (a, b):

Problem: Cannot represent translation using 2x2 matrices

Solution:Homogeneous Coordinates

++

byax

yx

Page 20: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Homogeneous CoordinatesIs a mapping from Rn to Rn+1:

Note: All triples (tx, ty, t) correspond to the same non-homogeneous point (x, y)Example (2, 3, 1) ≡ (6, 9, 3).

Inverse mapping:

),,(),,(),( ttytxWYXyx =→

WY

WXWYX ,),,(

Page 21: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Translation

• Translate(a, b):

Inverse: T-1(a, b) = T(-a, -b)Affine transformations now have the following form:

++

=

111001001

byax

yx

ba

100fdceba

Page 22: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Geometric InterpretationA 2D point is mapped to a line (ray) in 3D The non-homogeneous points are obtained by projecting the rays onto the plane Z=1

(X,Y,W)

yx

X

Y

W

1

(X,Y,1)

Page 23: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

ExampleRotation about an arbitrary point

1. Translate the coordinates so that the origin is at (x0,y0)2. Rotate by θ3. Translate back

(x0,y0)

θ

−−+−−

=

=

−−

1100sin)cos1(cossinsin)cos1(sincos

11001001

1000cossin0sincos

1001001

00

00

0

0

0

0

yx

xyyx

yx

yx

yx

θθθθθθθθ

θθθθ

Page 24: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

ExampleReflection about an arbitrary line

1.Translate the coordinates so that P1 is at the origin

2.Rotate so that L aligns with the x-axis3.Reflect about the x-axis4.Rotate back5.Translate back

p1

p2

L = p1 + t (p2-p1) = t p2 + (1-t) p1

Page 25: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Change of CoordinatesIt is often required to transform the description of an object from one coordinate system to another

Rule: Transform one coordinate frame towards the other in the opposite direction of the representation change

x

y

x’y’Representation

Transformation

Page 26: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Example• Change of coordinates: Represent P = (xp, yp, 1) in the (x’, y’) coordinate system

Where:

MPP ='

−−

−=

1001001

1000cossin0sincos

0

0

yx

M θθθθ

x

yx’y’

θ

(x0, y0)(xp, yp)

Page 27: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Example• Change of coordinates:Alternative method: assume x’ = (ux, uy) and y’ = (vx, vy) in the (x, y) coordinate system

where MPP ='

−−

=

1001001

10000

0

0

yx

vvuu

M yx

yx

x

y x’y’

(x0, y0)(ux, uy)(vx, vy)

Page 28: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

ExampleReflection about an arbitrary line

Define a coordinate systems (u, v) parallel to P1P2:

p1

p2

L = p1 + t (p2-p1) = t p2 + (1-t) p1

−−

=y

xuu

pppp

12

12u

=

−=

y

x

x

yvv

uuv

−−

=

1001001

10000

100010001

10000

1001001

1

1

1

1

y

x

y

x

pp

vvuu

vuvu

pp

M yx

yx

yy

xx

Page 29: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

3D Viewing Transformation Pipeline

Device Coordinates

Viewport

World Coordinates Object in World

Viewing coordinates

2D:2D mapping

3D:2D mapping

Page 30: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

World to Viewing CoordinatesIn order to define the viewing window we have to specify:

•Windowing-coordinate origin P0 = (x0,y0)•View vector up v = (vx,vy)

•Using v, we can find u: u = v x (0,0,1)

Transformation from world to viewing coordinates :

−−

=−

1001001

10000

0

0yx

vvuu

M yx

yx

vcwc

x world

y worldx view

y view

(x0,y0)

(vx,vy).

(ux,uy).

Page 31: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Window to Viewport Coordinates

(xmin,ymin)

(xmax,ymax)

Window is Viewing Coordinates Window translated to origin

Window scaled to Normalized Viewport size

Window scaled and translated to Viewport location in device coordinates

(umin,vmin)

(umaxn,vmaxn)

Normalized Device Coordinates

−−

=−

1001001

100

010

001

1000000

1001001

min

min

minmax

minmax

minmax

minmax

min

min

yx

yy

xxvv

uuvu

M dcvc

Page 32: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Efficiency ConsiderationsA 2D point transformation requires 9 multiplies and 6 adds

But since affine transformations have always the form:

The number of operations can be reduced to 4 multiplies and 4 adds

a b c x a x b y c zd e f y d x e y f zg h i z g x h y i z

+ + = + + + +

0 0 1 1 1

a b c x a x b y cd e f y d x e y f

+ + = + +

Page 33: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Efficiency ConsiderationsThe rotation matrix is:

When rotating of small angles θ, we can use the fact that cos(θ) ≅ 1 and simplify

+−+

=

− θθ

θθθθθθ

cossinsincos

cossinsincos

yxyx

yx

1 sin sinsin 1 sin

x x yy x y

θ θθ θ

+ = − − +

Page 34: 2D Geometrical Transformations - CS Brandeis Educs155/Lecture_06.pdf · 2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented by its

Determinant of a Matrix

If P is a polygon of area AP, transformed by a matrix M, the area of the transformed polygon is AP∗|M|

a bad bc

c d= −

a b cd e f aei bfg cdh ceg afh bdig h i

e f d f d ea b ch i g i g h

= + + − − −

= − +