geometric transformation. so far…. we have been discussing the basic elements of geometric...

43
Geometric Transformation

Upload: elwin-fitzgerald

Post on 27-Dec-2015

224 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Geometric Transformation

Page 2: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

So far….

We have been discussing the basic elements of geometric programming. We have discussed points, vectors and theiroperations and coordinate frames and how to change the representation of points and vectors from one frame to another.

Next topic involves how to map points from one place to another (transformation).

Page 3: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Affine Transformation

In this topic, we will concentrate on one particular transformationcalled affine transformations. Examples of affine transformationsare:

• translations• rotations• Uniform and non-uniform scaling• reflections (flipping objects about a line)• shearing ( which deform squares into parallelogram)

Page 4: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Affine Transformation (cont.)

Figure 1: Examples of affine transformation

Page 5: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Example

Figure 2: Transformation in 2-D and 3-D

Page 6: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Characteristics

These transformations all have a number of things in common.

1. They all map lines to lines ( parallel lines will still be parallelafter the transformations)

1. Translation, rotation and reflection preserve the lengths ofline segments and the angles between segments

3. Uniform scaling preserve angles but not length4. Non-uniform scaling and shearing do not preserve angles or

lengths

Page 7: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Usage

Transformations are useful in a number of situations:

1. We can compose a scene out a number of objects

Page 8: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Usage (cont.)

Page 9: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Usage (cont.)

2. Can design a single “motif” and manipulate the motif toproduce the whole shape of an object especially if the objecthas certain symmetries.

Example of snowflake after reflections, rotations and translationsof the motif

Page 10: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Usage (cont.)

3. To view an object from a different angle

Page 11: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Usage (cont.)

4. To produce animation

Page 12: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Affine Transformation

The two special types of affine transformation are

1. Rigid transformation: These transformations preserve bothangles and lengths (I.e. translations, rotations and reflections)

2. Orthogonal transformation: These transformations preserveangles but not necessarily length.

Page 13: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Affine Transformation (why?)

The most common transformations used in computer graphics.

They simplify operations to scale, rotate and reposition objects.

Several affine transformations can be combined into a simpleoverall affine transformation in terms of a compact matrixrepresentation

Page 14: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Transformation Matrix (2-D)

For a point P that map to Q after affine transformation has a matrix representation as shown:

11001232221

131211

y

x

y

x

P

P

mmm

mmm

Q

Q

NB: the third of the resultant matrix will always be 1 for a point

Page 15: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Transformation Matrix (2-D)

For a vector V that maps to W after affine transformationhas the matrix representation as shown:

01000232221

131211

y

x

y

x

V

V

mmm

mmm

W

W

NB: the third row of the resultant matrix will always be 0for a vector

Page 16: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Transformation Matrix

The scalar m that we have in the transformation matrixwill determine which affine transformation that we want to perform.

Page 17: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

OpenGL graphics pipeline

Normally in OpenGL, many transformation processes occur before the final objects are displayed on the screen. Basicallythe object that we define in our world will go through the sameProcedure.

Page 18: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Transformations

Transformations: changes in size, shape and orientation thatalter the coordinate descriptions of objects.

Usually, transformations are represented and calculated usingmatrices.

OpenGL also uses the same approach to perform transformations Lets look in detail at each of the transformations listed earlier..

Page 19: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Sine and Cosine

Sin = b/c if c = 1 then b = sin

Cos = a/c if c = 1 then c = cos

c

a

b

Recall our algebra lesson!!

Page 20: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Sine and Cosine (cont.)90

0180

270

y

x

z

-

Page 21: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Sine and Cosine (cont.)

Cos = x/z if z = 1 then cos = xSin = y/z if z = 1 then sin = y

Cos (- ) = x/z = cosSin (- ) = -y/z = -sin

Cos ( ) = cos cos - sin sin Sin ( ) = sin cos + cos sin

Page 22: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Matrices

In graphics most of the time matrix operation that we will deal with is matrix multiplication. The formula for multiplication ofmatrix A with m x p dimension and matrix B with p x n dimensionis:

mnm

ij

n

pnpjp

nj

mpm

ipi

p

cc

c

cc

bbb

bbb

aa

aa

aa

...

.....

..

.....

...

......

.........

.........

.........

......

...

.....

...

.....

...

1

111

1

1111

1

1

111

where

p

kkjikpjipjijiij babababac

12211 ...

Page 23: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Example

987

654

321

A

10

21

01

B

251

161

71

AB

Page 24: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Characteristics of Matrix

Multiplication of matrices is not commutative

AB != BA

