1.1 KiB
1.1 KiB
Math - 数学常量
数学库全局常量和辅助函数。
头文件
#include <XCEngine/Math/Math.h>
命名空间
XCEngine::Math
数学常量
| 常量 | 值 | 描述 |
|---|---|---|
PI |
3.14159265358979323846f | 圆周率 |
TWO_PI |
6.28318530717958647692f | 2π |
HALF_PI |
1.57079632679489661923f | π/2 |
DEG_TO_RAD |
PI / 180.0f | 度转弧度 |
RAD_TO_DEG |
180.0f / PI | 弧度转度 |
EPSILON |
1e-6f | 浮点比较容差 |
FLOAT_MAX |
3.402823466e+38f | float 最大值 |
辅助函数
| 函数 | 返回值 | 描述 |
|---|---|---|
Radians(degrees) |
float |
度转弧度 |
Degrees(radians) |
float |
弧度转度 |
使用示例
using namespace XCEngine::Math;
float radians = 90.0f * DEG_TO_RAD; // 90度 -> 弧度
float degrees = PI * RAD_TO_DEG; // 弧度 -> 度
float rad2 = Radians(45.0f); // 使用函数
// 浮点比较
if (std::abs(a - b) < EPSILON) {
// a 和 b 相等
}
// 三角函数(来自 <cmath>)
float sinVal = std::sin(angle);
float cosVal = std::cos(angle);