Skip to content

Instantly share code, notes, and snippets.

@paulfryzel
Created November 2, 2014 19:51
Show Gist options
  • Save paulfryzel/6bb9a0b81e94fd4e16c9 to your computer and use it in GitHub Desktop.
Save paulfryzel/6bb9a0b81e94fd4e16c9 to your computer and use it in GitHub Desktop.
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());
@paulfryzel
Copy link
Author

js-js/js.js test #1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment