You are on page 1of 22

Summary: Change the highlighted values and see the figure change. A second tab shows 3D.

Details: I've heard over the years how matrices are used in 2D and 3D graphics to rotate, translate, and scale figures. I've never,
however, really understood how it works. I decided to figure it out with the help of Wikipedia and Excel.

So, here is my 2D-geometry spreadsheet. You can change the highlighted values and match the figure move. The second tab
generalizes this to 3D and adds perspective projection. - Carl (Twitter: @CarlKadie)

http://en.wikipedia.org/wiki/Transformation_matrix#Examples_in_2D_graphics

Original
x y Original
0 0
-3 -2 -1 0 1
2 2 3
2 -2
-2 -2
-2 2
2 2 2

-1

-2

-3

Rotation
Rotation -3 -2 -1 0 1
3

2
Rotation
-3 -2 -1 0 1
3
angle (°) -10

Rotation Matrix x old y old


2
0.985 -0.174 x new
0.174 0.985 y new

1
x y one
0 0 1
1.622319 2.31691186 1
2.316912 -1.6223192 1 0
-1.62232 -2.3169119 1
-2.31691 1.62231915 1
1.622319 2.31691186 1
-1

-2

-3

Translation
In addition to the x- and y- coordinate, we add an "always one" coordinate to each point. It makes the formulas shorter.
Also, we'll use Excel SumProduct function which is a shortcut for doing a series of multiplies followed by an addition.

x y Translation
delta 1 -1
-3 -2 -1 0 1
3
Translation Matrix x old y old one old
1 0 1 x new
0 1 -1 y new
0 0 1 one new 2

x y one
1 -1 1
1
2.622319 1.31691186 1
3.316912 -2.6223192 1
-0.62232 -3.3169119 1
-1.31691 0.62231915 1 0
2.622319 1.31691186 1

-1
0

-1

-2

-3

Scaling x y Scaling
scale 0.5 0.25
-3 -2 -1 0 1
3
Scale Matrix x old y old
0.5 0 x new
0 0.25 y new
2

x y
0.5 -0.25
1
1.31116 0.32922797
1.658456 -0.6555798
-0.31116 -0.829228
-0.65846 0.15557979 0
1.31116 0.32922797

-1

-2

-3
and scale figures. I've never,
xcel.

re move. The second tab

Original
0 1 2 3
3

-1

-2

-3

Rotation
0 1 2 3
3

2
Rotation
0 1 2 3
3

-1

-2

-3

he formulas shorter.
d by an addition.

Translation
0 1 2 3
3

-1
0

-1

-2

-3

Scaling
0 1 2 3
3

-1

-2

-3
Scroll down to see more. Change highlighted values to see effects.
http://en.wikipedia.org/wiki/Transformation_matrix

Original
x y z one Original
0 0 0 1
-3 -2 -1 0 1
2 2 2 1 3
2 -2 2 1
-2 -2 2 1
-2 2 2 1
2 2 2 1 2
2 2 -2 1
2 -2 -2 1
2 -2 2 1
1
2 -2 -2 1
-2 -2 -2 1
-2 -2 2 1
-2 -2 -2 1
0
-2 2 -2 1
-2 2 2 1
-2 2 -2 1
2 2 -2 1
-1

-2

-3

xy-Rotation
deg rad xy-Rotation
angle 10 0.174533
-3 -2 -1 0 1
3
Rot Matrixx in y in z in one in
0.98480775 0.17364818 0 0 x out

2
-3 -2 -1 0 1
3

-0.1736482 0.98480775 0 0 y out


2
0 0 1 0 z out
0 0 0 1 one out

1
x y z one
0 0 0 1
2.31691186 1.62231915 2 1
1.62231915 -2.3169119 2 1 0
-2.3169119 -1.6223192 2 1
-1.6223192 2.31691186 2 1
2.31691186 1.62231915 2 1
2.31691186 1.62231915 -2 1 -1

1.62231915 -2.3169119 -2 1
1.62231915 -2.3169119 2 1
1.62231915 -2.3169119 -2 1
-2
-2.3169119 -1.6223192 -2 1
-2.3169119 -1.6223192 2 1
-2.3169119 -1.6223192 -2 1
-1.6223192 2.31691186 -2 1 -3
-1.6223192 2.31691186 2 1
-1.6223192 2.31691186 -2 1
2.31691186 1.62231915 -2 1

