Posts from the “Math” Category

Proof of the Touching Point Equation of Parabolas


Screenshot of Pixar in a Box (Bonus: completing the proof, Environment Modeling)

The proof of the touching point equation in the environment modeling tutorial of Pixar in a Box is very neat, but it took me a second round to understand. Here I’m writing a note hoping making the proof intuitively understandable.

We need to prove that the touching point P of the parabolas arc and line QR is controlled by t on line QR.

The proof starts with writing P as controlled by a random value s on line QR, where s controls line Q’R’. Then, reforming the equation of P controlled by s on line QR results in another equation, in which P is controlled by t on line Q’R’.

The result of the reformation indicates that P lies on line Q’R’ too. Hence, P is the intersection point of QR and Q’R’.

From the observation of section 4, P becomes the touching point of QR when s is equal to t.

There’s no proof of the observation though. But it’s a very neat one that I want to explain. Now that for any point P in QR, P is either the intersection point with line Q’R’, or the touching point. If s doesn’t equal to t, we can always define the intersection point. Otherwise, P has to be the touching point, because we cannot define this one single intersection point.

Proof completed! DAH!


Matrix for 2D Polynomial Surface

Given the polynomial coefficients of a 4 * 4 polynomial surface,

f(x,y) = p00 + p10*x + p01*y + p20*x^2 + p11*x*y + p02*y^2 + p30*x^3 + p21*x^2*y + p12*x*y^2 + p03*y^3 + p40*x^4 + p31*x^3*y + p22*x^2*y^2 + p13*x*y^3 + p04*y^4

how to conveniently compute f(x, y) in a shader?

If we just do a multiplication of 2 vectors each consists of 15 elements, it’s easy to make mistakes when composing the vectors. So I did a practice to use matrix to represent the equation for a 2 * 2 polynomial:

f(x,y) = p00 + p10*x + p01*y + p20*x^2 + p11*x*y + p02*y^2 =

Much cleaner right? Now we can use a generic matrix to represent a n * n polynomial:

f(x, y) = YPX,

where P is a (n + 1) * (n + 1) matrix of the coefficients:

P = [p_00, p_10, p_20, ............., p_n0
     p_01, p_11, p_21, ......, p_(n-1)1, 0
     p_02, p_12, p_22, ..., p_(n-2)2, 0, 0
     p_0n, 0, 0, ......................, 0],

Y is a 1 * (n + 1) vector for y values:

Y = [1, y, y^2, ..., y^n],

X is a (n + 1) * 1 vector for x values:

X = [1, x, x^2, ..., x^n]^T.

Gram-Schmidt Orthogonalization

Gram-Schmidt Orthogonalization produces a an orthogonal basis for a set of linearly independent vectors. So, the idea of getting a vector’s corresponding vector in the orthogonal basis is substracting the vector’s projections onto the preceding basis vectors by the vector itself. Then whatever left is orthogonal to all the preceding basis vectors.

My question was, why that further substractions of the projections do not affect the orthogonalization with previous basis vectors??? After a while of thinking.. I realize that it’s because further substractions all happen in spaces orthogonal to previous basis vectors, so of course whatever linear operations of vectors on the orthogonal spaces do not affect the resulting vector’s orthogonalization with previous basis vectors..


Exponential Function

exp(x) = 1 + x + x^2 / 2! + x^3 / 3! + x^4 / 4! + … + x^n / n!

float Exp(float x) {

float result = 0.f;

for(int i = 0; i < n; ++i) {

float a = pow(x, i);

float b = i * (i-1) * (i-2) * … * 1;

result += a/b;


return result;