Cheat Sheet for Computer Graphics
Winter 2019/Summer 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
1.1 Scalar Product
                 
               a1      b1
      a ◦ b = a2  ◦ b2  = a1 b1 + a2 b2 + a3 b3                                          (1)
               a3      b3
1.2 Cross Product
                                          
               a1      b1      a2 b 2 − a3 b 2
      a × b = a2  × b2  = a3 b1 − a1 b3                                                (2)
               a3      b3      a1 b 2 − a2 b 1
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
      ∆DE = 2∆y           and       ∆DN E = 2(∆x − ∆y)                                       (3)
and initialize
      D := ∆x − 2∆y.                                                                         (4)
Then keep incrementing x := x0 up to x1 . In each iteration, as long as x ≥ 0, we move to the
east (right) and update with ∆DE. If x < 0, we move north-east (increment y) and update
with ∆DN E.
                                                      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
Rotation by angle φ from origin (0, 0), anti-clockwise is implemented by
                            
            cos φ − sin φ 0
     Rφ =  sin φ cos φ 0                                                                  (8)
              0       0     1
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
To reflect   on the x-axis, invert y with
                  
        1     0 0
      0     −1 0 .                                                                       (10)
        0     0 0
To reflect on the y-axis, invert x with
                
        −1 0 0
       0 1 0 .                                                                           (11)
         0 0 1
5 Multiple Transformations
5.1 Matrix Application
Given are transformations M1 and M2 . To first compute M1 and then M2 , multiply a given
point with the matrix product
      M2 M1 ,                                                                              (12)
that is transformations are applied right to left.
5.2 Rotation and Transformation
Matrix M first translates by (tx , ty )   and then rotates by angle φ.
                                                                                  
            cos φ − sin φ 0          1     0 tx      cos φ − sin φ tx cos φ − ty sin φ
     M =  sin φ cos φ 0 · 0             1 ty  =  sin φ cos φ tx cos φ + ty sin φ     (13)
              0       0     1        0     0 1          0      0            1
Matrix N first    rotates by angle φ and then translates by (tx , ty ).
                                                                   
            1     0 tx      cos φ − sin φ 0       cos φ − sin φ tx
     N= 0        1 ty  ·  sin φ cos φ 0 =  sin φ cos φ ty                            (14)
            0     0 1          0      0    1        0       0         1
                                                    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
which moves the camera into the origin.
9 Phong Lighting Model
The Phong Lighting Model is based around three components, namely ambient light Lamb ,
diffuse reflection Ldif f and specular reflection Lspec .
9.1 Ambient Light
Ambient light is constant, parameterized by two arguments.
     Lamb = kamb · Iin                                                                   (20)
                                                  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.
      Ldif f = kdif f · Iin · cos φ                                                           (21)
             = kdif f · Iin · (n ◦ l)                                                         (22)
9.3 Specular Reflection
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.
      Lspec = kspec · Iin · cosm ϕ                                                            (23)
            = kspec · Iin · (v ◦ r)m                                                          (24)
If perfect reflection r is not known, it can be computed in terms of
      r = 2 · (n ◦ l) · n − l.                                                                (25)
10 Ray Tracing
10.1 Eye Ray
An eye ray r is a ray starting at eye position e in direction d.
      r(t) = e + t · d                                                                        (26)
10.2 Intersection Point
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)
10.3 Intersection With a Plane
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.