@anonymous/

GrandioseSharpRoutine

Lua

No description

fork
loading
Files
  • main.lua

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.10555802765804212","path":"main.lua","file":{"path":"main.lua","content":{"asEncoding":{"base64":"bG9jYWwgdmVjbWV0YSA9IHt9CmxvY2FsIGZ1bmN0aW9uIHZlYyh4LHkpCglyZXR1cm4gc2V0bWV0YXRhYmxlKAoJCXsKCQkJeCA9IHgsCgkJCXkgPSB5fSwKCQl2ZWNtZXRhKQplbmQKZnVuY3Rpb24gdmVjbWV0YS5fX3Rvc3RyaW5nKGEpCglyZXR1cm4gc3RyaW5nLmZvcm1hdCgndmVjKCVmLCVmKScsIGEueCwgYS55KQplbmQKZnVuY3Rpb24gdmVjbWV0YS5fX3VubShhKQoJcmV0dXJuIHZlYygtYS54LCAtYS55KQplbmQKZnVuY3Rpb24gdmVjbWV0YS5fX2FkZChhLGIpCglyZXR1cm4gdmVjKGEueCtiLngsIGEueStiLnkpCmVuZApmdW5jdGlvbiB2ZWNtZXRhLl9fc3ViKGEsYikKCXJldHVybiB2ZWMoYS54LWIueCwgYS55LWIueSkKZW5kCmZ1bmN0aW9uIHZlY21ldGEuX19tdWwoYSxiKQoJcmV0dXJuIHZlYyhhLngqYiwgYS55KmIpCmVuZApmdW5jdGlvbiB2ZWNtZXRhLl9fZGl2KGEsYikKCXJldHVybiB2ZWMoYS54L2IsIGEueS9iKQplbmQKbG9jYWwgZnVuY3Rpb24gZG90KGEsYikKCXJldHVybiBhLngqYi54ICsgYS55KmIueQplbmQKbG9jYWwgZnVuY3Rpb24gbGVmdChhKQoJcmV0dXJuIHZlYygtYS55LCBhLngpCmVuZApsb2NhbCBmdW5jdGlvbiBwcm9qZWN0KGEsIG54LG55KQoJcmV0dXJuIHZlYyhkb3QoYSxueCksIGRvdChhLG55KSkKZW5kCmxvY2FsIGZ1bmN0aW9uIHVucHJvamVjdChhLCBueCxueSkKCXJldHVybiBueCphLnggKyBueSphLnkKZW5k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mVsCgoJbG9jYWwgciA9IG1hdGguc3FydChkb3QocG9zLHBvcykpCglsb2NhbCBwaGkgPSBtYXRoLmF0YW4yKHBvcy55LCBwb3MueCkKCS0tIHByaW50KHIscGhpKQogIHByaW50KHRvc3RyaW5nKHZlbGNuKSkKZW5kCg=="},"asBuffer":null},"loaded":true}}
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
local vecmeta = {}
local function vec(x,y)
	return setmetatable(
		{
			x = x,
			y = y},
		vecmeta)
end
function vecmeta.__tostring(a)
	return string.format('vec(%f,%f)', a.x, a.y)
end
function vecmeta.__unm(a)
	return vec(-a.x, -a.y)
end
function vecmeta.__add(a,b)
	return vec(a.x+b.x, a.y+b.y)
end
function vecmeta.__sub(a,b)
	return vec(a.x-b.x, a.y-b.y)
end
function vecmeta.__mul(a,b)
	return vec(a.x*b, a.y*b)
end
function vecmeta.__div(a,b)
	return vec(a.x/b, a.y/b)
end
local function dot(a,b)
	return a.x*b.x + a.y*b.y
end
local function left(a)
	return vec(-a.y, a.x)
end
local function project(a, nx,ny)
	return vec(dot(a,nx), dot(a,ny))
end
local function unproject(a, nx,ny)
	return nx*a.x + ny*a.y
end

local radius = 10
local velocity = 1
local baseacceleration = velocity*velocity/radius
local pos = vec(-radius, 0)
local vel = vec(0, velocity)

local posreg_int = vec(0,0)
local velreg_int = vec(0,0)

for i = 1, 30 do
	local posabs = math.sqrt(dot(pos,pos))
	local cdir = pos/posabs
	local ndir = left(cdir)
	local poscn = vec(posabs, 0)
	local velcn = project(vel, cdir,ndir)
	local poscn_target = vec(radius, 0)
	local poscn_err = poscn_target - poscn
	posreg_int = posreg_int + poscn_err
	local velcn_target = vec(0, velocity) + poscn_err * 0.4 + posreg_int * 0.0
	local velcn_err = velcn_target - velcn
	velreg_int = velreg_int + velcn_err
	local acccn = vec(baseacceleration, 0) + velcn_err * 0.4 + velreg_int * 0.0
	local acc = unproject(acccn, cdir,ndir)
	vel = vel + acc
	pos = pos + vel

	local r = math.sqrt(dot(pos,pos))
	local phi = math.atan2(pos.y, pos.x)
	-- print(r,phi)
  print(tostring(velcn))
end