Lecture3 PDF
Lecture3 PDF
Topics:
1
Coordinate systems and frames
v = 1 v1 + 2 v2 + 3 v3 .
v2
v = 1v 1 + 2v 2 + 3v 3
1
v1
v3
2
Suppose we want to (linearly) change the basis vectors v 1 , v2 , v3 to u1 , u2 ,
u3 . We express the new basis vectors as combinations of the old ones,
T T
where a = ( 1 2 3 ) and b = ( 1 2 3 ) , then
v1 u1 v1
T T T
a v2 = v = b u2 = b M v2 ,
v3 u3 v3
a = M T b and b = (M T )1 a.
3
This 3D coordinate system is not, however, rich enough for use in computer
graphics. Though the matrix M could be used to rotate and scale vectors,
it cannot deal with points, and we want to be able to translate points
(and objects).
v= 1 v1 + 2 v2 + 3 v3 ,
P = P 0 + 1 v1 + 2 v2 + 3 v3 .
We can use vector and matrix notation and re-express the vector v and
point P as
v1 v1
v v
v = ( 1 2 3 0) 2 , and P = ( 1 2 3 1) 2 .
v3 v3
P0 P0
4
Change of frames
a = M T b and b = (M T )1 a.
5
Affine transformations
P () = (1 )P0 + P1
p() = (1 )p0 + p1 ,
M p() = (1 )M p0 + M p1 .
6
Rotation, translation, scaling, and shear
p0 = p + d,
where
x x0 x
y y0
p = , 0
p = 0 , d = y .
z z z
1 1 0
so that
x0 = x + x , y 0 = y + y , z 0 = z + z .
1 0 0 x
0 1 0 y
T = T (x , y , z ) = ,
0 0 1 z
0 0 0 1
called the translation matrix. One can check that the inverse is
T 1 (x , y , z ) = T (x , y , z ).
7
Rotation depends on an axis of rotation and the angle turned through.
Consider first rotation in the plane, about the origin. If a point (x, y) with
coordinates
x = cos , y = sin ,
x0 = cos( + ), y 0 = sin( + ).
x0 = x cos y sin ,
y 0 = x sin + y cos ,
or
x0 cos sin x
= .
y0 sin cos y
y y
x x
8
Thus the three rotation matrices corresponding to rotation about the z, x,
and y axes in lR3 are:
cos sin 0 0
sin cos 0 0
Rz = Rz () = ,
0 0 1 0
0 0 0 1
1 0 0 0
0 cos sin 0
Rx = Rx () = ,
0 sin cos 0
0 0 0 1
cos 0 sin 0
0 1 0 0
Ry = Ry () = .
sin 0 cos 0
0 0 0 1
All three give positive rotations for positive with respect to the right
hand rule for the axes x, y, z. If R = R() denotes any of these matrices,
its inverse is clearly
R1 () = R() = RT ().
9
Scaling can be applied in any of the three axes independently. If we send
a point (x, y, z) to the new point
x0 = x x, y 0 = y y, z 0 = z z,
x 0 0 0
0 y 0 0
S = S(x , y , z ) = ,
0 0 z 0
0 0 0 1
with inverse
S 1 (x , y , z ) = S(1/x , 1/y , 1/z ).
10
Shears can be constructed from translations, rotations, and scalings, but
are sometimes of independent interest.
y y
x x
z z
x0 = x + (cot )y, y 0 = y, z 0 = z,
1 cot 0 0
0 1 0 0
Hx () = ,
0 0 1 0
0 0 0 1
with inverse
Hx1 () = Hx ().
11
Rotation about an arbitrary axis
How do we find the matrix which rotates an object about an arbitrary point
p0 and around a direction u = p2 p1 , through an angle ?
y
p2
u
p1
x
p0
12
It remains to calculate x and y from u = (x , y , z ). The first rotation
Rx (x ) will rotate the vector u around the x axis until it lies in the y = 0
plane. Using simple trigonometry, we find that
1 0 0 0
0 z /d y /d 0
Rx (x ) = .
0 y /d z /d 0
0 0 0 1
cos y = d, sin y = x ,
and so
d 0 x 0
0 1 0 0
Ry (y ) = .
x 0 d 0
0 0 0 1
13
Example in OpenGL
void myinit(void)
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(4.0, 5.0, 6.0);
glRotatef(45.0, 1.0, 2.0, 3.0);
glTranslatef(-4.0, -5.0, -6.0);
}
q = Cp.
14
Spinning the Cube
The following program rotates a cube, using the three buttons of the mouse.
There are three callbacks:
glutDisplayFunc(display);
glutIdleFunc(spincube);
glutMouseFunc(mouse);
The display callback sets the model-view matrix with three angles deter-
mined by the mouse callback, and then draws the cube (see Section 4.4 of
the book).
void display()
{
glClear(GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glRotatef(theta[0], 1.0, 0.0, 0.0);
glRotatef(theta[1], 0.0, 1.0, 0.0);
glRotatef(theta[2], 0.0, 0.0, 1.0);
colorcube();
glutSwapBuffers();
}
15
The mouse callback selects the axis of rotation.
The idle callback increments the angle of the chosen axis by 2 degrees.
void spincube()
{
theta[axis] += 2.0;
if(theta[axis] >= 360.0) theta[axis] -= 360.0;
glutPostRedisplay();
}
16
A little bit about quarternions
ei = cos + i sin .
This rotates a given point rei in the complex plane to the new point
rei ei = rei(+) .
q = q1 i + q2 j + q3 k,
where i, j, k play a similar role to that of the unit vectors in lR 3 , and obey
the properties
i2 = j2 = k2 = 1,
and
ij = k = ji, jk = i = kj, ki = j = ik.
17
These properties imply that the sum and multiple of two quarternions a =
(q0 , q) and b = (p0 , p) are
a + b = (q0 + p0 , q + p),
and
ab = (q0 p0 q p, q0 p + p0 q + q p).
r = (cos(/2), sin(/2)v),
r1 = (cos(/2), sin(/2)v).
we claim that
p0 = r1 pr.
18
Lets check that this is correct! Following the rule for multiplication, a little
computation shows that p0 does indeed have the form (0, p0 ), and that
p0 = cos2 p + sin2 (v p)v + 2 sin cos (v p) + sin2 v (v p).
2 2 2 2 2
and the multiple-angle formulas for cos and sin, this simplifies to
19