My favorite two lines in this. The first uses dot products to find the component of v in the direction of a, the second simply reuses the first, but uses the perpendicular of a instead.
It was one of those "I wonder if this will work right" things, and it totally did. Thanks #Desmos.