A multidimensional vector math library for JS
var v = require('veck')
// These are all the same vector
var v1 = v(-2, 10, 2.3)
var v2 = v('-2i+10j+2.3k')
var v3 = v([-2,10,2.3])
var v4 = v({x: -2, y: 10, z: 2.3})
// These are also the same vector
// Note: vectors created through arguments can only be created with 'new'
var u1 = new v(-2, 3, 1, 4, -10.2, 7.5, 1)
var u2 = v([-2, 3, 1, 4, -10.2, 7.5, 1])
var u3 = new v([-2, 3, 1, 4, -10.2, 7.5, 1])
var u4 = v({a: -2, b: 3, c: 1, d: 4, e: -10.2, f: 7.5, g: 1})
var u5 = new v({a: -2, b: 3, c: 1, d: 4, e: -10.2, f: 7.5, g: 1})
var u6 = v('-2a+3b+c+4d-10.2e+7.5f+g+2h+10i')
var u7 = new v('-2a+3b+c+4d-10.2e+7.5f+g+2h+10i')
Returns veck as an Array
new v([1,2,3]).toArray() => [1,2,3]
Returns the vector as an ijk string, it will use more letters if need be.
new v([1,2,3]).toString() => 'i+2j+3k'
Makes an identical copy of the current vector.
new v([1,2,3]).equals(new v([1,2,3]))
// this is true
Performs a scalar multiplication on the current vector using the provided parameter, k. .multiply() can also be used as an alias for this
var v1 = v([1,2,3])
v1.times(2)
v1.equals(v([2,4,6]))
//This is true!
Performs a scalar division on the current vector using the provided parameter, k. This is the inverse of .multiply
var v1 = v([2,4,6])
v1.divide(2)
v1.equals(v([1,2,3]))
//This is true!
Computes the hadamard product of the two vectors. This is simply a new vector with each component being the product of the parent components. i.e.
var A = new v([1,2,3,4])
var B = new v([5,6,7,8])
A.hadamard(B)
// => [5,12,21,28]
// i.e. [A[0]*B[0], A[1]*B[1], A[2]*B[2], A[3]*B[3]]
This is the normal cross product of the two vectors, only works with vectors of 3 Dimensions. It will throw an error if a vector higher than 3 is given.
Computes the dot product of the two vectors.
Computes the angle between the two vectors
Normalizes the current vector, i.e. makes its magnitude one, but keeps it point in the same direction.