3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

23
3-D Transformational Geometry CS418 Computer Graphics John C. Hart

description

3-D Affine Transformations General Translation

Transcript of 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

Page 1: 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

3-D Transformational Geometry

CS418 Computer GraphicsJohn C. Hart

Page 2: 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

Graphics Pipeline

Homogeneous Divide

ModelCoords

ModelXform

WorldCoords

ViewingXform

StillClip

Coords.Clipping

WindowCoordinates

Windowto

Viewport

ViewportCoordinates

ClipCoords.

ViewingCoords

PerspectiveDistortion

Page 3: 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

3-D Affine Transformations• General

• Translation

=

=

Page 4: 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

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)

Page 5: 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

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

Page 6: 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

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

Page 7: 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

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

Page 8: 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

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

Page 9: 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

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

Page 10: 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

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

Page 11: 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

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

Page 12: 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

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

Page 13: 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

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

Page 14: 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

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

Page 15: 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

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)

Page 16: 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

Easier Way• Find an orthonormal vector system

x

y

z

u

v

Page 17: 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

Easier Way• Find an orthonormal vector system

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

x

y

z

u

v r

Page 18: 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

Easier Way• Find an orthonormal vector system

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

x

y

z

u

v r

u’

Page 19: 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

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’

Page 20: 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

Graphics Pipeline

Homogeneous Divide

ModelCoords

ModelXform

WorldCoords

ViewingXform

StillClip

Coords.Clipping

WindowCoordinates

Windowto

Viewport

ViewportCoordinates

ClipCoords.

ViewingCoords

PerspectiveDistortion

W2V Persp View Model

ScreenVertices

ModelVertices

Page 21: 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

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

Page 22: 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

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

Page 23: 3-D Transformational Geometry CS418 Computer Graphics John C. Hart.

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