Friday, May 12, 2017

Unit Normal / Vector

Unit Vector of a vector in n dimensions

function un(v)=v/max(len3(v),1e-64);// "1e-64" don allow div by zero
function len3(v) =len(v)>1?
sqrt(addl([for(i=[0:len(v)-1])pow(v[i], 2)]))
:len(v)==1?v[0]:v; 
function addl(l,c=0)= len(l)-1 >c?l[c]+addl(l,c+1):l[c];

No comments:

Post a Comment