Created
May 24, 2012 22:10
-
-
Save jkosoy/2784498 to your computer and use it in GitHub Desktop.
Trig
This file contains 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
Because I always forget... | |
// Get the angle between two points | |
atan2(y2-y1,x2-x1); | |
// Get the x and y of an object around a radius, given an angle. | |
x = cos(radians(angle)) * radius | |
y = sin(radians(angle)) * radius | |
// You can create weird orbits by changing the result of sin. For example: | |
y = sin(radians(angle))/2 * radius; | |
// And of course, add offset X and Ys if your circle isn’t at 0,0. | |
x = (cos(radians(angle)) * radius) + offsetX | |
y = (sin(radians(angle)) * radius) + offsetY | |
// Get the distance between two points. | |
sqrt(pow(y2-y1,2) + pow(x2-x1,2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment