From a59b6c0cfdeb469cecb00648cf6b3c03627322b8 Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Mon, 23 Dec 2019 23:11:42 -0500 Subject: added vec.js --- utils/vec.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 utils/vec.js (limited to 'utils') diff --git a/utils/vec.js b/utils/vec.js new file mode 100644 index 0000000..9808c8b --- /dev/null +++ b/utils/vec.js @@ -0,0 +1,26 @@ +// A utility library for vector (coordinate) operations. + +exports.mult = function(vec, scal){ + for (let i = 0; i < vec.length; i++) + vec[i] = scal*vec[i]; + return vec; +} + +function elem(orig, vec, op){ + let comb = []; + for (let i = 0; i < orig.length; i++){ + comb.push(op(vec[i],orig[i])); + } + return comb; +} +exports.elem = elem; + +exports.add = function(orig, vec){ + return elem(orig, vec, (a,b) => a+b); +} +exports.sub = function(orig, vec){ + return elem(orig, vec, (a,b) => a-b); +} +exports.dot = function(orig,vec){ + return elem(orig, vec, (a,b) => a*b); +} -- cgit