Docsity

Cheat Sheet for Computer Graphics, Cheat Sheet of Calculus

Toggle sidebar
bg1
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
a◦b=
a1
a2
a3
◦
b1
b2
b3
=a1b1+a2b2+a3b3(1)
1.2 Cross Product
a×b=
a1
a2
a3
×
b1
b2
b3
=
a2b2−a3b2
a3b1−a1b3
a1b2−a2b1
(2)
2 Bresehenham Algorithm
Given two points A= (x0, y0) and B= (x1, y1), we want to rasterize a line from Ato B. For
this, we first compute updates
∆DE = 2∆yand ∆DN E = 2(∆x−∆y) (3)
and initialize
D:= ∆x−2∆y. (4)
Then keep incrementing x:= x0up 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
pf3
pf4
pf5

Partial preview of the text

Download Cheat Sheet for Computer Graphics and more Cheat Sheet Calculus in PDF only on Docsity!

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

a ◦ b =

a 1 a 2 a 3

b 1 b 2 b 3

 (^) = a 1 b 1 + a 2 b 2 + a 3 b 3 (1)

1.2 Cross Product

a × b =

a 1 a 2 a 3

 ×

b 1 b 2 b 3

a 2 b 2 − a 3 b 2 a 3 b 1 − a 1 b 3 a 1 b 2 − a 2 b 1

2 Bresehenham Algorithm

Given two points A = (x 0 , y 0 ) and B = (x 1 , y 1 ), 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 := x 0 up to x 1. 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.

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

1 w

x y 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 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).  

sv 1 0 0 0 1

4.2 Rotation

Rotation by angle φ from origin (0, 0), anti-clockwise is implemented by

Rφ =

cos φ − sin φ 0 sin φ cos φ 0 0 0 1

In particular we get

Rπ 2 =

 (^) , Rπ =

 (^) , R 32 π =

6 Rotations in 3D Space

Anti-Clockwise rotation around an axis m by angle φ is achievable with matrix Rm as follows.

Rx =

0 cos φ − sin φ 0 0 sin φ cos φ 0 0 0 0 1

Ry =

cos φ 0 sin φ 0 0 1 0 0 − sin φ 0 cos φ 0 0 0 0 1

Rz =

cos φ − sin φ 0 0 sin φ cos φ 0 0 0 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.

w = − (^) ||^1 g|| g u = (^) ||t ×^1 w|| (t × w) v = w × u (18)

8 Viewing Transformation

From camera coordinate system (u, v, w), we can construct viewing matrix

Mview =

ux uy uz −uT^ e vx vy vz −vT^ e 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)

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.

tx = (c^ −d ◦e )n^ ◦ n (28)

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.