📏 Vector2D
由浮点精度组件 (X, Y) 组成的 2D 向量。主要用于 HUD 和屏幕绘制。
🎒 示例
local new_vector = Vector2D(1452.5, 512)
🛠 构造函数
Default Constructor
No description provided
local my_vector2d = Vector2D(X?, Y?)
🧽 属性
🦠 函数
信息
This structure supports +, -, *, /, ==, unary - (negation) and tostring operations.
| Returns | Name | Description | |
|---|---|---|---|
| float | Distance | 两点之间的距离 | |
| float | DistanceSquared | 两点之间的平方距离 | |
| boolean | IsNear | 高效检查向量是否在指定半径内接近另一个向量 | |
| float | Size | 获取该向量的长度(模长) | |
| float | SizeSquared | 获取该向量的平方长度 | |
| float | Dot | 两个向量的点积 | |
| float | Cross | 两个向量的叉积 | |
| Vector2D | Lerp | 在此向量与另一个向量之间进行线性插值 |
Optimal
Distance
返回 2 个向量之间的距离
local ret = my_vector2d:Distance(other)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector2D | other | Required parameter | 要获取距离的另一个向量 |
Returns
| Type | Description |
|---|---|
| float | 向量之间的距离 |
Optimal
DistanceSquared
返回 2 个向量之间的平方距离
local ret = my_vector2d:DistanceSquared(other)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector2D | other | Required parameter | 要获取平方距离的另一个向量 |
Returns
| Type | Description |
|---|---|
| float | 向量之间的平方距离 |
Optimal
IsNear
高效检查向量是否在指定半径内接近另一个向量
local ret = my_vector2d:IsNear(other, radius)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector2D | other | Required parameter | 要对比的向量 |
| float | radius | Required parameter | 要检查的半径范围 |
Returns
| Type | Description |
|---|---|
| boolean | 该向量是否接近另一个向量 |
Optimal
Size
获取该向量的长度(模长)
local ret = my_vector2d:Size()
Returns
| Type | Description |
|---|---|
| float | 向量的长度 |
Optimal
SizeSquared
获取该向量的平方长度
local ret = my_vector2d:SizeSquared()
Returns
| Type | Description |
|---|---|
| float | 向量的平方长度 |
Optimal
Dot
返回该向量与另一个向量之间的点积
local ret = my_vector2d:Dot(other)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector2D | other | Required parameter | 要进行点积的点 |
Returns
| Type | Description |
|---|---|
| float | 点积结果 |
Optimal
Cross
返回此向量与另一个向量之间的叉积,对于 2D 向量,该值为标量
local ret = my_vector2d:Cross(other)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector2D | other | Required parameter | 要进行叉积的向量 |
Returns
| Type | Description |
|---|---|
| float | 叉积结果 |
Optimal
Lerp
根据给定的 Alpha 值返回此向量与另一个向量之间的线性插值结果
local ret = my_vector2d:Lerp(other, alpha)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector2D | other | Required parameter | 要插值到的目标向量 |
| float | alpha | Required parameter | 插值 Alpha 值,设为 0 返回当前向量,设为 1 返回目标向量 |
Returns
| Type | Description |
|---|---|
| Vector2D | 插值后的向量 |
