Mathematically speaking, the zero vector cannot be normalized. Its length will always remain 0
.
For given vector v = (v1, v2, ..., vn)
we have: ||v|| = sqrt(v1^2 + v2^2 + ... + vn^2)
. Let us remember that a normalized vector is one that has ||v||=1
.
So for v = 0
we have: ||0|| = sqrt(0^2 + 0^2 + ... + 0^2) = 0
. You can never normalize that.
Also important to note that to ensure consistency, you should not return NaN
or any other null value. The normalized form of v=0
is indeed v=0
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…