Files
XCEngine/docs/api/math/h/h.md
2026-03-20 02:35:15 +08:00

1.4 KiB

Math

命名空间: XCEngine::Math

类型: header

头文件: XCEngine/Math/Math.h

描述: 数学库常量和辅助函数头文件。

概述

Math.h 提供了图形引擎常用的数学常量和辅助函数,包括圆周率、角度转换、浮点精度等基础常量,以及角度弧度转换等常用函数。

常量

常量 描述
PI 3.14159265358979323846f 圆周率
TWO_PI 6.28318530717958647692f
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 浮点最大值

辅助函数

函数 描述
Radians 度转弧度
Degrees 弧度转度

使用示例

#include <XCEngine/Math/Math.h>

using namespace XCEngine::Math;

// 使用常量
float angle = 90.0f * DEG_TO_RAD;  // 90度转弧度

// 使用函数
float rad = Radians(180.0f);        // 180度 -> π 弧度
float deg = Degrees(PI);      // π 弧度 -> 180度

// 比较浮点数
if (fabsf(a - b) < EPSILON) {
    // 认为 a 和 b 相等
}

相关文档