30秒学会 Golang 片段 · 2020年5月25日

30秒学会 Golang 片段 – Rads

Converts an angle from degrees to radians.

Use math.Pi and the degree to radian formula to convert the angle from degrees to radians.

代码实现

import "math"

func Rads(d float64) float64 {
    return d * math.Pi / 180.0
}

使用样例

Rads(90.0) // ~1.5708