Created
April 29, 2013 20:28
-
-
Save BrianHicks/5484517 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 Point(x, y) { | |
this.x = x; | |
this.y = y; | |
} | |
function Vector(degrees, length) { | |
this.degrees = degrees; // -180 to 180 | |
this.length = length; | |
this.radians = degrees * Math.PI / 180; | |
// assuming y is up | |
this.x = Math.cos(this.radians) * this.length; | |
this.y = Math.sin(this.radians) * this.length; | |
} | |
function transform(point, vector) { | |
return new Point( | |
point.x + vector.x, | |
point.y + vector.y | |
); | |
} | |
var original = new Point(20, 200), | |
offset = new Vector(60, 1000), | |
transformed = transform(original, offset); | |
console.log(transformed.x); // 520.0000000000001 | |
console.log(transformed.y); // 1066.0254037844386 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment