computer graphics lecture 4 geometry & transformations

36
Computer Graphics Computer Graphics Lecture 4 Geometry & Transformations

Upload: stephen-bridewell

Post on 14-Dec-2015

228 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

Computer Graphics

Lecture 4

Geometry & Transformations

Page 2: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 2

Some Basics

• Basic geometric types.– Scalars s– Vectors v– Points p = p + s * v

• Transformations– Types of transformation: rotation, translation, scale.– Matrix representation– Order

• Geometric modelling– Hierarchical modelling– Polyhedral shapes.

Page 3: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 3

Transformations.

What is a transformation?

• P=T(P)

Why use them?

• Modelling- Create objects in natural/convenient coordinates-Multiple instances of a prototype shape-Kinematics of linkages/skeletons - robot animation

• Viewing– Windows and device independence– Virtual camera: parallel and perspective projections

Page 4: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 4

Types of TransformationsContinuous (preserves neighbourhoods)One to one, invertibleClassify by invariants or symmetries

Isometry (distance preserved)– Reflections (interchanges left-handed and

right-handed)– Rigid body motion: Rotations + TranslationsSimilarity (preserves angles)– Uniform scaleAffine (preserves parallel lines)– Non-uniform scales, shears or skewsCollineation (lines remain lines)– PerspectiveNon-linear (lines become curves)– Twists, bends, warps, morphs, ...

Page 5: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 5

2D Translations.

TPP

d

dT

y

xP

y

xP

dyydxx

yxP

yxPP

yx

Now

,,

torscolumn vec theDefine

axis.y toparallel d axis, x toparallel d distance a ),(Point totranslate

),,( as defined Point

y

x

yx

PP’

Page 6: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 6

2D Scaling from the origin.

y

x.

0

0

y

xor

Now

0

0

matrix theDefine

. ,.

axis.y thealong s and

axis, x thealong sfactor aby ),(Point to(stretch) scale a Perform

),,( as defined Point

y

x

y

x

y

x

yx

s

sPSP

s

sS

ysyxsx

yxP

yxPP

PP’

Page 7: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 7

2D Rotation about the origin.

y

x

r

r

P’(x’,y’)

P(x,y)

Page 8: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 8

2D Rotation about the origin.y

x

r

r

P’(x’,y’)

P(x,y)

y

sin.

cos.

ry

rx

x

Page 9: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 9

2D Rotation about the origin.

y

x

r

r

P’(x’,y’)

P(x,y)

y

sin.

cos.

ry

rx

x

cos.sin.sin.cos.)sin(.

sin.sin.cos.cos.)cos(.

rrry

rrrx

Page 10: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 10

2D Rotation about the origin.

sin.

cos.

ry

rx

cos.sin.sin.cos.)sin(.

sin.sin.cos.cos.)cos(.

rrry

rrrx

Substituting for r :

Gives us :

cos.sin.

sin.cos.

yxy

yxx

Page 11: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 11

2D Rotation about the origin.

cos.sin.

sin.cos.

yxy

yxx

Rewriting in matrix form gives us :

y

x

y

x.

cossin

sincos

PRPR

,

cossin

sincosmatrix theDefine

Page 12: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 12

Transformations.• Translation.

– P=T + P

• Scale– P=S P

• Rotation– P=R P

• We would like all transformations to be multiplications so we can concatenate them

• express points in homogenous coordinates.

Page 13: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 13

Homogeneous coordinates

• Add an extra coordinate, W, to a point.– P(x,y,W).

• Two sets of homogeneous coordinates represent the same point if they are a multiple of each other.– (2,5,3) and (4,10,6) represent the same point.

• At least one component must be non-zero (0,0,0) is not defined.

• If W 0 , divide by it to get Cartesian coordinates of point (x/W,y/W,1).

• If W=0, point is said to be at infinity.

Page 14: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 14

Homogeneous coordinates

• If we represent (x,y,W) in 3-space, all triples representing the same point describe a line passing through the origin.

• If we homogenize the point, we get a point of form (x,y,1)– homogenised points form a plane at W=1.

P

X

Y

W

W=1 plane

Page 15: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 15

Translations in homogenised coordinates

• Transformation matrices for 2D translation are now 3x3.

1

.

100

10

01

1

y

x

d

d

y

x

y

x

11

y

x

dyy

dxx

Page 16: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 16

Concatenation.

• We perform 2 translations on the same point:

),(),(),(

:expect weSo

),(),(),(

),(

),(

21212211

21212211

22

11

yyxxyxyx

yyxxyxyx

yx

yx

ddddTddTddT

ddddTPddTddTPP

ddTPP

ddTPP

Page 17: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 17

Concatenation.

?

100

10

01

.

100

10

01

: is ),(),(product matrix The

2

2

1

1

2211

y

x

y

x

yxyx

d

d

d

d

ddTddT

Matrix product is variously referred to as compounding, concatenation, or composition

Page 18: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 18

Concatenation.

Matrix product is variously referred to as compounding, concatenation, or composition.This single matrix is called the Coordinate Transformation Matrix or CTM.

100

10

01

100

10

01

.

100

10

01

: is ),(),(product matrix The

21

21

2

2

1

1

2211

yy

xx

y

x

y

x

yxyx

dd

dd

d

d

d

d

ddTddT

Page 19: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 19

Properties of translations.

),(),(T 4.

),(),(),(),( 3.

),(),(),( 2.

)0,0( 1.

1-yxyx

yxyxyxyx

yyxxyxyx

ssTss

ssTttTttTssT

tstsTttTssT

IT

Note : 3. translation matrices are commutative.

Page 20: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 20

Homogeneous form of scale.

y

xyx s

sssS

0

0),(

Recall the (x,y) form of Scale :

100

00

00

),( y

x

yx s

s

ssS

In homogeneous coordinates :

Page 21: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 21

Concatenation of scales.

!multiply easy to -matrix in the elements diagonalOnly

100

0ss0

00ss

100

0s0

00s

.

100

0s0

00s

: is ),(),(product matrix The

y2y1

x2x1

y2

x2

y1

x1

2211

yxyx ssSssS

Page 22: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 22

Homogeneous form of rotation.

1

.

100

0cossin

0sincos

1

y

x

y

x

)()(

: i.e ,orthogonal are matricesRotation

).()(

matrices,rotation For

1

1

TRR

RR

Page 23: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 23

Orthogonality of rotation matrices.

100

0cossin

0sincos

)( ,

100

0cossin

0sincos

)(

TRR

100

0cossin

0sincos

100

0cossin

0sincos

)(

R

Page 24: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 24

Other properties of rotation.

matters.order Otherwise

same, thearerotation of centres theifonly

)()()()(

and

)()()(

)0(

RRRR

RRR

IR

Page 25: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 25

Types of transformations.

• Rotation and translation– Angles and distances are preserved– Unit cube is always unit cube– Rigid-Body transformations.

• Rotation, translation and scale.– Angles & distances not preserved.– But parallel lines are.– Affine transformations.

Page 26: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 26

3D Transformations.

• Use homogeneous coordinates, just as in 2D case.• Transformations are now 4x4 matrices.• We will use a right-handed (world) coordinate

system - ( z out of page ).

z (out of page)

y

x

Note:Convenient to think of display asBeing left-handed !!( z into the screen )

Page 27: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 27

Translation in 3D.

1000

100

010

001

),,(z

y

x

zyx d

d

d

dddT

Simple extension to the 3D case:

Page 28: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 28

Scale in 3D.

1000

000

000

000

),,(z

y

x

zyx s

s

s

sssS

Simple extension to the 3D case:

Page 29: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 29

Rotation in 3D

• Need to specify which axis the rotation is about.• z-axis rotation is the same as the 2D case.

1000

0100

00cossin

00sincos

)(

zR

Page 30: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 30

Rotation in 3D

• For rotation about the x and y axes:

1000

0cos0sin

0010

0sin0cos

)( ,

1000

0cossin0

0sincos0

0001

)(

yx RR

Page 31: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 31

Rotation about an arbitrary axis?• Hard!

• But we know how to rotate about the major axes.

• So turn required rotation into one about major axis.

• We need to translate arbitrary axis a to pass through origin, rotate to align with major axis, perform rotation, and rotate and translate back to original position.

• Say Mz is the compound transformation to translate and

rotate a to align with z-axis, then Mz-1 is the reverse

transformation required to restore a to its original position.

• Ignore translation for present, a passes through origin…..

Page 32: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 32

How do we define M?M transforms a into a vector along the z-axis, ie. Ma = k

Construct the rotation matrix Ras follows:

Ra () = M-1Rz()M

A suitable M-1can be found with a little effort, ie. M-1k = a

First define axis direction a as a unit vector as:

a = (a1,a2,a3) = Rz(-)Rx(-)k = (sinsin, sincos, cos)

2

1tana

a

3

22

21tana

aa Thus: and:

Page 33: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 33

Rotation about arbitrary axisSo: M-1 = Rz()Rx() and therefore: M = Rx()Rz()

And the full expression for a rotation about an arbitrary axis is:

Ra() = T-1Rz()Rx()Rz()Rx()Rz()T

Example: consider axis through origin,

Thus = 45o and 0o and

Ra() = Rx(-45o)Rz()Rx(45o)

)2

1,2

1,0(a

Page 34: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 34

Transformations of coordinate systems.

• Have been discussing transformations as transforming points.

• Useful to think of them as a change in coordinate system.

• Model objects in a local coordinate system, and transform into the world system.

• Unrealistic to think all objects are defined in the same coordinate system.

Page 35: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 35

Transformations of coordinate systems.

1

)()(

)()(

ji

)(

:shown that be alsocan It

:onsubstitutiby obtain we

and

i systemin point a toj systemin point a converts that transform theas M Define

system coordinatein point a as Define

jiij

kjjiki

kkj

j

jji

i

i

MM

MMM

PMP

PMP

iP

Page 36: Computer Graphics Lecture 4 Geometry & Transformations

Computer Graphics

7/10/2008 Lecture 4 36

Transform Left-Right, Right-Left

1000

0100

0010

0001

RLLR MM

Transforms between world coordinates and viewing coordinates. That is: between a right-handed set and a left-handed set.