3d object representation -...

32
Graphics Graphics Lab @ Korea University Geometric Transformation Korea University http://kucg.korea.ac.kr

Upload: buimien

Post on 23-Mar-2018

218 views

Category:

Documents


5 download

TRANSCRIPT

Graphics

Graphics Lab @ Korea University

Geometric

Transformation

Korea University

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

Transformation

Model Transformation

Lighting

Viewing Transformation

Projection Transformation

Clipping

Viewport Transformation

Scan Conversion

Image

3D Primitives

Transform into 3D World Coordinate System

Illustrate According toLighting and Reflectance

Transform into 3D Viewing Coordinate System

Transform into 2D Viewing Coordinate System

Clip Primitives outside Window’s View

Transform into Viewport

Draw Pixels

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

Transformation

3D Object Coordinate

Model Transformation

Viewing Transformation

Projection Transformation

Viewport Transformation

p(x’, y’) or p(u, v)

P(x, y, z)

3D World Coordinate

3D Viewing Coordinate

2D Projection Coordinate

2D Device Coordinate

3D Viewing Coordinate

3D Object Coordinate

3D World Coordinate

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

Contents

Translation

Scaling

Rotation

Other Transformations

Coordinate Transformations

OpenGL Transformations

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

Transformation in 3D

Transformation matrix

33 : Scaling, Reflection, Shearing, Rotation

31 : Translation

14 : Homogeneous Representation

1131

1333

000 S

LIFC

KHEB

JGDA

1×4

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

3D Translation

zyx tzztyytxx ',','

11000

100

010

001

1

'

'

'

z

y

x

t

t

t

z

y

x

z

y

x

xz

y

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

3D Scaling

zyx szzsyysxx ',','

11000

000

000

000

1

'

'

'

z

y

x

s

s

s

z

y

x

z

y

x

xz

y

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

Fixed-point Scaling

11000

100

010

001

1000

000

000

000

1000

100

010

001

1

'

'

