Skip to content

Instantly share code, notes, and snippets.

@vlandham
Forked from tmcw/README.md
Created February 28, 2013 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vlandham/5060099 to your computer and use it in GitHub Desktop.
Save vlandham/5060099 to your computer and use it in GitHub Desktop.
// Turning an angle into a point on a unit
// circle and then back again
// convert from degrees to radians
D2R = Math.PI / 180;
// convert from radians to degrees
R2D = 180 / Math.PI;
// our angle
angle = 30;
// this angle in radians
radians = angle * D2R;
// point on a unit circle
point = {
x: Math.cos(radians),
y: Math.sin(radians)
};
// back to the angle in radians
back = Math.atan2(point.y, point.x);
// back to the angle in degrees
back_angle = back * R2D;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment