Vec3 - 3 element Vector
This is a very simple library for maths on 3 element vectors. It's especially useful when dealing with 3D data, for example from Puck.js's magnetometer:
// get a zero reading when code is uploaded
var zero = Puck.mag();
// handle data as it's received from the magnetometer
Puck.on('mag', function(xyz) {
// work out strength by subtracting our zero reading and getting the magnitude
var strength = new Vec3(xyz).sub(zero).mag();
console.log(strength);
});
Puck.magOn();
Note: The value returned from Puck.mag()
is not itself a Vec3
, but
any object with x
, y
and z
fields can be used as an argument to a Vec3
method that expects another vector.
Reference
// Set the value of this vector
Vec3.prototype.set = function (x, y, z) { ... }
// Return a new vector made by adding the argument to this
Vec3.prototype.add = function (v) { ... }
// Return a new vector made by subtracting the argument from this
Vec3.prototype.sub = function (v) { ... }
// Multiply this vector by the scalar argument
Vec3.prototype.mul = function (v) { ... }
// Return the Dot product of this vector with the argument
Vec3.prototype.dot = function (v) { ... }
// Return the Cross product of this vector with the argument
Vec3.prototype.cross = function (v) { ... }
// Return the Magnitude of this vector
Vec3.prototype.mag = function () { ... }
// Return a vector containing the minimum XYZ components of this and the parameter
Vec3.prototype.min = function (v) { ... }
// Return a vector containing the maximum XYZ components of this and the parameter
Vec3.prototype.max = function (v) { ... }
/* @constructor Create a new vector
* Either with an object: new Vec3({x:1, y:2, z:3});
* 3 values: new Vec3(1,2,3);
* or nothing, for 0,0,0: new Vec3();
*/
function (x, y, z) { ... }
Using
(No tutorials are available yet)
This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.