-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.lua
More file actions
39 lines (32 loc) · 1.37 KB
/
helper.lua
File metadata and controls
39 lines (32 loc) · 1.37 KB
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
local matrix = require "matrix"
local complex = require "complex"
local R = {}
function R.checkbounce(body)
-- Make sure body has attributes [position, velocity, radius]
local x,y,z = body.position:getelement(1,1), body.position:getelement(2,1), body.position:getelement(3,1)
local vx,vy,vz = body.velocity:getelement(1,1), body.velocity:getelement(2,1), body.velocity:getelement(3,1)
local radius = body.radius
if (x+radius > 0.5 and vx > 0) or (x-radius < -0.5 and vx < 0) then
-- vx = -vx
body.velocity:setelement(1,1,-vx)
elseif (y+radius > 0.5 and vy > 0) or (y-radius < -0.5 and vy < 0) then
-- vy = -vy
body.velocity:setelement(2,1,-vy)
elseif (z+radius > 0.5 and vz > 0) or (z-radius < -0.5 and vz < 0) then
-- vz = -vz
body.velocity:setelement(3,1,-vz)
end
end
function R.vectortomultivector(vector)
sigma_1 = matrix{{0,1},{1,0}};
sigma_2 = matrix{{0,"-i"},{"i",0}}:replace(complex)
sigma_3 = matrix{{1,0},{0,-1}}
return sigma_1 * vector:getelement(1,1) + sigma_2 * vector:getelement(2,1) + sigma_3 * vector:getelement(3,1)
end
function R.multivectortovector(multivector)
a,_ = ((multivector:getelement(1,2)+multivector:getelement(2,1))/2):get()
_,b = ((multivector:getelement(2,1)-multivector:getelement(1,2))/2):get()
c,_ = ((multivector:getelement(1,1)-multivector:getelement(2,2))/2):get()
return matrix{a,b,c}
end
return R