3-d transformational geometry cs418 computer graphics john c. hart

Post on 08-Jan-2018

228 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

3-D Affine Transformations General Translation

TRANSCRIPT

3-D Transformational Geometry

CS418 Computer GraphicsJohn C. Hart

Graphics Pipeline

Homogeneous Divide

ModelCoords

ModelXform

WorldCoords

ViewingXform

StillClip

Coords.Clipping

WindowCoordinates

Windowto

Viewport

ViewportCoordinates

ClipCoords.

ViewingCoords

PerspectiveDistortion

3-D Affine Transformations• General

• Translation

=

=

3-D Coordinates• Points represented

by 4-vectors• Need to decide

orientation ofcoordinate axes 1

xyz

y

z

x

x

z

y

Right Handed Coord. Sys.

Left Handed Coord. Sys.

x

y

+z (rhc)

+z (lhc)

Scale

1 1 1

a x axb y by

c z cz

Uniform Scalea = b = c = ¼

z

yx

Squasha = b = 1, c = ¼

Stretcha = b = 1, c = 4

Projecta = b = 1, c = 0

Inverta = b = 1, c = -1

3-D Rotations

• About x-axis– rotates y z

• About y-axis– rotates z x

• About z-axis– rotates x y

• Rotations do not commute!

1cos sinsin cos

1

cos sin1

sin cos1

cos sinsin cos

11

Arbitrary Axis Rotation• Rotations about x, y and z axes• Rotation x rotation = rotation• Can rotate about any axis direction• Can do simply with vector algebra

– Ensure ||v|| = 1– Let o = (p v)v– Let a = p – o– Let b = v a, (note that ||b||=||a||)– Then p’ = o + a cos q + b sin q

• Simple solution to rotate a single point• Difficult to generate a rotation matrix

to rotate all vertices in a meshed model

x

y

z

v

pp’

ab

a

b

p

p’

||a||cos

||a||sin

o

Arbitrary Rotation• Find a rotation matrix that rotates by

an angle q about an arbitrary unit direction vector v

xz

v

v = (xv,yv,zv), xv2+yv

2+zv2=1

Rotateby

about v[ ]=[ ][ ][ ]Rotatez to v

Rotatev to z

Rotateby

about z

y

z

vx

z

v

z

Rotate v to z

1. Project v onto the yz plane andlet d = sqrt(yv

2 + zv2)

x

y

z

vvyz

v = (xv,yv,zv), xv2+yv

2+zv2=1

zv

yv

d

Rotate v to z

1. Project v onto the yz plane andlet d = sqrt(yv

2 + zv2)

2. Then cosfx = zv/d and sinfx = yv/d

x

y

z

vvyz

v = (xv,yv,zv), xv2+yv

2+zv2=1

zv

yv

d

fx

Rotate v to z

1. Project v onto the yz plane andlet d = sqrt(yv

2 + zv2)

2. Then cosfx = zv/d and sinfx = yv/d3. Rotate v by fx about x into the xz plane

x

y

z

vvyz

v = (xv,yv,zv), xv2+yv

2+zv2=1

zv

yv

d

fx

1

1

z yd dy zd d

v v

v v

Rotate v to z

1. Project v onto the yz plane andlet d = sqrt(yv

2 + zv2)

2. Then cosfx = zv/d and sinfx = yv/d3. Rotate v by fx about x into the xz plane

x

y

z

v

vxz

v = (xv,yv,zv), xv2+yv

2+zv2=1

fx

1

1

z yd dy zd d

v v

v v

Rotate v to z

1. Project v onto the yz plane andlet d = sqrt(yv

2 + zv2)

2. Then cosfx = zv/d and sinfx = yv/d3. Rotate v by fx about x into the xz plane4. Then cosfy = d and sinfy = xv x

y

z

v

vxz

v = (xv,yv,zv), xv2+yv

2+zv2=1

fy 1d

xv

1

1

z yd dy zd d

v v

v v

Rotate v to z

1. Project v onto the yz plane andlet d = sqrt(yv

2 + zv2)

2. Then cosfx = zv/d and sinfx = yv/d3. Rotate v by fx about x into the xz plane4. Then cosfy = d and sinfy = xv

5. Rotate vxz by fy about y into the z axisx

y

z

v

vxz

v = (xv,yv,zv), xv2+yv

2+zv2=1

fy

fx

1

1

11

z yd dy zd d

d x

x d

v v

v v

v

v

Rotate about v• Let Rv( )q be the rotation matrix for

rotation by q about arbitrary axis direction v

• Recall (Rx Ry) is the matrix (product) that rotates direction v to z axis

• ThenRv( )q = (Ry Rx)-1 Rz(q) (Ry Rx)

= Rx-1 Ry

-1 Rz(q) Ry Rx

= RxT Ry

T Rz(q) Ry Rx

(since the inverse of a rotation matrix is the transpose of the rotation matrix)

Easier Way• Find an orthonormal vector system

x

y

z

u

v

Easier Way• Find an orthonormal vector system

– Let r = u v/||uv||

x

y

z

u

v r

Easier Way• Find an orthonormal vector system

– Let r = u v/||uv||– Let u’ = v r

x

y

z

u

v r

u’

Easier Way• Find an orthonormal vector system

– Let r = u v/||uv||– Let u’ = v r

• Find a rotationfrom <r,u’,v> <x,y,z>

' 1' 0

0'11 1

x x x x

y y y y

z z z z

r u v rr u v r

r u v r

1' ' ' 0

0111

x y z x

x y z y

x y z z

r r r ru u u r

v v v r

x

y

z

u

v r

u’

Graphics Pipeline

Homogeneous Divide

ModelCoords

ModelXform

WorldCoords

ViewingXform

StillClip

Coords.Clipping

WindowCoordinates

Windowto

Viewport

ViewportCoordinates

ClipCoords.

ViewingCoords

PerspectiveDistortion

W2V Persp View Model

ScreenVertices

ModelVertices

Graphics Pipeline

Homogeneous Divide

ModelCoords

ModelXform

WorldCoords

ViewingXform

StillClip

Coords.Clipping

WindowCoordinates

Windowto

Viewport

ViewportCoordinates

ClipCoords.

ViewingCoords

PerspectiveDistortion

W2V Persp View Model01 1

s m

s m

m

x xy y

z

Graphics Pipeline

Homogeneous Divide

ModelCoords

ModelXform

WorldCoords

ViewingXform

StillClip

Coords.Clipping

WindowCoordinates

Windowto

Viewport

ViewportCoordinates

ClipCoords.

ViewingCoords

PerspectiveDistortion

01

s

s

xy

1

m

m

m

xyz

M

Transformation Order

01

s

s

xy

1

m

m

m

xyz

M

x

y

z

glutSolidTeapot(1); glRotate3f(-90, 0,0,1);glTranslate3f(0,1,0);glutSolidTeapot(1);

glTranslate3f(0,1,0);glRotate3f(-90, 0,0,1);glutSolidTeapot(1);

01

s

s

xy

1

m

m

m

xyz

M R T 01

s

s

xy

1

m

m

m

xyz

M T R

top related