Change of Basis in Game Development

48 Views Asked by At

I recently went back to re-learning some bits of linear algebra: change of basis.

And, as an exercise, I decided to revisit a video game mechanic: portals.
As this youtuber puts it, the math behind it is that you want to know the Camera's position relative to the Blue Portal and then that position relative to the Red Portal.

From what I understood of Change of Basis, I would translate this to transforming the vector $X_C$ from the Camera basis $C$ into vector $X_B$ -- its corresponding vector in the Blue Portal basis $B$. Finally, using that to find vector $X_R$ which would correspond to that vector in the Red Portal's basis $R$.

From here I applied the change of basis formula twice.

$$ B \times X_B = C \times X_C $$ $$ X_B = B^{-1} \times C \times X_C $$ $$ R \times X_R = B \times X_B $$ $$ X_R = R^{-1} \times B \times X_B $$

The problem is that if I replace $X_B$ in the last equation with the second one I get: $$ X_R = R^{-1} \times B \times B^{-1} \times C \times X_C = R^{-1} \times C \times X_C $$ This makes no sense as it no longer even takes $B$ into consideration.

The video seems to end up with a matrix that would correspond to: $$ R \times B^{-1} \times C $$

So, where did I go wrong?

1

There are 1 best solutions below

0
On BEST ANSWER

Simply: change of basis twice is not quite what you want to do. Let the canonical basis (i.e. that with matrix $1$) be $W$ i.e. $$R\times X_R = B\times X_B = C\times X_C = X_W$$ You can see that all the change of basis formula does is compute which vectors in each basis represent that same canonical vector, but we actually want to compute a different canonical vector from that of the camera vector: the one that's been transported by the portal. The key idea is that the transported vector $Y$ is the same locally in the red portal's space as the camera's is in the blue portal's space, i.e. $$Y_R = X_B$$ This is not a change of basis. It is an isometric map of blue portal's space onto red portal's space. We then we apply change of basis on $Y$ $$R\times Y_R = Y_W$$ $$Y_R = R^{-1}\times Y_W$$ and change of basis on $X$ $$B \times X_B = C\times X_C$$ $$X_B = B^{-1}\times C\times X_C$$ Combined giving $$R^{-1}\times Y_W = B^{-1}\times C\times X_C$$ $$Y_W = R\times B^{-1}\times C\times X_C$$ By linearity we can apply this equation over the identity matrix to get $$Y = R\times B^{-1}\times C$$