University of Tampere Computer Graphics 2013
School of Information Sciences Exercise 2
7.2.2013
1. We can get the minmum of parabola f (x) = ax2
+ bx + c, a > 0,, when f0(x) = 0. In this case x has the value of x = −b/2a. Determine the value of
t for which ` : P + tu is closest to point Q. Hint: Look at the intersection formulas below and calculate the minimum of f (t) = d2
(P + tu, Q).
2. Let’s write the ray of light in the form P + tu, kuk = 1 and t ≥ 0, where u is the direction of ray and P it’s starting point. Let’s look at the reflection of light in two dimensions. Determine the point in y-axis where a ray hits, which starts from origin, goes in the direction (1, 2) and reflects from the line
` : (X − (3, 3)) · 1 √ 2(−1, −1) = 0. ? `
3. Determine the ray of light, which we get, when a ray starting from (1, 2) reflects from a ball S, which has a center point (4, 5) and radius 2.
S
4. Determine a transformation, which scales points in the direction u with a coeffient s.
5. Programming environment. In this course we use OpenGL 4.0 programming environment in order to create graphics on the computer screen. Unfortu-nately such students whose computer does not have a graphics card that supports DirectX10/OpenGL 3.3 cannot compile/run the programs. How-ever, the exercises can be done without compiling. Read the preface from http://openglbook.com and install one of the listed C/C++ compiler to your computer if you do not already have one. Install also freeglut and glew libraries and try to compile an example program given in chapter 1. An-swer shortly to the following questions. What is the purpose of freeglut and glew libraries? What means a ”Shader”Program? What is the strength of ”buffer”objects?
6. We can use 3 × 3-matrices for rotations, translations, scaling and skewing. These are all transformations which has an inverse transformation. However, there are some useful transformations which are not invertible. Let’s look at how the vector projection on a plane and cross product can be presented in a matrix form.
Show that the projections can be calculated with 3 × 3-matrices as follows: Projuv: uuT kuk2v, Proju⊥v: I− uu T kuk2 v. When u is a unit vector, the fromulas can be given in a form uuT
ja I − uuT.
Show further, that also a cross product can be calculated with 3×3-matrices:
u× v : Skew(u)v = 0 −u3 u2 u3 0 −u1 −u2 u1 0 v.
About vector projections
Vectors v and u are perpendicular to each other and u spans a sub space of R3
which is complement to v. Let’s define the projection as follows: Projuv=
u· v
kuk2u, Proju⊥v= v − Projuv.
For the projections Projuv k u, Proju⊥v ⊥ u and v = Projuv+ Proju⊥v
divide a vector v in two parts, from which one is perpendicular to u and another is parallel. Look at the picture.
Proju⊥v
Projuv u
v
Let us show that Proju⊥v⊥ u:
(Proju⊥v)·u = v− v· u kuk2u ·u = v·u−v· u
kuk2(u·u) = v·u−
v· u kuk2kuk
2
= v·u−v·u = 0.
Interserction of line and plane
Let’s write a line in a form ` : X = P +tu and a plane in a form (X−Q)·n = 0. ( (X − Q) · n = 0 X = P + tu ⇐⇒ (P + tu − Q) · n = 0 ⇐⇒ (P − Q) · n + t(u · n) = 0 ⇐⇒ t = −(P − Q) · nu · n = (Q − P ) · n u· n
When a line is parallel to a plane u · n = 0. Then, if a point in a line P is in a plane (P − Q) · n, the intersection is whole line, otherwise, line and plane do not intersect.
Intersection of a ball and a line
Let’s write a line ` in a form ` : P + tu, kuk = 1 and a ball S in a form S : d2
(X, Q) = r2
, where d2
(X, Q) is a square of distance and r2
is a square of the radius of a ball. Squaring is not necessary, but it eases the calculations. Now the equation can be written in a form kX−Qk2
= (X −Q)·(X−Q) = r2 . ( d2 (X, Q) = r2 X = P + tu ⇐⇒ d2 (P + tu, Q) = kP + tu − Qk2 = r2 ⇐⇒ (P + tu − Q) · (P + tu − Q) = r2 ⇐⇒ (P − Q + tu) · (P − Q + tu) = r2 ⇐⇒ (P − Q) · (P − Q + tu) + tu · (P − Q + tu) = r2
⇐⇒ (P − Q) · (P − Q) + (P − Q) · (tu) + (tu) · (P − Q) + (tu) · (tu) = r2
⇐⇒ kP − Qk2 + 2t(u · (P − Q)) + kuk2 t2 = r2 ⇐⇒ kP − Qk2 + 2t(u · (P − Q)) + t2 = r2 ⇐⇒ t2 + 2t(u · (P − Q)) + kP − Qk2 − r2 = 0 ⇐⇒ t = −2(u · (P − Q)) ±p4(u · (P − Q)) 2 − 4(kP − Qk2 − r2) 2 ⇐⇒ t = −(u · (P − Q)) ±p(u · (P − Q))2 − kP − Qk2 + r2
If the expression under the square root < 0, a line does not intersect a ball. If kuk 6= 1, our expression gets the form:
t = −(u · (P − Q)) ±p(u · (P − Q)) 2 − kuk2 kP − Qk2 + kuk2 r2 kuk2 .
Properties of vector products
(DP1) u · v = v · u (CP1) u × v = −v × u
(DP2) u · (v + w) = u · v + u · w (CP2) u × (v + w) = u × v + u × w (DP3) (αu) · v = α(u · v) (CP3) (αu) × v = α(u × v)
Let the vectors u and v have an angle α between them. In this case following formulas are valid: