forked from huuhghhgyg/Container-Terminal-Simulation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrawCircle.lua
48 lines (38 loc) · 1.33 KB
/
DrawCircle.lua
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
37
38
39
40
41
42
43
44
45
46
47
48
scene.setenv({
grid = 'plane'
})
-- 圆形参数
local centerPt = {0, 0, 0} -- 圆心
local radius = 10 -- 半径
-- 弧度参数
local fromRadian = 7 --开始位置弧度
local toRradian = 9 --终止位置弧度
-- 绘制起点
local pfrom = scene.addobj('points', {
vertices = {radius * math.sin(fromRadian) + centerPt[1], centerPt[2], radius * math.cos(fromRadian) + centerPt[3]},
size = 5,
color = 'red'
})
-- 绘制终点
local pto = scene.addobj('points', {
vertices = {radius * math.sin(toRradian) + centerPt[1], centerPt[2], radius * math.cos(toRradian) + centerPt[3]},
size = 5,
color = 'blue'
})
-- 计算
local dradian = 0.1 -- 步进弧度长度
local radian = toRradian-fromRadian > math.pi * 2 and math.pi or toRradian-fromRadian -- 旋转弧度
local pointN = math.floor(radian / dradian) -- 步进次数
local vertices = {radius * math.sin(fromRadian) + centerPt[1], 0, radius * math.cos(fromRadian) + centerPt[3]} -- 需要预先绘制原点
for r = 1, pointN do
local radianWalked = r * dradian + fromRadian
local i = r * 3
vertices[i + 1] = radius * math.sin(radianWalked) + centerPt[1]
vertices[i + 2] = centerPt[2]
vertices[i + 3] = radius * math.cos(radianWalked) + centerPt[3]
end
-- 绘制polyline
local circle = scene.addobj('polyline', {
vertices = vertices
})
scene.render()