Posts

# Writing Raw WebAssembly

WebAssembly is a binary instruction format for the web. It shipped in all major browsers and it is more than likely that it is going to be a game changer. High performance, CPU-bound apps such as games and digital content creation packages that would struggle to be performant in JavaScript have now a chance to be usable on the web.
WebAssembly is an intermediate instruction representation format, suitable to be a compile target for languages such as C, C++ and Rust.

Posts

# The Angle Between Two Vectors

Let’s take two vectors \(\vec{a}\) and \(\vec{b}\) on the 2D plane and an orthonormal basis \((\vec{i}, \vec{j})\); we denote \(\mathcal{C}\) the application that maps a vertex to its coordinates. For some \(a, \alpha, b, \beta\) it must be true that:
$$ \mathcal{C}(\vec{a}) = [x_a, y_a] = [a~cos(\alpha), a~sin(\alpha)] \\
\mathcal{C}(\vec{b}) = [x_b, y_b] = [b~cos(\beta), b~sin(\beta)] $$
The sine of the oriented angle Now let us consider the oriented angle between \(\vec{a}\) and \(\vec{b}\); this is equal to \(\beta - \alpha\).

Posts

# The TBN Matrix

Let \(p_1\), \(p_2\) and \(p_3\) be the vertices of a triangle in a 3D space \(S\), with texture coordinates \((u_1, v_1)\), \((u_2, v_2)\) and \((u_3, v_3)\) respectively. Vectors \(\vec{p_1 p_2}\) and \(\vec{p_1 p_3}\) lie in a plane \(P\). Let \((\vec{t}, \vec{b})\) be a base of \(P\). then, there must exist \(\alpha, \beta, \gamma, \delta\) such that:
$$ \vec{p_1 p_2} = \alpha \vec{t} + \beta \vec{b} $$
$$ \vec{p_1 p_3} = \gamma \vec{t} + \delta \vec{b} $$

Posts

# Coordinate systems

Let \(\vec{v}\) be a vector on a plane. Let’s assume that there exist two other vectors \(\vec{i}\) and \(\vec{j}\) on the same plane such that we can express \(\vec{v}\) as:
$$ \vec{v} = x \vec{i} + y \vec{j} $$
Where \(x, y \in \mathbb{R} \).
In such a scenario, we can call the ordered list \((\vec{i}, \vec{j})\) a coordinate system for the plane and we call the pair \((x, y)\) the coordinates of \(\vec{v}\) in that coordinate system.

Posts

# The Pythagorean theorem

In this post I will provide an intuitive proof of a very foundational little result in elementary geometry: the Pythagorean theorem.
Statement Given a right triangle as the one in Figure 1.i with legs a and b and hypothenuse c, the Pythagorean theorem states that the area of the square whose side is c is the sum of the areas of the two squares having sides a and b. See Figure 1.