# Help me understand the derivation of this tangent space to object space matrix

I was trying to follow this http://foundationsofgameenginedev.com/FGED2-sample.pdf

But had problem understanding formula 7.33. $$p_i-p_j=(u_i-u_j)\mathrm{t}+(v_i-v_j)\mathrm{b}$$ * $$p_i,p_j$$ being vertices on a triangle, and $$u_*,v_*$$ being their texture coordiniates, and $$M_{tangent}=\left[\mathrm{t}\space\mathrm{b}\space\mathrm{n}\right]$$

If the matrix has to be orthogonal (why though?), then if I'm not mistaken, all its vectors have to measure 1 in magnitude. It surely looks like there lacks constraints on $$p_i$$ and $$p_j$$ - they can be at any distance from each other while $$\left|u_i-u_j\right|<1$$.

Where did I get it wrong?

@pmw1234 Please read the following and do elaborate a little. I'm all confused here. Whether or not the textbooks I have are good enough.

The book says because M is orthogonal, $$M^T$$ is the reverse transformation.

The textbook definition of an orthogonal matrix is $$$${M^T}{M}={M}{M^T}=I$$$$ or $${M^T}={M^{-1}}$$

From the definition follows one of the properties:

A matrix is orthogonal if and only if its rows/cols are orthonormal vectors.

Proof:

$$\begin{eqnarray} \text{Because}\\ M&=&\begin{bmatrix} \mathrm{r}_{1}\\ \mathrm{r}_{2}\\ \vdots\\ \mathrm{r}_{n} \end{bmatrix}\\ M^T&=&\begin{bmatrix}\mathrm{r}_{1}^T&\mathrm{r}_{2}^T&\ldots&\mathrm{r}_{n}^T\end{bmatrix}\\ M\times{M^T}&=&\begin{bmatrix} \mathrm{r}_{1}\mathrm{r}_{1}^T&\mathrm{r}_{1}\mathrm{r}_{2}^T&\ldots&\mathrm{r}_{1}\mathrm{r}_{n}^T\\ \mathrm{r}_{2}\mathrm{r}_{1}^T&\mathrm{r}_{2}\mathrm{r}_{2}^T&\ldots&\mathrm{r}_{2}\mathrm{r}_{n}^T\\ \vdots&\vdots&\ddots&\vdots\\ \mathrm{r}_{n}\mathrm{r}_{1}^T&\mathrm{r}_{n}\mathrm{r}_{2}^T&\ldots&\mathrm{r}_{n}\mathrm{r}_{n}^T \end{bmatrix}\\ \\ \text{Therefore}\\ \mathrm{r}_{i}\mathrm{r}_{j}^T&=&0&(i\neq{j})\\ \mathrm{r}_{i}\mathrm{r}_{i}^T&=&\left|\mathrm{r}_{i}\right|=1\\ \\ \end{eqnarray}$$

i.e. the rows form an orthonormal basis.

Q.E.D.

If the book calling M orthogonal isn't enough, and the rows are merely literally "orthogonal" to each other, I don't see how the "reverse transformation" is meaningful.

A trivial example is.

$$\begin{eqnarray} M&=&\begin{bmatrix} 2&0&0\\ 0&1&0\\ 0&0&1\\ \end{bmatrix}\textrm{the rows being perfectly "orthogonal"}\\ M^T&=&M\\ V&=&\begin{bmatrix} 1\\ 1\\ 1\\ \end{bmatrix}\\ M\times{V}&=&\begin{bmatrix} 2\\ 1\\ 1\\ \end{bmatrix}\\ M^T\times{M}\times{V}&=&\begin{bmatrix} 4\\ 1\\ 1\\ \end{bmatrix} \end{eqnarray}$$ I can't see how $$M^T$$ reverses anything.

• This is more of a linear algebra question. But if you really stop and think about it, two vectors can still be orthogonal and have very different magnitudes. Just image a short vector (small magnitude) orthogonal to a very long vector (high magnitude). Since vectors don't have position, it doesn't matter where the original points are. The end goal being to generate an orthonormal basis (which is orthogonal by definition) that allows us to perform a "change of basis" on both vertices and vectors, in this case from object space to so call "tangent space". Dec 22 '20 at 0:23
• I understand two vectors can be orthogonal no matter their magnitudes, but the text says the very Matrix is orthogonal and even gives its transpose as its inverse. I read the given code, if I understand correctly, it generates an "average" tangent by summing up all tangents and normalizing the result, then produces an orthonormal basis of [t, b, n]. But 7.33 to me, definitely won't guarantee orthonormal t and b. Dec 22 '20 at 2:14
• @pmw1234 So it's summing up tangents of various magnitudes (each derived from 7.33) to generate the "average". I can't figure out the math behind this. Dec 22 '20 at 2:20
• That equation is saying: Given the vector Pij that you can move in the U direction some number of units and then in the V direction some number of units, and the sum of those two vectors is the same is Pij. U and V are coordinate axis in the basis that we are looking for and they are called the tangent and bitangent. Together with the normal we have a complete TBN basis. Later they have to be normalized (which the text even points out) in order to make the final basis using the gram schmidt process. Dec 22 '20 at 21:02
• @pmw1234 Sorry for the slow reply, I see that they are normalized later. I was assuming this formula should give me unit t and b, since it follows the part stating that the matrix is orthogonal, and is using the same letters. Small modifications say, with t', b', would clear things up for me. And finally thanks for your kind replies. Jan 12 at 1:51