Make Swift Assume Degrees for Trigonometry Calculations

后端 未结 7 2442
抹茶落季
抹茶落季 2020-12-06 14:01

Is it possible to change a setting, property, etc in Swift for iOS so that it assumes degrees for trigonometry calculations rather than radians?

For example si

7条回答
  •  不思量自难忘°
    2020-12-06 14:18

    You can define global functions that return the sin of a degree value. Just place the function in a swift file outside of any class.

    func sind(degrees: Double) -> Double {
        return sin(degrees * M_PI / 180.0)
    }
    

    So anywhere in your project you can just use:

    sind(90) // Returns 1
    

提交回复
热议问题