TITLE: Orthogonal Projection onto the $ {L}_{2} $ Unit Ball
QUESTION [7 upvotes]: On an article I'm reading, I find that:
if $v$ is a vector, the projection of of $v$ on the unit ball is:
$$p(v)=\frac{v}{\max\{1,\|v\|\}}$$
I know that a projection of a point $v$ into a space is the nearest point to $v$ inside the space..why the expression above?

REPLY [7 votes]: You can do it using KKT Conditions.
Here is something I wrote once doing so (Solution to Home Work exercise I had):

I wrote MATLAB code which implements them both at Mathematics StackExchange Question 2338491 - GitHub.
There is a test which compares the result to a reference calculated by CVX.