CODECUBE VENTURES

Radian/Degree Conversion

For anyone getting into 3D programming, these two formulas will come in quite handy

Radians = Degrees * Math.PI / 180;

Degrees = Radians * 180 / Math.PI;

See, lots of algorithms use Radians ... even many of Direct3D's methods, such as Matrix.RotationAxis(), take radians. Now, one thing you might want to do if you will be converting often is setting a constant for the 180/PI and PI/180. Since the outcome of that mathematical operation will always be the same, no sense in recalculating it every time.

public const float PIover180 = (float)Math.PI / 180;

//can't have a number as the first char of a variable

public const float OneEightyoverPI = 180 / (float)Math.PI;

Latest post: Digging Up the First Version of CodeCube

See more in the archives