L-7 Transformations
L-7 Transformations
Q=T(P)
• Line preserving
• Characteristic of many physically
important transformations
- Rigid body transformations: rotation, translation
- Scaling, shear
• Importance in graphics is that we need
only transform endpoints of line segments
and let implementation draw line segment
between the transformed endpoints
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 4
Pipeline Implementation
frame
u T(u) buffer
transformation rasterizer
v T(v) T(v)
v T(v)
T(u)
u T(u)
vertices vertices pixels
d
P
! x' $ ! 1 0 0 d x $! x $
# & # &# &
# y' &=# 0 1 0 d y &# y &
# z' & # &#
0 0 1 dz & z &
# & # # &
" 1 % #" 0 0 0 1 &%" 1 %
x’= x + dx
y’= y + dy
z’= z + dz
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 12
Rotation (2D)
x’ = x cos q – y sin q
x = r cos f y’= x sin q + y cos q
y = r sin f
- or in homogeneous coordinates
p’= Rz(q)p
[ ]
écos q --sin q 0 0ù
ê sin q cos q ú
0 0ú
R = Rz(q) = ê
ê 0 0 1 0ú
ê ú
ë 0 0 0 1û
é cos q 0 sin q 0ù
ê 0 1 0 0ú
R = Ry(q) = ê ú
ê- sin q 0 cos q 0ú
ê ú
ë 0 0 0 1û
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 17
Rotation Around an Arbitrary Axis
• Rotate a point P
around axis n (x,y,z)
by angle q
# tx 2 + c txy + sz txz − sy 0&
% (
% txy − sz ty 2 + c tyz + sx 0(
R=
%txz + sy tyz − sx tz 2 + c 0(
% (
$ 0 0 0 1'
• c = cos(q)
• s = sin(q)
• t = (1 - c)
Graphics Gems I, p. 466 & 498
19
Rotation Around an Arbitrary Axis
20
Scaling
Expand or contract along each axis (fixed point of origin)
x’=sxx
y’=syy
z’=szz
p’=Sp
é sx 0 0 0ù
ê0 sy 0 0 ú
S = S(sx, sy, sz) = ê ú
ê0 0 sz 0ú
ê ú
ë0 0 0 1û
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 21
Reflection
sx = -1 sy = 1 original
sx = -1 sy = -1 sx = 1 sy = -1
é1 cot q 0 0ù
ê0 1 0 0ú
H(q) = ê ú
ê0 0 1 0ú
ê ú
ë0 0 0 1û
P’ = T ✴ P T
33
1994 Foley/VanDam/Finer/Huges/Phillips ICG
Composition of 2D Transforms
T
P’ = T ✴ P
34
1994 Foley/VanDam/Finer/Huges/Phillips ICG
Composition of 2D Transforms
35
1994 Foley/VanDam/Finer/Huges/Phillips ICG
Composition of
Transformation Matrices
• Be sure to multiple transformations in
proper order!
é1 cot q 0 0ù
ê0 1 0 0ú
H(q) = ê ú
ê0 0 1 0ú
ê ú
ë0 0 0 1û
We want C = T –1 R T
so we must do the operations in the following order
C¬I
C ¬ CT -1
C ¬ CR
C ¬ CT
void main() {
vec3 angles = radians( theta );
vec3 c = cos( angles );
vec3 s = sin( angles );
// Remember: these matrices are column-major!
mat4 rx = mat4( 1.0, 0.0, 0.0, 0.0,
0.0, c.x, s.x, 0.0,
0.0, -s.x, c.x, 0.0,
0.0, 0.0, 0.0, 1.0 ); 62
Rotation Shader (cont)
vColor = aColor;
gl_Position = rz * ry * rx * aPosition;
} 63
Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015
Smooth Rotation
• From a practical standpoint, we often want to
use transformations to move and reorient an
object smoothly
- Problem: find a sequence of model-view
matrices M0,M1,…..,Mn so that when they are
applied successively to one or more objects we
see a smooth transition
• For orientating an object, we can use the fact
that every rotation corresponds to part of a
great circle on a sphere
- Find the axis of rotation and angle
- Virtual trackball (see text)
Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015 64
Incremental Rotation
66
Quaternions
• Extension of imaginary numbers from two to
three dimensions
• Requires one real and three imaginary
components i, j, k
q=q0+q1i+q2j+q3k
70
71
72
A & B are quaternions