Converting Radians into Degrees (and Vice Versa)

When working with angles, most people are comfortable measuring angles using degrees, but many of Apple’s frameworks expect radians. To convert degrees to radians (or vice versa), you could write your own conversion functions, but there’s no reason to do so since Apple’s GLKit framework includes such conversion functions.

All you have to do is import the GLKit into your project to gain access to its conversion functions. Then define degrees or radians as a Float data type.

To convert degrees into radians, use the GLKMathDegreesToRadians function.

To convert radians into degrees, use the GLKMathRadiansToDegrees function like this:

import GLKit

let degrees: Float = 360

let radians = GLKMathDegreesToRadians(degrees)
let newDegrees = GLKMathRadiansToDegrees(radians)

The above code will convert 360 degrees into 6.283185 radians and then convertĀ 6.283185 radians back to 360 degrees.

December 4th, 2017 by
HTML Snippets Powered By :