college of engineering university of porto computer graphics and interfaces / graphics systems jgb /...

19
COLLEGE OF ENGINEERING UNIVERSITY OF PORTO COMPUTER GRAPHICS AND INTERFACES / GRAPHICS SYSTEMS JGB / AAS 2004 1 2D Geometric Transformations Graphics Systems / Computer Graphics and Interfaces

Upload: maverick-tubb

Post on 14-Dec-2015

219 views

Category:

Documents


1 download

TRANSCRIPT

COLLEGE OF ENGINEERING UNIVERSITY OF PORTO

COMPUTER GRAPHICS AND INTERFACES /GRAPHICS SYSTEMS JGB / AAS 2004

1

2D Geometric Transformations

Graphics Systems /

Computer Graphics and Interfaces

COLLEGE OF ENGINEERING UNIVERSITY OF PORTO

COMPUTER GRAPHICS AND INTERFACES /GRAPHICS SYSTEMS JGB / AAS 2004

2

2D Geometric Transformations

The geometric transformations in computer graphics are essential to position, change the orientation and scale objects in the scene created. The movement is also implemented by the processing parameters vary over time.

Transformations:

• Translation

• Scaling

• Rotation

COLLEGE OF ENGINEERING UNIVERSITY OF PORTO

COMPUTER GRAPHICS AND INTERFACES /GRAPHICS SYSTEMS JGB / AAS 2004

3

Translation

Vertices: (4,5) and (7,5)

TxT = 3y= -4

xT= X + Tx

yT= Y + Ty

The pair of translation is called for translation vector. Each vertex is assigned a displacement T:

y

x

T

T

T

T

y

x

y

x

In the form of matrix product:

1

.10

01y

x

T

T

y

x

y

x

T

T

COLLEGE OF ENGINEERING UNIVERSITY OF PORTO

COMPUTER GRAPHICS AND INTERFACES /GRAPHICS SYSTEMS JGB / AAS 2004

4

Scaling

20 40 60

xT= X * Sx

yT* Y = Sy Regarding the origin.

100

Sx = 2

Sy = 2

8040 120

200

12040

80

150

Sx = 2

Sy = -1.5

COLLEGE OF ENGINEERING UNIVERSITY OF PORTO

COMPUTER GRAPHICS AND INTERFACES /GRAPHICS SYSTEMS JGB / AAS 2004

5

Scaling

In matrix form:

y

x

s

s

y

x

y

x

T

T .0

0

Scale Factor:

> Increase the subject 1

<1 reduces the object

sx= Sy Uniform scaling factor does not distort the object

COLLEGE OF ENGINEERING UNIVERSITY OF PORTO

COMPUTER GRAPHICS AND INTERFACES /GRAPHICS SYSTEMS JGB / AAS 2004

6

Rotation

x, yb

the

x = R.cos (a)

y = R.sen (a)

100 xRYR

R

xRR.cos = (a + b) = R.cos (a). Cos (b) - R.sen (a). Sin (b) = x.cos (b) - y.sen (b)

yRR.sen = (a + b) = R. Sin (b).cos (a) + R.sen (a). Cos (b) = x.sen (b) + y.cos (b)

Around the origin.

Obtains a new position on the previous and the relative angle of rotation.

Vertices: (20.0) (60.0) (40,100)

Rotation of -45

Vertices: (14:14, -14.14), (42.43, -42.43), (98.99, 42.43)

COLLEGE OF ENGINEERING UNIVERSITY OF PORTO

COMPUTER GRAPHICS AND INTERFACES /GRAPHICS SYSTEMS JGB / AAS 2004

7

Rotation

In matrix form:

y

x

bbsen

bsenb

y

x

R

