I am trying to convert this Obj-C
code to Swift
code but I don't know what the equivalent of this code should be ?
#define DEGREES_TO_RADIANS(degrees)((M_PI * degrees)/180)
I googled and found this
But I don't understand how to convert that in Swift in my case?
Apple provides these GLKit functions for conversion:
Also, to convert fron radians to degrees (if anyone stumbles upon this on google):
Compiles under Swift 3. Still keep all values, do all calculations in radians with CGFloats..., but make the code more readable with the constants in degrees. For example: 90° The ° sign will magically do the degrees to radians conversion.
How to set this up:
Define and use a postfix operator for the ° sign. This operator will do the conversion from degrees to radians. This example is for Ints, extend these also for the Float types if you have the need.
Some examples of usage:
Warning!
It is too easy to use this conversion twice (on a value already in radians by mistake), you will get a very small number as the result, and seemingly the resulting angle will be always zero... DO NOT use ° on the same value twice (do not convert twice)!!:
swift 2.3
You're no longer limited to ASCII characters when creating variable names, so how about this using π (alt-p):
Example usage:
This is not identically what you asked, but in Swift 3 / iOS 10, you can use the Measurement type and do the conversion without knowing the formula!