Node.js examples for Data Structure:Vector
Vector length, dot product, distance, angle
function vecLength(x,y){ return Math.sqrt(x*x + y*y); } function vecDot(x1,y1, x2,y2){ return x1*x2+y1*y2; } function vecDist(x1,y1, x2,y2){ return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } function vecAngle(x1,y1, x2,y2){ return Math.acos(vecDot(x1,y1, x2,y2)/((vecLength(x1,y1)*vecLength(x2,y2)))+EPSILON); }