Reversing change of basis I have a direction vector (x,y,z) that I am representing as relative to a surface normal by performing a 'change of basis' on it, using the orthogonal basis created using the surface normal as the z-forward (0,0,1) in the new basis. I perform this using dot products between each basis and the elements of the direction vector.
I then rotate this direction vector in 'surface normal space', and would like to then bring it back into the original space it existed in, the original basis, so that it is no longer represented as local to the surface normal. How can I do this?
 A: The change of basis is essentially a matrix multiplication. Assuming your original vector is $v=(x,y,z)$ in global coordinates, and $a,b,c$ are the unit vectors of the local coordinate system. Then what you do is this:
$$\begin{pmatrix}x'\\y'\\z'\end{pmatrix}=
\begin{pmatrix}a\cdot v\\ b\cdot v\\c\cdot v\end{pmatrix}=
\begin{pmatrix}-\;a\;-\\-\;b\;-\\-\;c\;-\end{pmatrix}\cdot
\begin{pmatrix}x\\y\\z\end{pmatrix}$$
Computing the three dot products is the same as a multiplication with a matrix whose rows are the unit vectors of the new (local) coordinate system, expressed in coordinates for the old (global) coordinate system.
The usual thing to undo a matrix multiplication is you multiply with the inverse matrix. But if $a,b,c$ are orthonormal, then the matrix is called orthogonal and the inverse of that matrix is just its transpose: a matrix whose columns are $a,b,c$. So the inverse transformation is
$$\begin{pmatrix}x\\y\\z\end{pmatrix}=
\begin{pmatrix}|&|&|\\a&b&c\\|&|&|\end{pmatrix}\cdot
\begin{pmatrix}x'\\y'\\z'\end{pmatrix}=
x'a + y'b + z'c$$
In a sense the linear combination at the end there is the generic definition of how coordinates and basis connect: the coordinates of a vector always describe the coefficients of a linear combination of the basis vectors. This is true even if you don't assume the existence of a global coordinate system at all.
If you want to, you can comine all three steps (changing from global to local coordinate system, performing rotation in local coordinate system, changing back to global coordinate system) as a single operation, by multiplying the matrices.
$$\begin{pmatrix}|&|&|\\a&b&c\\|&|&|\end{pmatrix}\cdot
\begin{pmatrix}
\cos\varphi&-\sin\varphi&0\\
\sin\varphi&\cos\varphi&0\\
0&0&1
\end{pmatrix}\cdot
\begin{pmatrix}-\;a\;-\\-\;b\;-\\-\;c\;-\end{pmatrix}$$
This can be useful if you want to rotate multiple vectors for the same surface normal.
Also notice that if you always want to rotate about a given angle around the normal direction, you essentially have the axis-angle description of a rotation. You can use Rodrigues' formula to compute the rotation without converting to a local coordinate system first. You can also convert that description to a rotation matrix and from that to a number of other descriptions without going through the local coordinate system first.
