I am having trouble with a singularity while normalizing a 2D vector v for in case of v = [0,0]. I would like the normalization to return some proper unit vector in this case, e.g. v = [1,0].
While trying to calculate
v/|v|, it is easy to calculate a singularity free vector norm |v| = sqrt(v(1)^2, v(2)^2 + eps) similar to
this post. However, v/|v| is still zero in this case due to the numerator.
What I am therefore looking for is a way to slightly push the first component of v to one side away from 0, something like v(1) = v(1) + sign(v(1)) * eps for sign(x<0)=-1/
sign(x>=0)=1. However, as sign is defined with sign(0) = 0, this does not work as well.
It feels like this is quite a usual problem but I just cannot think of a proper answer. Is there an easy way to remove this singularity?