Geometrical Transformation
Tong-Yee Lee
1
Course Outline
Standard Graphics Pipeline
Local coordinate
Outline
3
Modeling Transform
4
Insert them
Into different
Locations of
World coordinate
system
Overview
5
2-D Transformations
6
Local coordinate
To world coordinate
2-D Transformations
7
2-D Transformations
8
Usually, (0,0) point
Is used to align
Local and world coordinates
first
2-D Transformations
9
2-D Transformations
10
2-D Transformations
11
Basic 2D Transformations
12
Basic 2D Transformations
13
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)
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
General 2D Scaling
16
Move to origin
Scale
Move back
Basic 2D Transformations
17
Rotation around the origin (2-D)
18
Ex: polar coordinate (極座標)
Rotation around the origin (2-D)
19
Rotation around the origin (2-D)
20
Rotation (3-D)
21
Rotation (3-D)
22
Basic 2D Transformations
23
Basic 2D Transformations
24
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
tx
ty
Basic 2D Transformations
27
2D Rotation
April 2010
28
General 2D Rotation
April 2010
29
Move to origin
Rotate
Move back
Matrix Representation
30
Matrix Representation
31
2x2 Matrix
32
Scaling
33
Scaling Around A Point
34
2x2 Matrix
35
Shear (2-D)
36
Shear (3-D)
37
2x2 Matrix
38
2x2 Matrix
39
2D Reflections
April 2010
40
2x2 Matrix
41
2D Translation
42
Basic 2D Transformations
43
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
Matrix Composition
45
w=1
Matrix Composition
46
i.e. 1 point is OK
i.e. if many points are used, matries are composed first
Matrix Composition
47
(交換律)
T*R*P != RT*P
Matrix Composition
48
i.e., M= T(a,b)*R(Q)*T(-a,-b)
P’=M*P
3D Transformations
49
w=1
Basic 3D Transformations
50
w=1
Basic 3D Transformations
51
General rotation about an axis
52
Developing the General Rotation Matrix�
53
t= <Xv, Yv, Zv>
→
54
55
56
57
58
59
Developing the General Rotation Matrix
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
Example -1
61
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
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
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
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
Review of Raster Displays
67
p1
t1
t2
n
p0
p2
68
p.s.vector will not be changed
By translation matrix
69
Inverse Transformation
70
Inverse Transformation
71
OpenGL transformation Matrices
72
OpenGL transformation Matrices
73
Another Example: Robot
74
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);
OpenGL transformation Matrices
76
OpenGL transformation Matrices
77
78
79
80
81
82
83
84
85
86
87
88
89
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
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