'

),,( ),,( ),,(z

y

x

z

y

x

s

s

s

z

y

x

z

y

x

zyxTsssSzyxTf

f

f

z

y

x

f

f

f

fffzyxfff

x x x xzzzz

y y y y

Original Position Translation Scaling Inverse Translation

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

3D Rotation

Coordinate-axes rotations

x-axis rotation

y-axis rotation

z-axis rotation

General 3D rotations

Rotation about an axis that is parallel to one of the

coordinate axes

Rotation about an arbitrary axis

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

Coordinate-axes Rotations

z-Axis Rotation x-Axis Rotation y-Axis Rotation

11000

0100

00cossin

00sincos

1

'

'

'

z

y

x

z

y

x

11000

0cossin0

0sincos0

0001

1

'

'

'

z

y

x

z

y

x

11000

0cos0sin

0010

0sin0cos

1

'

'

'

z

y

x

z

y

x

z

y

x

z

y

x

z

y

x

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

Order of Rotations

Order of rotations affects final position

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

General 3D Rotations

Rotation about an axis that is parallel to one of the coordinate axes

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

General 3D Rotations

Rotation about an arbitrary axis

Basic Idea

1. Translate (x1, y1, z1) to the origin

2. Rotate (x’2, y’2, z’2) on to the z axis

3. Rotate the object around the z-axis

4. Rotate the axis to the original

orientation

5. Translate the rotation axis to the

original position

(x2, y2, z2)

(x1, y1, z1)

x

y

R-1

T-1

R

T

TRRRRRTR xyzyx

111

R

z

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

General 3D Rotations

Step 1. Translate

1000

100

010

001

1

1

1

z

y

x

T

x

y

z

(x2, y2, z2)

(x1, y1, z1)

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

General 3D Rotations

Step 2. Rotate about x axis by α

1000

0//0

0//0

0001

1000

0cossin0

0sincos0

0001

dcdb

dbdcx

R

d

c

cb

c

d

b

cb

b

22

22

cos

sin

(a, b, c)(0, b, c)

ProjectedPoint

RotatedPoint

x

y

z

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

Arbitrary Axis Rotation

Step 3. Rotate about y axis by β (clockwise)

222222

cos,sin

dacbal

l

d

l

a

1000

0/0/

0010

0/0/

1000

0cos0sin

0010

0sin0cos

ldla

lald

y

R

x

y

z

ProjectedPoint

RotatedPoint

d

(a,0,d)

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

Arbitrary Axis Rotation

Step 4. Rotate about z axis by the angle

1000

0100

00cossin

00sincos

zR

y

x

z

l

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

Arbitrary Axis Rotation

Step 5. Reverse transformation

To place the axis back in its initial position

x

y

z

1000

0cos0sin

0010

0sin0cos

1000

0cossin0

0sincos0

0001

1000

100

010

001

1

1

1

111

z

y

x

yx RRT

TRRRRRTR xyzyx

111

l

l

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

Find the new coordinates of a unit cube 90º-rotated about an axis defined by its endpoints A(2, 1, 0) and B(3, 3, 1).

Example

A Unit Cube

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

Example

Step1. Translate point A to the origin

T(-2, -1, 0)

1000

0100

1010

2001

T

x

z

y

A’(0, 0, 0)

B’(1, 2, 1)

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

1000

05

5

5

520

05

52

5

50

0001

xR

6121,5

5

5

1cos,

5

52

5

2

12

2sin 222

22

l

Example

Step 2. Rotate axis A’B’ about the x axis by

Until it lies on the xz plane

x

z

y

l

(0, 2, 1)

B”(1, 0, )

B’(1, 2, 1)

5

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

x

z

y

1000

06

300

6

6

0010

06

60

6

30

yR

6

30

6

5cos,

6

6

6

1sin

Example

Step 3. Rotate axis A’B’’ about the y axis by β

Until it coincides with the z axis

(0, 0, 6)

l

B”(1, 0, )5

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

Example

Step 4. Rotate the cube 90° about the z axis

Finally, the concatenated rotation matrix about the

arbitrary axis AB becomes,

TRRRRRTR xyzyx 90111

1000

0100

0001

0010

90zR

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

1000

560.0167.0741.0650.0

151.1075.0667.0742.0

742.1983.0075.0166.0

1000

0100

1010

2001

1000

05

5

5

520

05

52

5

50

0001

1000

06

300

6

6

0010

06

60

6

30

1000

0100

0001

0010

1000

06

300

6

6

0010

06

60

6

30

1000

05

5

5

520

05

52

5

50

0001

1000

0100

1010

2001

R

Example

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

PRP

Example

Multiplying R(θ) by the point matrix of the original cube

11111111

076.0091.0560.0726.0817.0650.0301.1467.1

483.0409.0151.1225.1184.0258.0484.0558.0

891.2909.1742.1725.2816.2834.1667.1650.2

11111111

10011001

00001111

11001100

1000

560.0167.0741.0650.0

151.1075.0667.0742.0

742.1983.0075.0166.0

P

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

11000

0100

010

001

1

'

'

'

z

y

x

b

a

z

y

x

11000

0100

0010

0001

1

'

'

'

z

y

x

z

y

x

Other Transformations

Reflection to the xy plane

z-axis shear

xz

y

xz

y

(a, b, c) (a, b, -c)

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

Coordinate Transformations

Coordinate systems

Local (modeling) coordinate

World coordinate

Scene

<Local Coordinate System>

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

Coordinate Transformations

Coordinate systems

Local (modeling) coordinate

World coordinate

Scene

<Word Coordinate System>

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

OpenGL Transformations

void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

glRotatef(45.0, 0.0, 0.0, 1.0);

glutSolidCube(0.3);

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

OpenGL Transformations

void glTranslatef(GLfloat dx, GLfloat dy, GLfloat dz)

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

glTranslatef(0.5, -0.5, 0.0);

glutSolidCube(0.3);

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

OpenGL Transformations

void glScalef(GLfloat sx, GLfloat sy, GLfloat sz)

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

glScalef(2.0, 1.0, 1.0);

glutSolidCube(0.3);

http://kucg.korea.ac.kr

KUCG

Graphics Lab @ Korea University

OpenGL Transformations

OpenGL Transformation Sample

http://kucg.korea.ac.kr