dp-s_doc/Object/Math/Math.md

283 lines
8.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# MathClass 类函数文档
## 一、getDirectionToTargetX 函数
### 函数签名
- `function getDirectionToTargetX(objX, x)`
### 参数
- `objX`:整数,表示对象的 X 坐标
- `x`:整数,表示目标 X 坐标
### 返回值
- 如果 `objX` 大于 `x`,返回 0否则返回 1。
---
## 二、Rand 函数
### 函数签名
- `function Rand(Min, Max)`
### 参数
- `Min`:整数,表示随机数的最小值
- `Max`:整数,表示随机数的最大值(左闭右开区间)
### 返回值
- 一个在 `Min``Max` 之间的随机整数。
---
## 三、getCollisionByObjBox 函数
### 函数签名
- `function getCollisionByObjBox(obj, box)`
### 参数
- `obj`:对象,包含 `X`、`Y`、`Z` 属性
- `box`:数组,表示碰撞盒的参数
### 返回值
- 数组,包含碰撞盒的两个顶点坐标。
---
## 四、GetDistancePos 函数
### 函数签名
- `function GetDistancePos(startX, direction, offsetX)`
### 参数
- `startX`:整数,表示起始 X 坐标
- `direction`整数表示方向0 或 1
- `offsetX`:整数,表示偏移量
### 返回值
- 根据方向计算得到的新的 X 坐标。
---
## 五、getRorateAngleByCurrentPos 函数
### 函数签名
- `function getRorateAngleByCurrentPos(x1, y1, z1, x2, y2, z2)`
### 参数
- `x1`、`y1`、`z1`:整数,表示第一个点的坐标
- `x2`、`y2`、`z2`:整数,表示第二个点的坐标
### 返回值
- 目前总是返回 0。
---
## 六、sq_BParabola 函数
### 函数签名
- `function sq_BParabola(currentT, maxT, initZPos, jumpHeight, lastZPos)`
### 参数
- `currentT`:整数,表示当前时间
- `maxT`:整数,表示最大时间
- `initZPos`:整数,表示初始 Z 坐标
- `jumpHeight`:整数,表示跳跃高度
- `lastZPos`:整数,表示最终 Z 坐标
### 返回值
- 通过贝塞尔曲线计算得到的 Z 坐标,整数类型。
---
## 七、sq_Parabola 函数
### 函数签名
- `function sq_Parabola(x, b, c)`
### 参数
- `x`:整数,表示自变量
- `b`:整数,表示抛物线参数
- `c`:整数,表示抛物线参数
### 返回值
- 通过抛物线公式计算得到的值,浮点数类型。
---
## 八、Get2D_Distance 函数
### 函数签名
- `function Get2D_Distance(x1, y1, x2, y2)`
### 参数
- `x1`、`y1`:整数,表示第一个点的坐标
- `x2`、`y2`:整数,表示第二个点的坐标
### 返回值
- 两个点之间的平面距离,浮点数类型。
---
## 九、CheckAngleIsInArea 函数
### 函数签名
- `function CheckAngleIsInArea(judge, startA, endA)`
### 参数
- `judge`:整数,表示要判断的角度
- `startA`:整数,表示起始角度
- `endA`:整数,表示结束角度
### 返回值
- 如果 `judge``startA``endA` 形成的锐角内,返回 `true`;否则返回 `false`
---
## 十、toDegree 函数
### 函数签名
- `function toDegree(x)`
### 参数
- `x`:浮点数,表示弧度值
### 返回值
- 弧度值转换为角度值,浮点数类型。
---
## 十一、toRadian 函数
### 函数签名
- `function toRadian(x)`
### 参数
- `x`:浮点数,表示角度值
### 返回值
- 角度值转换为弧度值,浮点数类型。
---
## 十二、CubeAndCubeCollection 函数
### 函数签名
- `function CubeAndCubeCollection(c1StartX, c1StartY, c1StartZ, c1EndX, c1EndY, c1EndZ, c2StartX, c2StartY, c2StartZ, c2EndX, c2EndY, c2EndZ)`
### 参数
- `c1StartX`、`c1StartY`、`c1StartZ`:整数,表示第一个立方体的起始坐标
- `c1EndX`、`c1EndY`、`c1EndZ`:整数,表示第一个立方体的结束坐标
- `c2StartX`、`c2StartY`、`c2StartZ`:整数,表示第二个立方体的起始坐标
- `c2EndX`、`c2EndY`、`c2EndZ`:整数,表示第二个立方体的结束坐标
### 返回值
- 如果两个立方体有碰撞,返回 `true`;否则返回 `false`
---
## 十三、pointIsInCubeArea 函数
### 函数签名
- `function pointIsInCubeArea(px, py, pz, startX, startY, startZ, endX, endY, endZ)`
### 参数
- `px`、`py`、`pz`:整数,表示要判断的点的坐标
- `startX`、`startY`、`startZ`:整数,表示立方体的起始坐标
- `endX`、`endY`、`endZ`:整数,表示立方体的结束坐标
### 返回值
- 如果点在立方体内,返回 `true`;否则返回 `false`
---
## 十四、pointIsIn4PointArea 函数
### 函数签名
- `function pointIsIn4PointArea(px, py, x1, y1, x2, y2, x3, y3, x4, y4)`
### 参数
- `px`、`py`:整数,表示要判断的点的坐标
- `x1`、`y1`、`x2`、`y2`、`x3`、`y3`、`x4`、`y4`:整数,表示四边形的四个顶点坐标
### 返回值
- 如果点在四边形内,返回 `true`;否则返回 `false`
---
## 十五、get4PointArea 函数
### 函数签名
- `function get4PointArea(x1, y1, x2, y2, x3, y3, x4, y4)`
### 参数
- `x1`、`y1`、`x2`、`y2`、`x3`、`y3`、`x4`、`y4`:整数,表示四边形的四个顶点坐标
### 返回值
- 四边形的面积,浮点数类型。
---
## 十六、get3PointArea 函数
### 函数签名
- `function get3PointArea(x1, y1, x2, y2, x3, y3)`
### 参数
- `x1`、`y1`、`x2`、`y2`、`x3`、`y3`:整数,表示三角形的三个顶点坐标
### 返回值
- 三角形的面积,浮点数类型。
---
## 十七、getSign 函数
### 函数签名
- `function getSign(var)`
### 参数
- `var`:整数,表示要判断符号的数
### 返回值
- 如果 `var` 小于 0返回 1如果 `var` 大于 0返回 -1如果 `var` 等于 0返回 0。
---
## 十八、sqrt 函数
### 函数签名
- `function sqrt(sum)`
### 参数
- `sum`:浮点数,表示要开平方的数
### 返回值
- `sum` 的平方根,浮点数类型。
---
## 十九、Round 函数
### 函数签名
- `function Round(var)`
### 参数
- `var`:浮点数,表示要四舍五入的数
### 返回值
-`var` 进行四舍五入后的结果,整数类型。
---
## 二十、getUniformVelocity 函数
### 函数签名
- `function getUniformVelocity(sv, ev, currentRate, maxRate)`
### 参数
- `sv`:浮点数,表示起始值
- `ev`:浮点数,表示结束值
- `currentRate`:整数,表示当前速率
- `maxRate`:整数,表示最大速率
### 返回值
- 根据当前速率和最大速率计算得到的在 `sv``ev` 之间的值,浮点数类型。
---
## 二十一、sq_GetAccel 函数
### 函数签名
- `function sq_GetAccel(sv, ev, currentRate, maxRate, increaseFeature)`
### 参数
- `sv`:浮点数,表示起始值
- `ev`:浮点数,表示结束值
- `currentRate`:整数,表示当前速率
- `maxRate`:整数,表示最大速率
- `increaseFeature`:布尔值,表示加速度的特征
### 返回值
- 根据当前速率、最大速率和加速度特征计算得到的在 `sv``ev` 之间的值,浮点数类型。
---
## 二十二、getMax 函数
### 函数签名
- `function getMax(a, b)`
### 参数
- `a`、`b`:整数,表示要比较的两个数
### 返回值
- `a``b` 中的较大值。
---
## 二十三、getMin 函数
### 函数签名
- `function getMin(a, b)`
### 参数
- `a`、`b`:整数,表示要比较的两个数
### 返回值
- `a``b` 中的较小值。
---
## 二十四、getBeizeri 函数
### 函数签名
- `function getBeizeri(var1, var2, p0, p1, p2, p3)`
### 参数
- `var1`、`var2`:整数,表示贝塞尔曲线的参数
- `p0`、`p1`、`p2`、`p3`:浮点数,表示贝塞尔曲线的控制点
### 返回值
- 通过贝塞尔曲线公式计算得到的值,浮点数类型。
---
## 二十五、getBeizeriAngle 函数
### 函数签名
- `function getBeizeriAngle(var1, var2, p0, p1, p2, p3)`
### 参数
- `var1`、`var2`:整数,表示贝塞尔曲线的参数
- `p0`、`p1`、`p2`、`p3`:浮点数,表示贝塞尔曲线的控制点
### 返回值
- 通过贝塞尔曲线公式计算得到的角度值,浮点数类型。
---