1 eel 5771-001 introduction to computer graphics geometric transformations by kiranmayi karri...

Post on 20-Jan-2016

256 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

1

EEL 5771-001Introduction to Computer

GraphicsGeometric Transformations

ByKiranmayi

KarriU81100483

Outline

•Transformation•Geometric Transformation•2D Transformation•3D Transformation•References

2

Transformation

• What is a transformation?An operation that changes one configuration into another. A geometric transformation maps positions that define the object to other positions Linear transformation means the transformation is defined by a linear function.

• Why use them? Modeling Moving the objects to the desired location in the environment Multiple instances of a prototype shape

3

Geometric Transformation

• In computer graphics many applications need to alter or manipulate a picture, for example, by changing its size, position or orientation. This can be done by applying a geometric transformation to the coordinate points defining the picture.

• Once the models are prepared, we need to place them in the environment .Objects are defined in their own local coordinate system .We need to translate, rotate and scale them to put them into the world coordinate system .

4

Types of TransformationsGeometric Transformations • Translation • Rotation • Scaling Linear Transformation • Non-uniform scales, shears or skews Non-linear Transformation • Twists, bends, warps, morphs

5

Translation

A common requirement is to move a picture to a new position. Translation transform simply moves every point by a certain amount horizontally and a certain amount vertically. The original object and its translation have the same shape and size, and they face in the same direction.

6

2-D Transformations

2D Translation-Matrix Notation

7

P

P

T

x

y

,

, ,

x y

x

y

x x t y y t

tx x

ty y

P P T

P P T

• A translation moves all points in an object along the same straight-line path to new positions.

• The path is represented by a vector, called the translation or shift vector.

• We can write the components:

p'x = px + tx

p'y = py + ty

• or in matrix form:P' = P + T

Rotation

• A rotation is a transformation that turns a figure about a fixed point called the center of rotation.  An object and its rotation are the same shape and size, but the figures may be turned in different directions.

• Another common type of transformation is rotation. This is used to orientate objects. A rotation transform, rotates each point about the origin, (0,0). Every point is rotated through the same angle, called the angle of rotation. For this purpose, angles can be measured either in degrees or in radians. A rotation with a positive angle rotates points in the direction from the positive x-axis to the positive y-axis.

8

2-D Transformations

2D Rotation – Matrix Notation

A rotation repositions all points in an object along a circular path in the plane centered at the pivot point.

9

x

y

rx

ry

x

y

,r rx y

,x y

,x y

Rotation in angle about a

pivot (rotation) point , .r rx y

cos sin

sin cos

cos sin

sin cos

r r r

r r r

r r

x x x x y y

y y x x y y

P P R P P

R

Scaling

• Changing the size of an object is called a scale. We scale an object by scaling the x and y coordinates of each vertex in the object.

• We have two types of scaling, Uniform and Non-Uniform ScalingUniform ScalingUniform scaling is a linear transformation that enlarges or shrinks objects by a scale factor that is the same in all directions. The result of uniform scaling is similar  to the original. Uniform scaling happens, for example, when enlarging or reducing a photograph, or when creating a scale model of a building, car, airplane, etc.

10

2-D Transformations

Scaling

Non Uniform ScalingIs obtained when at least one of the scaling factors is different from the others; a special case is directional scaling or stretching. Non-uniform scaling changes the shape of the object; e.g. a square may change into a rectangle, or into a parallelogram if the sides of the square are not parallel to the scaling axes (the angles between lines parallel to the axes are preserved, but not all angles). It occurs, for example, when a faraway billboard is viewed from an oblique angle, or when the shadow of a flat object falls on a surface that is not parallel to it.

11

2-D Transformations

2D Scaling-Matrix Notation

12

,

0

0

x y

x

y

x x s y y s

sx x

sy y

P S P

1

1

x f x

y f y

f

x x s x s

y y s y s

P P S P 1-S

Scaling about a fixed point ,f fx y

Homogeneous coordinates are a way to handle projective geometric spaces easily. These are non-Euclidean geometries that represent non-linear projections, like a perspective projection.

Now, they also use an extra coordinate. The transformation between a Cartesian coordinate system and a Homogeneous one is done by dividing all of the components of the Homogeneous coordinates by the last coordinate.

13

Homogeneous Coordinates

Homogenous Coordinates• In Euclidean space (geometry), two parallel lines on the same plane cannot intersect, or

cannot meet each other forever. It is a common sense that everyone is familiar with.  However, it is not true any more in projective space.Euclidean space (or Cartesian space) describe our 2D/3D geometry so well, but they are not sufficient to handle the projective space (Actually, Euclidean geometry is a subset of projective geometry). The Cartesian coordinates of a 2D point can be expressed as (x, y).  What if this point goes far away to infinity? The point at infinity would be (∞,∞), and it becomes meaningless in Euclidean space. The parallel lines should meet at infinity in projective space, but cannot do in Euclidean space.

• Solution to the problem of Euclidean Space is Homogeneous Coordinates• Homogeneous coordinates, introduced by August Ferdinand Möbius, make calculations of

graphics and geometry possible in projective space. Homogeneous coordinates are a way of representing N-dimensional coordinates with N+1 numbers.  To make 2D Homogeneous coordinates, we simply add an additional variable, w, into existing coordinates. Therefore, a point in Cartesian coordinates, (X, Y) becomes (x, y, w) in Homogeneous coordinates. And X and Yin Cartesian are re-expressed with x, y and w in Homogeneous as; X = x/w Y = y/w 

For instance, a point in Cartesian (1, 2) becomes (1, 2, 1) in Homogeneous. If a point, (1, 2), moves toward infinity, it becomes (∞,∞) in Cartesian coordinates. And it becomes (1, 2, 0) in Homogeneous coordinates, because of (1/0, 2/0) = (∞,∞). Notice that we can express the point at infinity without using "∞".

14

15

Inverse Transformations

Composite 2-D Transformations

• We can represent any sequence of transformations as a single matrix.No special cases when transforming a point – matrix

* vector.Composite transformations – matrix * matrix.

• Composite transformations:– Rotate about an arbitrary point – translate, rotate,

translate– Scale about an arbitrary point – translate, scale,

translate– Change coordinate systems – translate, rotate,

scale16

Composite Transformation

• Transformation T followed by • Transformation Q followed by • Transformation R

17

Order of Composite transformation

• In composite transformations, the order of transformations is very important.

18

Rotation followed by Translation:

Translation followed by Rotation:

Rotation wrt x-axis and y-axis

• To rotate about an arbitrary point P (px,py) by �θ: Translate the object so that P will coincide �with the origin: T(-px, -py) Rotate the object: �R(θ) Translate the object back: T(px,py) .�

• Translate the object so that P will coincide �with the origin: T(-px, -py) Rotate the object: �R(θ) � Translate the object back: T(px,py) �

19

Rotation wrt. Arbitrary point

• To rotate about P1 (x1,y1), the following sequence of the fundamental transformations are needed:1.Translate the object by (-x1, -y1) 2.Rotate (Ø)3.Translate the object by (x1, y1)

• The matrix representation of these steps is

 

20

Scaling wrt. Arbitrary point

• To scale about P1 (x1,y1), the following sequence of the fundamental transformations is needed1.Translate the object by (-x1, -y1)2.Scale by (Sx, Sy)3.Translate the object by (x1, y1)

• This series of steps can be performed as following: 

21

Composite transformation order

• In a composite transformation, the order of the individual transformations is very important. Matrix operations are not cumulative. For example, the result of a Graphics → Rotate → Translate → Scale → Graphics operation will be different from the result of a Graphics → Scale → Rotate → Translate → Graphics operation. The main reason that order is significant is that transformations like rotation and scaling are done with respect to the origin of the coordinate system. The result of scaling an object that is centered at the origin is different from the result of scaling an object that has been moved away from the origin. Similarly, the result of rotating an object that is centered at the origin is different from the result of rotating an object that has been moved away from the origin.

22

Scale → Rotate → Translate composite transformation

23

Translate → Rotate → Scale composite transformation with Append

Translate → Rotate → Scale composite transformation with Prepend

Composite transformation order

Rigid Motion

• A rigid motion is the action of taking an object and moving it to a different location without altering its shape or size. Reflections, rotations, translations, and glide reflections are all examples of rigid motions. In fact, every rigid motion is one of these four kinds.

24

Rigid Motion

• Reflection• Every reflection is completely determined

by its axis of reflection. 2. Every reflection is completely determined by a single point-image pair P and P 0 (provided that P 6= P 0 ). 3. The fixed points of a reflection are exactly the points on its axis of reflection. 4. Reflections are improper rigid motions (they reverse clockwise and counterclockwise orientations). 5. Applying the same reflection twice gives the identity motion.

25

Rigid Motion

• Rotation• Every rotation is completely determined by

its rotocenter and the angle of rotation. 2. A 360◦ rotation is equivalent to the identity motion. (So are720◦ , 1040◦ , . . . ) 3. A rotation that is not the identity has exactly one fixed point: the rotocenter. 4. Rotations are proper rigid motions (they preserve clockwise/counterclockwise orientations). 5. A rotation is determined by any two point-image pairs P, P 0 and Q, Q 0

26

Rigid Motion

• Translation• 1. Every translation is completely determined

by a vector of translation, v. 2. In a translation other than the identity, every point gets moved, so there are no fixed points. 3. Translations are proper rigid motions (they preserve clockwise/counterclockwise orientations). 4. A translation is determined by any one point-image pair P, P 0 . 5. The effect of a translation can be reversed by a translation in the opposite direction (with vector −v).

27

Reflections

28

Reflection is nothing more than a rotation of the object by 180o. In case of reflection the image formed is on the opposite side of the reflective medium with the same size. Therefore we use the identity matrix with positive and negative signs according to the situation respectively.

Reflections

29

x

y

x

y

x

y

Reflections

30

Reflections wrt to an arbitrary axis

31

Shear in x and y -direction

• A shear along the x direction in 2D changes a rectangle (with lower right corner at the origin) into a parallelogram as follows

The transformation has the properties: a) The y coordinate of any point (x,y) is unchanged b) the x coordinate is stretched in a

linear way, based on the height of the point above the x axis - i.e. on y. Thus the coordinate change has the form:

x' = x + ay y' = y where a is a constant that measures the degree of shearing. If

a is negative then the shearing is in the opposite direction.

32

Matrix Notation• A suitable multiplicative matrix description of

the transform is given by: SHx(a) = | 1 a 0 |

| 0 1 0 | | 0 0 1 |

• We can similarly introduce a shearing along the y axis, which would have the form:

• x' = x y' = y + bx • and in this case a suitable matrix description is

given by: • SHy(b) = | 1 0 0 |

| b 1 0 | | 0 0 1 |

33

Raster Methods

Raster Graphics• Image is represented as a rectangular grid of

colored pixels– PIXEL = Pictu(X)re ELement

• Translation• If you want to move a point (x0 , y0) to a new

position (xt , yt)• The transformation would be

xt = x0 + dx and yt = y0 + dy• For motion dx and dy are the components of

the velocity vectordx = cos v and dy = - sin v

34

Raster Methods• Scaling• Multiply the coordinates of each vertex by the scale factor• Everything will expand from the center• The transformation would be

xt = x0 * scale and yt = y0 * scale

• Rotation• Spin and object around it centered around the z-axis• Rotate each point the same angle

– Positive angles are clockwise– Negative angles are counterclockwise– C++ uses radians (not degrees)

• The transformation would be

xt = x0 * cos() – y0 * sin()

yt = y0 * cos() + x0 * sin()

35

3D Transformation

• A 3D point (x,y,z) – x,y, and z coordinates

• We will still use column vectors to represent points

• Homogeneous coordinates of a 3D point

(x,y,z,1) • Transformation will be performed

using 4x4 matrix

36

3D Translation

• Very similar to 2D transformation

• Translation transformation

37

11000

100

010

001

1

z

y

x

t

t

t

z

y

x

x

y

x

Homogenous coordinates

3D Scaling

• Very similar to 2D transformation• Scaling transformation

38

11000

000

000

000

1

z

y

x

s

s

s

z

y

x

z

y

x

Homogenous coordinates

3D Rotation

• 3D rotation is done around a rotation axis

• Fundamental rotations – rotate about x, y, or z axes

• Counter-clockwise rotation is referred to as positive rotation (when you look down negative axis)

39

3D Rotation wrt z-axis

• Rotation about z – similar to 2D rotation

40

x

y

z

+

11000

0100

00cossin

00sincos

1

z

y

x

z

y

x

zz

yxy

yxx

'

cossin'

sincos'

• Rotation about y: z -> y, y -> x, x->z

41

11000

0cos0sin

0010

0sin0cos

1

z

y

x

z

y

x

yy

xzx

xzz

'

cossin'

sincos'

y

z

x

x

y

z

3D Rotation wrt y-axis

• Rotation about x (z -> x, y -> z, x->y)

42

x

y

z

11000

0cossin0

0sincos0

0001

1

z

y

x

z

y

x

xx

zyz

zyy

'

cossin'

sincos'

z

x

y

3D Rotation wrt x-axis

3D Rotation about Arbitrary Axes

• Rotate p about the by the angle

x

y

zr

),,( zyxp

r

43

Inverse of 3D Transformations

11000

100

010

001

1

z

y

x

t

t

t

z

y

x

x

y

x

• Invert the transformation• In general, X= AX’->x’=A-

1X

1

'

'

'

1000

100

010

001

1

z

y

x

t

t

t

z

y

x

x

y

x

11000

0100

00cossin

00sincos

1

z

y

x

z

y

x

1

'

'

'

1000

0100

00cossin

00sincos

1

z

y

x

z

y

x

)(zR)( zR

T(tx,ty,tz) T(-tx,-ty,-tz)

3D Rotation about Arbitrary Axes

• Rotate p about the by the angle

45

x

y

zr

),,( zyxp

r

3D Rotation about Arbitrary Axes

• Translate so that rotation axis passes through the origin

46

x

y

zr

TRRRRRT zyzyz )()()()()(1

3D Rotation about Arbitrary Axes

• Rotation by about z-axis

47

x

y

z

r

TRRRRRT zyzyy )()()()()(1

3D Rotation about Arbitrary Axes

• Rotation by about y-axis

48

x

y

z

r

xTRRRRRT zyzyy )()()()()(1

3D Rotation about Arbitrary Axes

• Rotation by about z-axis

49

x

y

z

r

xTRRRRRT zyzyy )()()()()(1

3D Rotation about Arbitrary Axes

• Rotation by about y-axis

50

x

y

z

r

xTRRRRRT zyzyy )()()()()(1

3D Rotation about Arbitrary Axes

• Translate the object back to original point

51

x

y

z

r

TRRRRRT zyzyz )()()()()(1

3D Shearing

52

3D Reflection

53

3D Reflection Transformation

54

Affine Transformation

55

3D Coordinate Transformation

• Transform object description from to

56

pj

i

i

j

o

o

ji ij

1

'

'

'

1000

'

'

'

10

0

0

z

y

x

zkkjkik

ykjjjij

xkijiii

z

y

x

TTT

TTT

TTT

),,( 000 zyx

k

'k

poooop

3D Coordinate Transformation

• Transform object description from to

57

pj

i

i

j

o

o

ji ij

1

'

'

'

1000

'

'

'

10

0

0

z

y

x

zkkjkik

ykjjjij

xkijiii

z

y

x

TTT

TTT

TTT

),,( 000 zyx

k

'k

poooop

3D Coordinate Transformation

• Transform object description from to

58

i

i

j

o

ji ij

1

'

'

'

1000

'

'

'

10

0

0

z

y

x

zkkjkik

ykjjjij

xkijiii

z

y

x

TTT

TTT

TTT

k

p'i

'j

3D Coordinate Transformation

• Transform object description from to

59

ji ij

'i

11000

0cos0sin

0010

0sin0cos

1

z

y

x

z

y

x

x

y

z

Composite 3D Transformation

• Similarly, we can easily extend composite transformation from 2D to 3D

60

1

2

3

),,( 0yx

3c

2c

1c

0c

A

Composite 3D Transformation

61

xRRhTRhTRRRhTRRRzyxTp )()()0,,0()()0,,0()()()()0,,0()()()(),,( 332211110000000

References• http://www.math.tau.ac.il/~dcor/Graphics/cg-slides/geom3d.p

df• http://www-inst.eecs.berkeley.edu/~cs184/fa05/lectures/lectu

re-04.pdf• https://www.cg.tuwien.ac.at/courses/CG1/textblaetter/englisc

h/02%20Geometric%20Transformations%20(engl).pdf• http://www.inf.ed.ac.uk/teaching/courses/cg/lectures/lect2cg2

x6.pdf• http://www.cs.trinity.edu/~jhowland/cs3353/intro/intro/• http://math.hws.edu/graphicsbook/c2/s3.html#graphics2d.3.2• http://cs455.cs.byu.edu/lectureslides/Discussion06.pdf• https://cseweb.ucsd.edu/classes/wi03/cse167/lectures/

lec9.pdf• http://www.cs.cornell.edu/courses/cs4620/2014fa/lectures/

10transforms3d.pdf• https://www.math.ku.edu/~jmartin/courses/math105-F11/

Lectures/chapter11-part3.pdf62

References

• http://www.win.tue.nl/~vanwijk/2IV60/2IV60_3_2D_transformations.pdf

• http://www.dgp.toronto.edu/~hertzman/418notes.pdf• http://nccastaff.bmth.ac.uk/hncharif/MathsCGs/

Transformations.pdf• http://www.in.tum.de/fileadmin/user_upload/Lehrstuehle/

Lehrstuhl_XV/Teaching/SS07/ComputerGraphics/CG-06-Transformations.pdf

• http://web.cse.ohio-state.edu/~parent/classes/581/Lectures/5.2DtransformsAhandout.pdf

• https://en.wikipedia.org/wiki/Geometric_transformation• http://cs.boisestate.edu/~tcole/cs341/fall04/vg/

10ch53d.pdf

63

top related