Skip to content

Instantly share code, notes, and snippets.

@tmcw
Last active December 14, 2015 08:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tmcw/5059825 to your computer and use it in GitHub Desktop.
Save tmcw/5059825 to your computer and use it in GitHub Desktop.
Math demo (made for mistakes)
// 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