Multiplication of several matrices is associative

A(BC) = (AB)C

Page 25: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Identity Matrix

Set of matrices that when they multiply another matrixwhich reproduce that matrix is called identity matricesI.e:

1000

0100

0010

0001

100

010

001

10

011

1D 2D 3D 4D

Page 26: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Object Transformation vs Coordinate Transformation

Object Transformation: alters the coordinates of eachpoint on the object according to some rule. No change ofcoordinate system

Coordinate Transformation: defines a new coordinate system in terms of the old one and then represents all of the object’spoint in the new coordinate system

Page 27: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Translation

Reposition an object along a straight line path from onecoordinate location to another

2D point is translated by adding translation distances tothe x and y coordinates

When translating (x,y) to (x’,y’) by value tx’ = x + tx

y’ = y + ty

Page 28: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Translation (cont.)

The (tx,ty) is the translation distances called TRANSLATIONVECTOR

In matrix form

y

xP

'

''

y

xP

y

x

t

tT

Then point P’ = P + T

y

x

y

x

ty

tx

t

t

y

xP'

Page 29: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Translation (cont.)

For 2-D translation the transformation matrix T has the following form:

100

10

01

y

x

m

m

Where mx and my are the translation values in x and yaxis

T =

Page 30: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Translation (cont.)

For 3-D translation the transformation matrix T has the followingform:

1000

100

010

001

z

y

x

m

m

m

Where mx, my and mz are the translation values in x, y and z axis

T =

Page 31: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Translation (cont.)

Translation is a rigid body transformation• the object is not being deformed• all points are moved in the same distance

How to translate?

• straight lines – based on end points• polygons - based on vertices• Circles - based on centre

Page 32: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Rotations

Reposition an object along a circular path in a specifiedPlane

Rotations are specified by:• a rotation angle• a rotation point (pivot point) at position (x,y)

Positive rotation angle means rotate counter-clockwisenegative rotation angle means rotate clockwise

Page 33: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Rotations (cont.)

(x,y)

(x’,y’)

r

r

The original point (x,y) can be represented in polarcoordinates form:

x = r cos (1) y = r sin (2)

Page 34: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Rotations (cont.)

The new point (x’,y’) can be expressed asx’ = r cos ( )y’ = r sin ( )

These equation can be written as

x’ = r cos cos - r sin siny’ = r cos sin + r sin cos

Page 35: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Rotations (cont.)

Substituting the equations with equation (1) and (2), we get

x’ = x cos - y sin y’ = x sin + y cos

Therefore, the rotation matrix R can be expressed as

cossin

sincosR =

Page 36: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Rotations (cont.)

For 2-D rotation the transformation matrix R has the followingForm (in homogeneous coordinate system):

100

0cossin

0sincos

NB: for counter-clockwise rotation

Page 37: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Rotations (cont.)

In 3-D world, the rotation is more complex since we have toConsider rotation about three different axis; x, y and z axis.Therefore we have three different transformation matrices in3-D world.

1000

0100

00cossin

00sincos

Rz( ) =

Rotation about z-axis (ccw)

Page 38: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Rotations (cont.)

1000

0cossin0

0sincos0

0001

1000

0cos0sin

0010

0sin0cos

Rx( ) =

Ry( ) =

Rotation about y-axis (ccw)

Rotation about x-axis (ccw)

Page 39: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Rotations (cont.)

This rotation matrix is for case where the rotation is at theorigin.

For a rotation at any other points, we need to perform thefollowing transformations:

1. Translating the object so the rotation point is at the origin.2. Rotating the object around the origin3. Translating the object back to its original position

Recall that rotation is a rigid affine transformation

Page 40: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Scaling

Scaling changes the size of an object

Scaling can also reposition the object but not always

Uniform scaling is performed relative to some central fixedpoint (I.e at the origin). The scaling value (scale factor) for uniform scaling must be both equal.

Non-uniform scaling has different scaling factors. Also refersas differential scaling

Page 41: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Scaling (cont.)

The value of the scale factors (Sx, Sy, Sz) determine the size of the scaled object.

• if equal to 1 -> no changes• if greater than 1 -> increase in size (magnification)• if 0 < scale factors < 1 -> decrease in size

(demagnification)• if negative value -> reflection !!!

Page 42: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Scaling (cont.)

For 2-D scaling the transformation matrix S will have thefollowing form

100

00

00

y

x

S

S

S =

Page 43: Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations

Scaling (cont.)

For 3-D scaling the transformation matrix S has the followingform:

1000

000

000

000

z

y

x

S

S

S

S =