📏 Vector2D
由浮点精度组件 (X, Y) 组成的 2D 向量。主要用于 HUD 和屏幕绘制。
🎒 示例
local new_vector = Vector2D(1452.5, 512)
🛠 构造函数
Default Constructor
No description provided
local my_vector2d = Vector2D(X?, Y?)
🧽 属性
🦠 函数
信息
该结构支持 +、-、*、/、==、一元 -(取反)以及 tostring 操作。
| Returns | Name | Description | |
|---|---|---|---|
| float | Distance | 两点之间的距离 | |
| float | DistanceSquared | 两点之间的平方距离 | |
| boolean | IsNear | 高效检查向量是否在指定半径内接近另一个向量 | |
| float | Size | 获取该向量的长度(模长) | |
| float | SizeSquared | 获取该向量的平方长度 | |
| float | Dot | 两个向量的点积 | |
| float | Cross | 两个向量的叉积 | |
| Vector2D | Lerp | 在此向量与另一个向量之间进行线性插值 |
Optimal
Distance
两点之间的距离。
返回两个向量之间的距离
local ret = my_vector2d:Distance(other)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector2D | other | Required parameter | 要获取距离的另一个向量 |
Returns
| Type | Description |
|---|---|
| float | 向量之间的距离 |
Optimal
DistanceSquared
两点之间的平方距离。
返回两个向量之间距离的平方
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
两个向量的叉积。
返回此向量与另一个向量的叉积,对于二维向量而言该值为标量
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 | 插值后的向量 |