xz-Rotation
deg rad xz-Rotation
angle 20 0.349066
-3 -2 -1 0 1
3
Rot Matrixx in y in z in one in
0.93969262 0 0.34202 0 x out
0 1 0 0 y out
2
-0.3420201 0 0.939693 0 z out
0 0 0 1 one out

0
1
x y z one
0 0 0 1
2.86122527 1.62231915 1.086955 1
2.20852162 -2.3169119 1.324519 1 0
-1.4931447 -1.6223192 2.671816 1
-0.840441 2.31691186 2.434251 1
2.86122527 1.62231915 1.086955 1
1.49314469 1.62231915 -2.67182 1 -1

0.84044105 -2.3169119 -2.43425 1


2.20852162 -2.3169119 1.324519 1
0.84044105 -2.3169119 -2.43425 1
-2
-2.8612253 -1.6223192 -1.08695 1
-1.4931447 -1.6223192 2.671816 1
-2.8612253 -1.6223192 -1.08695 1
-2.2085216 2.31691186 -1.32452 1 -3
-0.840441 2.31691186 2.434251 1
-2.2085216 2.31691186 -1.32452 1
1.49314469 1.62231915 -2.67182 1

yz-Rotation
deg rad yz-Rotation
angle 0 0
-3 -2 -1 0 1
3
Rot Matrixx in y in z in one in
1 0 0 0 x out
0 1 0 0 y out
2
0 0 1 0 z out
0 0 0 1 one out

1
x y z one
0 0 0 1
2.86122527 1.62231915 1.086955 1
2.20852162 -2.3169119 1.324519 1 0

-1
0
-1.4931447 -1.6223192 2.671816 1
-0.840441 2.31691186 2.434251 1
2.86122527 1.62231915 1.086955 1
-1
1.49314469 1.62231915 -2.67182 1
0.84044105 -2.3169119 -2.43425 1
2.20852162 -2.3169119 1.324519 1
0.84044105 -2.3169119 -2.43425 1
-2
-2.8612253 -1.6223192 -1.08695 1
-1.4931447 -1.6223192 2.671816 1
-2.8612253 -1.6223192 -1.08695 1
-2.2085216 2.31691186 -1.32452 1 -3
-0.840441 2.31691186 2.434251 1
-2.2085216 2.31691186 -1.32452 1
1.49314469 1.62231915 -2.67182 1

Translation
x y z Translation
delta 0 0 4
-3 -2 -1 0 1
3
Trans Matrx in y in z in one in
1 0 0 0 x out
0 1 0 0 y out
2
0 0 1 4 z out
0 0 0 1 one out

1
x y z one
0 0 4 1
2.86122527 1.62231915 5.086955 1
2.20852162 -2.3169119 5.324519 1 0
-1.4931447 -1.6223192 6.671816 1
-0.840441 2.31691186 6.434251 1
2.86122527 1.62231915 5.086955 1
1.49314469 1.62231915 1.328184 1 -1

0.84044105 -2.3169119 1.565749 1


2.20852162 -2.3169119 5.324519 1
0.84044105 -2.3169119 1.565749 1
-2
-2.8612253 -1.6223192 2.913045 1

-3
-2

-1.4931447 -1.6223192 6.671816 1


-2.8612253 -1.6223192 2.913045 1
-2.2085216 2.31691186 2.675481 1 -3
-0.840441 2.31691186 6.434251 1
-2.2085216 2.31691186 2.675481 1
1.49314469 1.62231915 1.328184 1

Scale
x y z Scale
scale 0.75 0.75 1
-3 -2 -1 0 1
3
Scale Matrx in y in z in one in
0.75 0 0 0 x out
0 0.75 0 0 y out
2
0 0 1 0 z out
0 0 0 1 one out

1
x y z one
0 0 4 1
2.14591895 1.21673936 5.086955 1
1.65639122 -1.7376839 5.324519 1 0
-1.1198585 -1.2167394 6.671816 1
-0.6303308 1.7376839 6.434251 1
2.14591895 1.21673936 5.086955 1
1.11985852 1.21673936 1.328184 1 -1

0.63033079 -1.7376839 1.565749 1


1.65639122 -1.7376839 5.324519 1
0.63033079 -1.7376839 1.565749 1
-2
-2.1459189 -1.2167394 2.913045 1
-1.1198585 -1.2167394 6.671816 1
-2.1459189 -1.2167394 2.913045 1
-1.6563912 1.7376839 2.675481 1 -3
-0.6303308 1.7376839 6.434251 1
-1.6563912 1.7376839 2.675481 1
1.11985852 1.21673936 1.328184 1
Simple Projection

Projection Matrix

x in y in z in one in
1 0 0 0 x out
0 1 0 0 y out
0 0 1 0 z out
0 0 1 0 one out

x y z one
0 0 4 4
2.14591895 1.21673936 5.086955 5.086955
1.65639122 -1.7376839 5.324519 5.324519
-1.1198585 -1.2167394 6.671816 6.671816
-0.6303308 1.7376839 6.434251 6.434251
2.14591895 1.21673936 5.086955 5.086955
1.11985852 1.21673936 1.328184 1.328184
0.63033079 -1.7376839 1.565749 1.565749
1.65639122 -1.7376839 5.324519 5.324519
0.63033079 -1.7376839 1.565749 1.565749
-2.1459189 -1.2167394 2.913045 2.913045
-1.1198585 -1.2167394 6.671816 6.671816 Simple Projection
-2.1459189 -1.2167394 2.913045 2.913045 -3 -2 -1 0 1
-1.6563912 1.7376839 2.675481 2.675481 3

-0.6303308 1.7376839 6.434251 6.434251


-1.6563912 1.7376839 2.675481 2.675481
1.11985852 1.21673936 1.328184 1.328184
2

x y z one
0 0 1 1 1
0.42184746 0.23918816 1 1
0.31108746 -0.3263551 1 1
-0.1678491 -0.18237 1 1
-0.0979649 0.27006778 1 1 0
0.42184746 0.23918816 1 1
0.84314999 0.91609231 1 1
0.40257462 -1.10981 1 1
-1

-2
0

-1
0.31108746 -0.3263551 1 1
0.40257462 -1.10981 1 1
-0.7366583 -0.4176864 1 1
-0.1678491 -0.18237 1 1 -2
-0.7366583 -0.4176864 1 1
-0.6191004 0.64948477 1 1
-0.0979649 0.27006778 1 1
-0.6191004 0.64948477 1 1 -3
0.84314999 0.91609231 1 1

angle left/rigangle up/down


0.000 0.000 Angles to Each Point
22.872 13.452
90
17.280 -18.074
-9.528 -10.335 75
-5.595 15.113
22.872 13.452 60
40.136 42.493
21.928 -47.979 45

17.280 -18.074
30
21.928 -47.979
-36.378 -22.670 15
up/down angle

-9.528 -10.335
-36.378 -22.670 0
-90 -75 -60 -45 -30 -15 0 15 30
-31.762 33.003
-5.595 15.113 -15

-31.762 33.003
-30
40.136 42.493
-45

-60

-75

-90

left/right angle
-90

left/right angle

Field of View (FOV) in degress


110

lt/rt %FOV up/down %FOV


0% 0% % of FOV to Each Point
21% 12%
50%
16% -16%
-9% -9%
40%
-5% 14%
21% 12%
36% 39% 30%

20% -44%
16% -16% 20%
20% -44%
-33% -21% 10%

up/down angle
-9% -9%
-33% -21% 0%
-50% -40% -30% -20% -10% 0% 10% 20%
-29% 30%
-5% 14% -10%
-29% 30%
36% 39% -20%

-30%

-40%

-50%

left/right angle
Original
0 1 2 3
3

-1

-2

-3

xy-Rotation
0 1 2 3
3

2
0 1 2 3
3

-1

-2

-3

xz-Rotation
0 1 2 3
3

0
1

-1

-2

-3

yz-Rotation
0 1 2 3
3

-1
0

-1

-2

-3

Translation
0 1 2 3
3

-1

-2

-3
-2

-3

Scale
0 1 2 3
3

-1

-2

-3
mple Projection
0 1 2 3
3

-1

-2
0

-1

-2

-3

gles to Each Point


90

75

60

45

30

15

0
-30 -15 0 15 30 45 60 75 90

-15

-30

-45

-60

-75

-90

left/right angle
-90

left/right angle

f FOV to Each Point


50%

40%

30%

20%

10%

0%
% -10% 0% 10% 20% 30% 40% 50%

-10%

-20%

-30%

-40%

-50%

left/right angle

You might also like