Degrees to radians
JavaScript’s Math.PI
constant can be used to convert an angle from degrees to radians. The conversion formula is radians = degrees * Math.PI / 180.0
.
代码实现
const degreesToRads = deg => (deg * Math.PI) / 180.0;
degreesToRads(90.0); // ~1.5708
Radians to degrees
Conversely, the conversion formula from radians to degrees is degrees = radians * 180.0 / Math.PI
.
使用样例
const radsToDegrees = rad => (rad * 180.0) / Math.PI;
radsToDegrees(Math.PI / 2); // 90
翻译自:https://www.30secondsofcode.org/js/s/convert-degrees-radians