Node.js examples for Data Structure:Vector
Returns the cross product between the two vectors. Must be 3-dimensional.
/* returns the cross product between the two vectors. Must be 3-dimensional. */ Array.prototype.cross = function(vec, vy, vz) { var x = this[0], y = this[1], z = this[2]; var vx;/*from w w w .j a v a2 s . com*/ if (typeof(vec) == "object") { vx = vec[0]; vy = vec[1]; vz = vec[2]; } else { vx = vec; } if (this.equals(vec)) throw new Error("Vector <"+this+"> is equal to <"+vec+">; can't compute cross product"); var result = [y*vz - z*vy, z*vx - x*vz, x*vy - y*vx]; checkNaN(result); return result; };