View Single Post
  #20  
Old 01-06-2011, 02:50 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
PHP Code:
function degtorad(temp.d) {
  return 
temp.d*pi/180;
}

function 
radtodeg(temp.r) {
  return 
temp.r*180/pi;

For anyone interested.

A degree is a value between 0 and 360, which we can write as [0,360].
A radian is a value between 0 and 2*pi, which we can write as [0,2*pi].

This is how degtorad would work:
  • Start with [0,360].
  • Divide by 360, and get to [0,1].
  • Multiple by 2pi, and get to [0,2*pi].

(The way I wrote it in the code was divide by 180 then multiple by pi. Same thing.)

radtodeg would just be the opposite.

Also worth noting, 0 points to the right, and positive values rotate counterclockwise.
Reply With Quote