diff options
author | Holden Rohrer <holden.rohrer@gmail.com> | 2019-12-23 23:11:42 -0500 |
---|---|---|
committer | Holden Rohrer <holden.rohrer@gmail.com> | 2019-12-23 23:11:42 -0500 |
commit | a59b6c0cfdeb469cecb00648cf6b3c03627322b8 (patch) | |
tree | c8bed9dceb150d630ef3eddf2ede5d79e06f571e /utils | |
parent | 6c912dc1511c7eb17b2c2ff43c1023e8fb9aff78 (diff) |
added vec.js
Diffstat (limited to 'utils')
-rw-r--r-- | utils/vec.js | 26 |
1 files changed, 26 insertions, 0 deletions
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); +} |