Saturday, May 31, 2008

Degrees and Radians

When you were learning trigonometry, you probably measured angles in degrees. But in calculus, angles are measured in radians (search for "degrees vs. radians" on Google for the reasons). Being able to convert between these two units might be handy. PHP provides two functions for this purpose, but no such luck in ASP. As usual, we're going to write our own.


Radians is heavily based on my favorite number, pi. We're going to need this number in our calculations, so make sure to define a constant for it.


Const M_PI = 3.14159265358979323846


And now the functions themselves...


  1. function deg2rad(x)
  2.     deg2rad = x * M_PI / 180
  3. end function
  4. function rad2deg(x)
  5.     rad2deg = x * 180 / M_PI
  6. end function

View this code on Snipplr

No comments: