1 of 92

Geometrical Transformation

​

​

​

Tong-Yee Lee

1

2 of 92

Course Outline

Standard Graphics Pipeline

Local coordinate

3 of 92

Outline

  • General Transform

​

    • Scale,rotation, translation etc

​

​

3

4 of 92

Modeling Transform

  • Specify transformation for objects
    • Allow definitions of objects in own local coordinate systems
    • Allow use of object definition multiple times in a scene (in global coordinate system)

4

Insert them

Into different

Locations of

World coordinate

system

5 of 92

Overview

  • 2D transformations
    • Basic 2-D transformations
    • Matrix representation
    • Matrix composition
  • 3D transformations
    • Basic 3-D transformation
    • Same as 2-D

5

6 of 92

2-D Transformations

6

Local coordinate

To world coordinate

7 of 92

2-D Transformations

7

8 of 92

2-D Transformations

8

Usually, (0,0) point

Is used to align

Local and world coordinates

first

9 of 92

2-D Transformations

9

10 of 92

2-D Transformations

10

11 of 92

2-D Transformations

11

12 of 92

Basic 2D Transformations

12

13 of 92

Basic 2D Transformations

13

14 of 92

Scaling

S = S(sx, sy, sz) =

14

Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

x’=sxx

y’=syy

z’=szz

p’=Sp

Expand or contract along each axis (fixed point of origin)

15 of 92

Reflection

corresponds to negative scale factors

15

Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

original

sx = -1 sy = 1

sx = -1 sy = -1

sx = 1 sy = -1

16 of 92

General 2D Scaling

16

Move to origin

Scale

Move back

17 of 92

Basic 2D Transformations

17

18 of 92

Rotation around the origin (2-D)

18

Ex: polar coordinate (極座標)

19 of 92

Rotation around the origin (2-D)

19

20 of 92

Rotation around the origin (2-D)

20

21 of 92

Rotation (3-D)

21

22 of 92

Rotation (3-D)

22

23 of 92

Basic 2D Transformations

23

24 of 92

Basic 2D Transformations

24

25 of 92

Translation

Although we can move a point to a new location in infinite ways, when we move many points there is usually only one way

25

Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009

object

translation: every point displaced

by same vector

26 of 92

tx

ty

27 of 92

Basic 2D Transformations

27

28 of 92

2D Rotation

April 2010

28

29 of 92

General 2D Rotation

April 2010

29

Move to origin

Rotate

Move back

30 of 92

Matrix Representation

30

31 of 92

Matrix Representation

31

32 of 92

2x2 Matrix

32

33 of 92

Scaling

33

34 of 92

Scaling Around A Point

34

35 of 92

2x2 Matrix

35

36 of 92

Shear (2-D)

36

37 of 92

Shear (3-D)

37

38 of 92

2x2 Matrix

38

39 of 92

2x2 Matrix

39

40 of 92

2D Reflections

April 2010

40

41 of 92

2x2 Matrix

41

42 of 92

2D Translation

42

43 of 92

Basic 2D Transformations

43

44 of 92

Homogeneous Coordinates

44

i.e., vector

(x1,y1,1) – (x2,y2,1)

= (x1-x2.y1-y2,0)

i.e., projection, w is related

to depth from eye

45 of 92

Matrix Composition

45

w=1

46 of 92

Matrix Composition

46

i.e. 1 point is OK

i.e. if many points are used, matries are composed first

47 of 92

Matrix Composition

47

(交換律)

T*R*P != RT*P

48 of 92

Matrix Composition

48

i.e., M= T(a,b)*R(Q)*T(-a,-b)

P’=M*P

49 of 92

3D Transformations

49

w=1

50 of 92

Basic 3D Transformations

50

w=1

51 of 92

Basic 3D Transformations

51

52 of 92

General rotation about an axis

52

53 of 92

Developing the General Rotation Matrix�

53

t= <Xv, Yv, Zv>

→

54 of 92

54

55 of 92

55

56 of 92

56

57 of 92

57

58 of 92

58

59 of 92

59

60 of 92

Developing the General Rotation Matrix

  • Be careful …………

60

Z

X

(+,+)

(-,-)

In both cases, tan(y/x) are positive.

So, we need to carefully choose

it by checking the signs of x and y

61 of 92

Example -1

  • planet.c
    • Control:
      • ‘d’
      • ‘y’
      • ‘a’
      • ‘A’
      • ESC

61

62 of 92

Example -3

void GL_display() // GLUT display function

{

// clear the buffer

glClear(GL_COLOR_BUFFER_BIT);

​

glColor3f(1.0, 1.0, 1.0);

glPushMatrix();

glutWireSphere(1.0, 20, 16); // the Sun

glRotatef(year, 0.0, 1.0, 0.0);

glTranslatef(3.0, 0.0, 0.0);

glRotatef(day, 0.0, 1.0, 0.0);

glutWireSphere(0.5, 10, 8); // the Planet

glPopMatrix();

// swap the front and back buffers

glutSwapBuffers();

}

​

62

63 of 92

Example -4

void GL_idle() // GLUT idle function

{

day += 10.0;

if(day > 360.0) day -= 360.0;

​

year += 1.0;

if(year > 360.0) year -= 360.0;

​

// recall GL_display() function

glutPostRedisplay();

}

​

63

64 of 92

Example -5

void GL_keyboard(unsigned char key, int x, int y) // GLUT keyboard function

{

switch(key)

{

case 'd': day += 10.0;

if(day > 360.0) day -= 360.0;

glutPostRedisplay();

break;

case 'y': year += 1.0;

if(year > 360.0) year -= 360.0;

glutPostRedisplay();

break;

case 'a': glutIdleFunc(GL_idle); // assign idle function

break;

case 'A': glutIdleFunc(0);

break;

case 27: exit(0);

}

}

64

65 of 92

Example -6

int main(int argc, char** argv)

{

glutInit(&argc, argv);

glutInitWindowSize(500, 500);

glutInitWindowPosition(0, 0);

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);

glutCreateWindow("Planet");

init();

glutDisplayFunc(GL_display);

glutReshapeFunc(GL_reshape);

glutKeyboardFunc(GL_keyboard);

glutMainLoop();

return 0;

}

​

65

66 of 92

Review of Raster Displays

67 of 92

67

p1

t1

t2

n

p0

p2

68 of 92

68

p.s.vector will not be changed

By translation matrix

69 of 92

69

70 of 92

Inverse Transformation

70

71 of 92

Inverse Transformation

71

72 of 92

OpenGL transformation Matrices

72

73 of 92

OpenGL transformation Matrices

73

74 of 92

Another Example: Robot

74

75 of 92

75

(0,0,0)

Rotation center is at

(-1,0,0) instead of

(0,0,0)

2

shoulder

elbow

glTranslate(2,0,0);

glTranslate(-1,0,0);

76 of 92

OpenGL transformation Matrices

76

77 of 92

OpenGL transformation Matrices

77

78 of 92

78

79 of 92

79

80 of 92

80

81 of 92

81

82 of 92

82

83 of 92

83

84 of 92

84

85 of 92

85

86 of 92

86

87 of 92

87

88 of 92

88

89 of 92

89

90 of 92

90

(a)

(b)

Step 1:

Separate

x vector

​

Note: vector a

is a unit vector

i.e: cos(90-Ɵ) = sin(Ɵ)

��Angular displacement �glRotate(θ, Ax,Ay,Az)�

91 of 92

91

The above formula is a matrix form, so we can use Matrix to compute rotation

In above equation, v=(x,y,z)T and n=(ax,ay,az)T

92 of 92

92