C++ 中 NumPy/PHP rad2deg 的等效物
为了将弧度转换为度,PHP 提供 rad2deg 函数,而 Python 的 NumPy 库提供 np.rad2deg。
在 C++ 中没有将弧度转换为度的标准函数。
但是,你可以使用此简单代码片段:
rad2deg.cpp
#define _USE_MATH_DEFINES
#include <cmath>
/**
* 将给定的弧度角度转换为度。
*/
template<typename F>
F rad2deg(F angle) {
return angle * 180.0 / M_PI;
}这适用于 double、float 等,并返回以度为单位的角。
公式非常简单:
$$\text{Degrees} = \frac{\text{Radians} \cdot 180°}{\pi}$$Check out similar posts by category:
C/C++, Mathematics
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow