Showing posts with label normal. Show all posts
Showing posts with label normal. Show all posts

Tuesday, May 16, 2017

Distance from a point to a plane

Usage:

my_dist=distance_point2plane([0,0,50],[100,0,0],[-1,0,0]);
point_projected_on_plane= point-my_dist*planes_normal;


function distance_point2plane(point, planes_origin, planes_normal) =
let (v = point - planes_origin)   
(
v.x * planes_normal.x + 
v.y * planes_normal.y + 
v.z * planes_normal.z
)); 

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];