CG Cheat Sheet 2020
CG Cheat Sheet 2020
This is a rudimentary cheat sheet for the lecture Computer Graphics, Winter Term 2019. It is
by no means complete, rather it is optimized to fit with the challenge set by the exam. That
is, it contains the formulas and matrices you are expected to recall during the exam.
1 Basic Math
2 Bresehenham Algorithm
Given two points A = (x0 , y0 ) and B = (x1 , y1 ), we want to rasterize a line from A to B. For
this, we first compute updates
and initialize
D := ∆x − 2∆y. (4)
1
3 Homogeneous Coordinates
• Given a point (x, y, z) in 3D space, the homogeneous coordinate that represents that point
is (x, y, z, w = 1).
• To undo this conversion, compute
x
1
y (5)
w
z
4 Affine Transformations
4.1 Shearing
Horizontal sheering keeps y fixed. On paper, it looks like the y-axis is moving. It maps the
axis vector (0, 1) to (sh , 1).
1 sh 0
0 1 0 (6)
0 0 1
Vertical sheering keeps x fixed. On paper, it looks like the x-axis is moving. It maps the axis
vector (1, 0) to (1, sv ).
1 0 0
sv 1 0 (7)
0 0 1
4.2 Rotation
In particular we get
0 −1 0 −1 0 0 0 1 0
R π2 = 1 0 0 , Rπ = 0 −1 0 , R 3π = −1 0 0 . (9)
2
0 0 1 0 0 1 0 0 1
2
4.3 Reflection
5 Multiple Transformations
Given are transformations M1 and M2 . To first compute M1 and then M2 , multiply a given
point with the matrix product
M2 M1 , (12)
3
6 Rotations in 3D Space
Anti-Clockwise rotation around an axis m by angle φ is achievable with matrix Rm as follows.
1 0 0 0
0 cos φ − sin φ 0
Rx =
0 sin φ cos φ 0
(15)
0 0 0 1
cos φ 0 sin φ 0
0 1 0 0
Ry =
− sin φ 0 cos φ 0
(16)
0 0 0 1
cos φ − sin φ 0 0
sin φ cos φ 0 0
Rz =
0
(17)
0 1 0
0 0 0 1
7 Camera
A camera is often defined by eye vector e, gaze direction g and view-up vector t. However, in
practice it is useful to construct the (u, v, w) coordinate system for a given camera.
1 1
w=− g u= (t × w) v =w×u (18)
||g|| ||t × w||
8 Viewing Transformation
From camera coordinate system (u, v, w), we can construct viewing matrix
ux uy uz −uT e
vx vy vz −v T e
Mview = (19)
wx wy wz −wT e
0 0 0 1
4
9.2 Diffuse Reflection
Diffuse reflection imitates micro structure and random reflection. It is dependent on the angle φ
between surface normal n and light vector l. Both n and l have to be normalized.
Specular reflection creates spotlight effects. It takes the eye position into account. To compute
it, we need the perfect reflection vector r and view vector v, both of which need to be normalized.
Angle ϕ is the angle between vectors v and r. Material constant m introduces a cutoff for the
highlight, higher values for m result in smaller highlights.
r = 2 · (n ◦ l) · n − l. (25)
10 Ray Tracing
r(t) = e + t · d (26)
An intersection point x of an eye ray with some geometry is defined by distance tx the ray had
to travel from eye to geometry.
x = e + tx · d (27)
Given a plane defined by a normal n and some point c on the plane, we can compute intersection
point x by finding the right value for tx .
(c − e) ◦ n
tx = (28)
d◦n
We only care about real solutions for tx . We also only care for solutions tx > 0 as negative
values mean that we traveled in opposite of direction d.
5
10.4 Intersection With a Sphere
Given a sphere with center c and radius r, find out tx for which an eye ray e + tx · d intersects
the sphere. The solution can be found by solving the quadratic equation in terms of
√
−b ± b2 − 4c
tx = (29)
2
with
b = 2 · d ◦ (e − c) and c = (e − c) ◦ (e − c) − r2 . (30)
If there is no real solution for tx , there is no intersection of the ray with the sphere.
11 Fin
Keine Macht für Niemand.