Skip to content

Instantly share code, notes, and snippets.

@jkosoy
Created May 24, 2012 22:10
Show Gist options
  • Save jkosoy/2784498 to your computer and use it in GitHub Desktop.
Save jkosoy/2784498 to your computer and use it in GitHub Desktop.
Trig
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