R .)cos()(

)()cos(

Note: b positive movement in the opposite clockwise direction.

+

COLLEGE OF ENGINEERING UNIVERSITY OF PORTO

COMPUTER GRAPHICS AND INTERFACES /GRAPHICS SYSTEMS JGB / AAS 2004

8

Composition of Transformations

The application of a sequence of operations

=

1 single transformation

T1T2

T3

Tc

COLLEGE OF ENGINEERING UNIVERSITY OF PORTO

COMPUTER GRAPHICS AND INTERFACES /GRAPHICS SYSTEMS JGB / AAS 2004

9

Composition of Transformations

Initial situation

(20.0)

(60.0)

(40,100)

100

20 60

After rotation

(0, -20)

(0, -60)

(100, -40)

a = - 90 °

After translation

(-80, -20)

(-80, -60)

(20, -40)

Tx = -80, Ty = 0

0.0

Replacing the transformations:

Initial situation

(20.0)

(60.0)

(40,100)

100

20 60

After translation

(-60.0)

(-20.0)

(-40.100)

Tx = -80, Ty = 0

After rotation

(0.60)

(0.20)

(100.40)

a = - 90 °

100

20 60

-80

Conclusion: The application of the transformations is not commutative

COLLEGE OF ENGINEERING UNIVERSITY OF PORTO

COMPUTER GRAPHICS AND INTERFACES /GRAPHICS SYSTEMS JGB / AAS 2004

10

Homogeneous coordinatesThe previous sequence, rotation, translation then applied to each vertex can be written as:

y

x

aasen

asena

y

x

R

R .)cos()(

)()cos(

1

11

If the matrices representing the transformations were of the same size would be able to combine.

2

However, the above transformations can also be written as (homogeneously)

1

).(

1

.

100

0)cos()(

0)()cos(

11

1

y

x

aRy

x

aasen

asena

y

x

R

R

1

.10

011

1

2

2R

R

y

x

R

R y

x

T

T

y

x

1

).,(

1

.

100

10

01

11

1

1

1

2

2

R

R

yxR

R

y

x

R

R

y

x

TTTy

x

T

T

y

x

We can then write:

1

).().,(

12

2

y

x

aRTTTy

x

yxR

R The matrix product is:• Associative• In general Noncommutative

),().()().,( yxyx TTTaRaRTTT

COLLEGE OF ENGINEERING UNIVERSITY OF PORTO

COMPUTER GRAPHICS AND INTERFACES /GRAPHICS SYSTEMS JGB / AAS 2004

11

Homogeneous coordinates - summary

Rotation Matrix

)(

100

0)cos()(

0)()cos(

aRaasen

asena

),(

100

10

01

yxy

x

TTTT

T

Matrix Translation

Escalation Matrix

),(

100

00

00

yxy

x

ssSs

s

In homogeneous coordinates of an object n dimensions is represented in space n +1 dimensions.

(X, y) (x.h, y.h h)

2D 3D

We consider h = 1

COLLEGE OF ENGINEERING UNIVERSITY OF PORTO

COMPUTER GRAPHICS AND INTERFACES /GRAPHICS SYSTEMS JGB / AAS 2004

12

Transformations - Examples

T (dx2, Dy2) * T (dx1, Dy1) = T (dx1+ Dx2, Dy1+ Dy2)

T (dx1, Dy1)T (dx2, Dy2)

T (?,?)P

P '

P''

P '= T (dx1, Dy1) * P

R'' = T (dx2, Dy2) * P '

R'' = T (dx2, Dy2) * T (dx1, Dy1) * P

100

10

01

100

10

01

.

100

10

01

12

12

1

1

2

2

yy

xx

y

x

y

x

dd

dd

d

d

d

d

Check that:

O (sx2, Sy2) S * (sx1, Sy1) S = (sx1* Sx2, Sy1* Sy2)

R (the2) * R (the1) = R (a2+ A1)

COLLEGE OF ENGINEERING UNIVERSITY OF PORTO

COMPUTER GRAPHICS AND INTERFACES /GRAPHICS SYSTEMS JGB / AAS 2004

13

Transformations on a arbitrary point (pivot)

Rotation

Rotation of -45 The rotation moves objects around the origin.

Solution:• Traverse the object so that the point Anchorman coincides with the origin• Rotating the object around the origin• Making the translation of the object so that the point Anchorman return to starting position (inverse of first)

COLLEGE OF ENGINEERING UNIVERSITY OF PORTO

COMPUTER GRAPHICS AND INTERFACES /GRAPHICS SYSTEMS JGB / AAS 2004

14

Transformations on a arbitrary point (pivot)

),().().,(

100

))())cos(1()cos()(

))())cos(1()()cos(

100

10

01

.

100

0)cos()(

0)()cos(

.

100

10

01

yxyx

xy

yx

y

x

y

x

ddTaRddT

asendadaasen

asendadasena

d

d

aasen

asena

d

d

Transformation matrix

Scaling• Traverse the object so that the point Anchorman coincides with the origin• Climb the object• Making the translation of the object so that the point Anchorman return to starting position (inverse of first)

),().,().,(

100

)1(0

)1(0

100

10

01

.

100

00

00

.

100

10

01

yxyxyxyyy

xxx

y

x

y

x

y

x

ddTssSddTsds

sds

d

d

s

s

d

d

COLLEGE OF ENGINEERING UNIVERSITY OF PORTO

COMPUTER GRAPHICS AND INTERFACES /GRAPHICS SYSTEMS JGB / AAS 2004

15

Exercise

Determine the transformation matrix for:

T (-x1,-y1) S (0.5,0.5) R (90) T (x2, y2)

If P1= (1,2) and P2= (3.3) determine the matrix of equivalent transformation.

COLLEGE OF ENGINEERING UNIVERSITY OF PORTO

COMPUTER GRAPHICS AND INTERFACES /GRAPHICS SYSTEMS JGB / AAS 2004

16

Other transformations

ReflectionIn relation to axis x corresponds to a 180 ° rotation in 3D space around the axis of reflection, which results in a scaling S (1, -1)

100

010

001

In relation to axis y:

100

010

001

y

x

x

y

COLLEGE OF ENGINEERING UNIVERSITY OF PORTO

COMPUTER GRAPHICS AND INTERFACES /GRAPHICS SYSTEMS JGB / AAS 2004

17

Other transformations

x

y

Reflection relative to the line y = x

100

001

010

)45().1,1().45( RSR

Reflection relative to the line y =-x

100

001

010

)45().1,1().45( RSR

x

y

COLLEGE OF ENGINEERING UNIVERSITY OF PORTO

COMPUTER GRAPHICS AND INTERFACES /GRAPHICS SYSTEMS JGB / AAS 2004

18

Inverse Transformations

If a transformation possibly composite is given by a matrix Mdimensions of 3x3, then the inverse transformation that puts the object in its initial position (ie no transformation) is given by M-1.

Once M represents one or more transformations, the inverse matrix should be.

M.M-1 = I

For some transformations is easy to find the inverse matrix:

Translation:

Scaling:

100

10

011

y

x

t

t

T

100

0/10

00/11

y

x

s

s

S

COLLEGE OF ENGINEERING UNIVERSITY OF PORTO

COMPUTER GRAPHICS AND INTERFACES /GRAPHICS SYSTEMS JGB / AAS 2004

19

Exercise

(Question of the May 23, 2002 test)