Professional Documents
Culture Documents
Maths For Computer Graphics
Maths For Computer Graphics
Maths For Computer Graphics
01 Translation
2D transformations
Translation
y' = y + 1
Where P'(x', y') is three units to the right and one unit
above P.
2D transformations
Translation
translated
original
X
Fig. 7.1 The translated shape results by adding 3 to
every x-coordinate, and 1 to every y-coordinate of the
original shape.
The transform is
x' = x + 3
y' = y + 1
06.01 Translation
2D transformations
Scaling
Shape scaling is achieved by multiplying coordinates
x' = 2 x
y ' = 1.5 y
This transform results in a horizontal scaling of 2 and a
vertical scaling of 1.5.
Note that a point located at the origin does not change its
place, therefore, scaling is relative to the origin.
06.01 Translation
2D transformations
Scaling
Y
scaled
origina
l
X
Fig. 7.2 The scaled shape results by multiplying
every x-coordinate by 2 and every y-coordinate
by 1.5.
The transform is
x' = 2 x
y ' = 1.5 y
06.01 Translation
2D transformations
Reflection
To reflect a shape relative to the y-axis
x' = x
y' = y
To reflect a shape relative to the x-axis
x' = x
y' = y
06.01 Translation
2D transformations
Reflection
Y
original
Fig. 7.3 The top right-hand shape can give rise to the three
reflections simply by reversing the signs of coordinates.
The transform is
x' = x
y' = y
06.01 Translation
Matrices
Matrix notation was investigated by the British
mathematician Cayley around 1858.
Matrices
x a b x
y = c d . y
Scaling
x' 2 0 x
y ' = 0 1.5 y
Translation
?
06.01 Translation
Homogeneous coordinates
Homogeneous coordinates surfaced in the early 1800s
where they were independently proposed by A. F. Mbius
(who invented a one-sided curled band), Feuerbach,
tienne Bobillier, and Plcker.
Homogeneous coordinates
Homogeneous coordinates define a point in a plane using
three coordinates instead of two.
Homogeneous coordinates
Y
Homogeneous coordinates
Consider the following transformation on the
homogeneous point (x, y, 1)
x a b c x
y = d e f . y
1 0 0 1 1
This expands to
x = ax + by + c
y = dx + ey + f
1=1
which solves the above problem of translating.
Homogeneous coordinates
2D translation
The algebraic and matrix notation for 2D translation is
x = x + t x
y = y + t y
or using matrices
x 1 0 tx x
y = 0 1 t y . y
1 0 0 1 1
e.g.
x 1 0 2 x
y = 0 1 3 . y
1 0 0 1 1
Homogeneous coordinates
2D scaling
The algebraic and matrix notation for 2D scaling is
x = s x x
y = s y y
or using matrices
x s x 0 0 x
y = 0 s 0 . y
y
1 0 0 1 1
e.g.
x 2 0 0 x
y = 0 1.5 0 . y
1 0 0 1 1
Homogeneous coordinates
2D scaling relative to a point
To scale relative to another point (px, py):
Homogeneous coordinates
2D scaling relative to a point
Example
x 2 0 1 x
y = 0 2 1 . y
1 0 0 1 1
x' = 2 x 1
y' = 2 y 1
06.01 Translation
Homogeneous coordinates
2D reflections
The matrix notation for reflecting about the y axis is
x 1 0 0 x
y = 0 1 0 . y
1 0 0 1 1
x 1 0 0 x
y = 0 1 0 . y
1 0 0 1 1
06.01 Translation
Homogeneous coordinates
2D reflections relative to a line
To make a reflection about an arbitrary vertical or
horizontal axis.
x1 = x 1
x2 = ( x 1)
x = ( x 1) + 1
which simplifies to
x = x + 2
y = y
06.01 Translation
Homogeneous coordinates
2D reflections relative to a line
x = x + 2
y = y
or in matrix form
x 1 0 2 x
y = 0 1 0 . y
1 0 0 1 1
Y
X
-2 -1 0 1 2 3 4
Homogeneous coordinates
2D reflection relative to a line
A similar transform is used for reflections about an
arbitrary x-axis, y = a y
x = x
y = ( y a y ) + a y = y + 2a y
In matrix form
x ' 1 0 0 x
y ' = 0 1 2a y
y
1 0 0 1 1
06.01 Translation
2D Shearing
A shape is sheared by leaning it over at an angle .
The y-coordinate remains unchanged but the x-
coordinate is a function of y and tan()
x = x + y tan( )
y = y
Y
original sheared
Fig. 7.6 The original square shape is sheared to the right by and angle ,
and the horizontal shift is proportional to ytan().
06.01 Translation
2D Shearing
In matrix form
x 1 tan( ) 0 x
y = 0 1 0 . y
1 0 0 1 1
06.01 Translation
2D Rotation
A point P(x, y) is to be rotated by an angle about the
origin to P'(x', y').
Y
y P(x, y)
X
x' x
Fig. 7.7 The point P(x, y) is rotated through an
angle to P(x, y).
x = R cos( + )
y = R sin( + )
06.01 Translation
2D Rotation
x = R cos( + )
y = R sin( + )
therefore
x = R(cos( ) cos( ) sin( ) sin( ) )
y = R(sin( ) cos( ) + cos( ) sin( ) )
x = R x cos( ) sin( )
y
R R
y = R cos( ) + x sin( )
y
R R
x = x cos( ) y sin( )
y = x sin( ) + y cos( )
In matrix form
x cos( ) sin( ) 0 x
y = sin( ) cos( ) 0 . y
1 0 0 1 1
06.01 Translation
2D Rotation
Example
To rotate a point by 90 the matrix becomes
x 0 1 0 x
y = 1 0 0 . y
1 0 0 1 1
x 1 0 0 x
y = 0 1 0 . y
1 0 0 1 1
1: Subtract ( p x , p y )
x1 = ( x p x )
y1= ( y p y )
2: Rotate about the origin
x2 = ( x p x ) cos( ) ( y p y ) sin( )
y 2 = ( x p x ) sin( ) + ( y p y ) cos( )
3: Add ( p x , p y )
x = ( x p x ) cos( ) ( y p y ) sin( ) + p x
y = ( x p x ) sin( ) + ( y p y ) cos( ) + p y
simplifying
x = x cos( ) y sin( ) + p x (1 cos( )) + p y sin( )
y = x sin( ) + y cos( ) + p y (1 cos( )) p x sin( )
06.01 Translation
1: translate ( p x , p y )
2: perform the scaling (sx, sy)
3: translate ( p x , p y )
In matrix form
x x
y = [translate( p , p )] [scale( s , s )] [translate( p , p )] y
x y x y x y
1 1
which becomes
x ' 1 0 p x s x 0 0 1 0 p x x
y ' = 0 1 py 0 sy 0 0 1 p y y
1 0 0 1 0 0 1 0 0 1 1
06.01 Translation
x ' 1 0 p x s x 0 0 1 0 p x x
y ' = 0 1 py 0 sy 0 0 1 p y y
1 0 0 1 0 0 1 0 0 1 1
x ' 1 0 p x s x 0 sx px x
y ' = 0 1 py 0 sy s y p y y
1 0 0 1 0 0 1 1
and finally
x ' s x 0 sx px x
y ' = 0 sy sy py y
1 0 0 1 1
06.01 Translation
x' x
y ' = [translate ( a ,0)] [reflection ] [translate ( a ,0)] y
x x
1 1
which expands to
x 1 0 a x 1 0 0 1 0 a x x
y = 0 1 0 . 0 1 0 . 0 1 0 . y
1 0 0 1 0 0 1 0 0 1 1
x 1 0 a x 1 0 a x x
y = 0 1 0 . 0 1 0 . y
1 0 0 1 0 0 1 1
x 1 0 2a x x
y = 0 1 0 . y
1 0 0 1 1
06.01 Translation
x cos( ) sin( ) 0 x
y = sin( ) cos( ) 0 . y
1 0 0 1 1
A rotation about an arbitrary point ( p x , p y )
x x
y = [translate( p , p )] [rotate ] [translate( p , p )] y
x y x y
1 1
which expands to
3D transformations
3D translation
x 1 0 0 tx x
y 0 1 0 t y y
= .
z 0 0 1 tz z
1 0 0 1 1
0
3D scaling
x s x 0 0 0 x
y 0 sy 0 0 y
= .
z 0 0 sz 0 z
1 1
1 0 0 0
x s x 0 0 p x (1 s x ) x
y 0 sy 0 p y (1 s y ) y
= .
z 0 0 sz p z (1 s z ) z
1 0 0 0 1 1
06.01 Translation
3D Rotations
Y
P(x, y, z)
P(x, y, z)
X
Z
Fig. 7.8 Rotating P about the z-
axis.
x = x cos( ) y sin( )
y = x sin( ) + y cos( )
z = z
x cos( ) sin( ) 0 0 x
y sin( ) cos( ) 0 0 y
= .
z 0 0 1 0 z
1 1
1 0 0 0
06.01 Translation
3D Rotations
When rotating about the x-axis, the x-coordinate remains
constant whilst the y- and z-coordinates are changed.
Algebraically, this is
x = x
y = y cos( ) z sin( )
z = y sin( ) + z cos( )
In a matrix transform
x 1 0 0 0 x
y 0 cos( ) sin( ) 0 y
= .
z 0 sin( ) cos( ) 0 z
1 1
1 0 0 0
06.01 Translation
3D Rotations
When rotating about the y-axis, the y-coordinate remains
constant whilst the x- and z-coordinates are changed.
Algebraically, this is
x = z sin( ) + x cos( )
y = y
z = z cos( ) x sin( )
In matrix form
x cos( ) 0 sin( ) 0 x
y 0 1 0 0 y
= .
z sin( ) 0 cos( ) 0 z
1 1
1 0 0 0
06.01 Translation
pitch roll
Z yaw X
1 0 0 0
0 cos( pitch) sin( pitch) 0
0 sin( pitch) coa( pitch) 0
1
0 0 0
rotate yaw about the y-axis
Combined rotations
A common way of combining yaw, pitch and roll is
x x
y y
= [ yaw] [ pitch] [roll ]
z z
1
1
If translation is involved
x x
y y
= [translate ] [ yaw] [ pitch] [roll ]
z z
1 1
Gimbal Lock
Y Y
Y'
X' pitch = 90
Y'
roll = 45
Z'
Z X Z X' X
Z'
Fig. 7.12 The X'Y'Z' axial system Fig. 7.13 The X'Y'Z' axial system
after a roll of 45. after a pitch of 90.
P(x, y,
z)
px
z=
py
z
X
Z P(x, y, z)
x x
y y
= [translate( px , py ,0)] [rotate ] [translate( px , py ,0)]
z z
1 1
Or in matrix form
x cos( ) sin( ) 0 p x (1 cos( )) + p y sin( ) x
y sin( ) cos( ) 0 p (1 cos( )) p sin( ) y
= y x
.
z 0 0 1 0 z
1
1 0 0 0 1
06.01 Translation
Determinants
Determinants arise in the solution of linear equations
c1 = a1 x + b1 y (1)
c 2 = a 2 x + b2 y (2)
Solving for x
Multiply (1) by b2 and (2) by b1
c1b2 = a1b2 x + b1b2 y
c 2 b1 = a2 b1 x + b1b2 y
Then subtract
c1b2 c2 b1 = a1b2 x a 2 b1 x
c1b2 c2 b1
x=
a1b2 a2 b1
Determinants
c1 = a1 x + b1 y (1)
c 2 = a 2 x + b2 y (2)
Solving for y
Multiply (1) by a2 and (2) by a1
a 2 c1 = a1 a 2 x + a 2 b1 y
a1c2 = a1 a 2 x + a1b2 y
Subtracting
a1c2 a2 c1 = a1b2 y a2 b1 y
a1c2 a2 c1
y=
a1b2 a2 b1
Determinants
c1b2 c2 b1
x=
a1b2 a2 b1
a1c2 a2 c1
y=
a1b2 a2 b1
Let
a1 b1
= a1b2 a2 b1 = the determinat
a2 b2
x 1
=
c1b2 c 2 b1 a1b2 a 2 b1
y 1
=
a1c2 a 2 c1 a1b2 a 2 b1
x y 1
= =
c1b2 c 2 b1 a1c2 a 2 c1 a1b2 a2 b1
Et voila!
x y 1
= =
c1 b1 a1 c1 a1 b1
c2 b2 a2 c2 a2 b2
06.01 Translation
Determinants summary
c1 = a1 x + b1 y
c 2 = a 2 x + b2 y
c1 a1 b1 x
c = a b y
2 2 2
x y 1
= =
c1 b1 a1 c1 a1 b1
c2 b2 a2 c2 a2 b2
Example
10 = 2 x + y
4 = 5x y
x y 1
= =
10 1 2 10 2 1
4 1 5 4 5 1
x y 1
= =
14 42 7
Therefore x = 2 and y = 6
06.01 Translation
Determinants
With a set of three linear equations:
d1 = a1 x + b1 y + c1 z
d 2 = a2 x + b2 y + c2 z
d 3 = a3 x + b3 y + c3 z
Determinants
d1 = a1 x + b1 y + c1 z
d 2 = a2 x + b2 y + c2 z
d 3 = a3 x + b3 y + c3 z
d1 a1 b1 c1 x
d = a b2 c2 . y
2 2
d 3 a3 b3 c3 z
therefore
x y z 1
= = =
d1 b1 c1 a1 c1 d1 a1 b1 d1 a1 b1 c1
d2 b2 c2 a2 c2 d2 a2 b2 d2 a2 b2 c2
d3 b3 c3 a3 c3 d3 a3 b3 d3 a3 b3 c3
a1 b1 c1
a2 b2 c2 = a1b2 c3 a1b3 c2 + a 2 b3 c1 a2 b1c3 + a3b1c2 a3b2 c
a3 b3 c3
b2 c2 b1 c1 b1 c1
a1 a2 + a3
b3 c3 b3 c3 b2 c2
06.01 Translation
x a b x
y = c d . y
Determinant of a transform
This transform encodes a scaling of 2, and results in an
overall area scaling of 4
2 0 2 0
0 2 and the determinant is 0 2 = 4
cos( ) sin( )
sin( ) cos( ) its determinant is cos 2
( ) + sin 2
( ) = 1