算法 - 极坐标位移

0: →
90: ↑
180: ←
270: ↓
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

---@param ox number 原点X
---@param oy number 原点Y
---@param deg number 偏移朝向
---@param dis number 偏移距离
local function calculateOffset(ox, oy, deg, dis)
local radians = deg * math.pi / 180
local fx = ox + math.cos(radians) * dis
local fy = oy + math.sin(radians) * dis
return fx, fy
end

---@param ox number 原点X
---@param oy number 原点Y
---@param deg number 偏移朝向
---@param dis number 偏移距离
local function calculateOffset(ox, oy, deg, dis)
-- 将角度转换为弧度
local radians = deg * math.pi / 180

-- 计算偏移
local fx = ox + math.cos(radians) * dis
local fy = oy + math.sin(radians) * dis

-- DEBUG
-- ox = math.round(ox * 10000) / 10000
-- oy = math.round(oy * 10000) / 10000
-- fx = math.round(fx * 10000) / 10000
-- fy = math.round(fy * 10000) / 10000
-- print('deg', deg)
-- print('ox, oy', ox, oy)
-- print('fx, fy', fx, fy)

return fx, fy
end