-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVector3D.jsx
57 lines (43 loc) · 1.15 KB
/
Vector3D.jsx
1
#include Matrix.jsxVector3D = function(x, y, z){ if ( !(this instanceof arguments.callee) ) { return new Vector3D(x, y, z); } Matrix.apply(this, [[x],[y],[z],[1]]); this.x = x; this.y = y; this.z = z; if(this.rows != 4 || this.columns != 1){ throw new Error("Error: a 3D Vector must have 3 coordinates"); } return this;}Vector3D.prototype = new Matrix(true);Vector3D.prototype.clone = function(){ return new Vector3D(this.x, this.y, this.z);}Vector3D.prototype.setX = function(val){ this.x = val; this[0][0] = val; return this;}Vector3D.prototype.setY = function(val){ this.y = val; this[1][0] = val; return this;}Vector3D.prototype.setZ = function(val){ this.z = val; this[2][0] = val; return this;}Vector3D.prototype.toVector2D = function(){ return new Vector2D(x, y);}Vector3D.prototype.apply3DMatrix = function(m3){ var result = m3 * this; return new Vector3D(result[0][0], result[1][0], result[2][0]);}Vector3D.prototype["-"] = function(other){ return new Vector3D(this.x - other.x, this.y - other.y, this.z - other.z);}