Created
November 2, 2014 19:51
-
-
Save paulfryzel/6bb9a0b81e94fd4e16c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Vector3(x, y, z) { | |
this.x = x; | |
this.y = y; | |
this.z = z; | |
} | |
Vector3.prototype.magnitude = function() { | |
return Math.sqrt(Math.pow(this.x, 2) + Math.pow(this.y, 2) + Math.pow(this.z, 2)); | |
}; | |
Vector3.prototype.normalize = function() { | |
var length = this.magnitude(); | |
return new Vector3(this.x / length, this.y / length, this.z / length); | |
}; | |
var a = new Vector3(3, 1, 2); | |
print(a.magnitude()); | |
print(a.normalize().magnitude()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
js-js/js.js test #1