How do you scale along a non canonical direction? Silly question but I am not figuring it out on my own.
In 3D you can scale a point / shape / field along a canonical direction quite easily:
$p = (x_0, x_1, x_2)$ becomes $p = (ax_0, x_1, x_2)$ for example if we wanted to scale along the first axis. This map has the property that distances in any plane parallel to the plane $(x_1, x_2)$ remain unaffected.
Now given an arbitrary vector $N$ I want to induce the same transformation along the direction of $N$.
One possible solution, of course, is to find a rotation that transforms $N$ into one of the canonical directions, scale that direction, then invert the transformation. i.e. $RSR^{-1}$.
However this is inelegant, I am trying to do it in a way that involves only $N$ and requires no change of basis. i.e. I want to scale points along $N$ without changing the coordinate space, and perhaps better, in a coordinate free way.
 A: Given any vector $\vec{v}$, there is a unique way to decompose $\vec{v}$ into a component along $N$ and a component orthogonal to $N$, namely $\vec{v} = \operatorname{proj}_N(\vec{v}) + (\vec{v} - \operatorname{proj}_N(\vec{v}))$.  Moreover, there's a nice formula: $\operatorname{proj}_N(\vec{v}) = \left(\frac{N \cdot \vec{v}}{N \cdot N}\right)N$.
If I understand the question correctly, the thing you want to do is send $\vec{v}$ to $a\operatorname{proj}_N(\vec{v}) + (\vec{v} - \operatorname{proj}_N(\vec{v}))$.
In particular, in the case where $N = (1, 0, 0)$, and $\vec{v} = (x_0, x_1, x_2)$, we have
$$a\operatorname{proj}_N(\vec{v}) + (\vec{v} - \operatorname{proj}_N(\vec{v})) = a(x_0, 0, 0) + (x_0, x_1, x_2) - (x_0, 0, 0) = (ax_0, x_1, x_2)$$
This shows that the construction I described agrees with what you're saying should happen when you scale along one of the coordinate axes.
A: The way to construct a matrix that does this is as follows:
The component of $P$ parallel to $N$ is $N\cdot P N = (N^TP)N = NN^TP$
Thus $-NN^T P + P = (-NN^T + I)P$ is P minus its component orthogonal to $N$. Thus $(-NN^T + I)P + sNN^TP$ is the scaling of $P$ along the direction $N$ as described in Chris Eagle's answer.
We get:
$$(-NN^T + I)P + sNN^TP = (-NN^T + I + sNN^T)P$$
$$ = (NN^T(-I + sI) + I)P$$
$$ = (NN^T(s - 1) + I)P$$
Thus the matrix $((s - 1)NN^T + I)$ Represents a linear scaling along the direction $N$ for any $P$ in a coordinate free way.
Notice that matrix must be symmetric btw.
