-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmathex.lua
More file actions
39 lines (33 loc) · 728 Bytes
/
mathex.lua
File metadata and controls
39 lines (33 loc) · 728 Bytes
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
function vec2angle(x, y)
return math.atan2(y, x)
end
function vec2length(x, y)
return math.sqrt(x*x + y*y)
end
function vec2normalize(x, y)
local length = vec2length(x, y)
return x/length, y/length
end
function vec2scale(x, y, factor)
return x*factor, y*factor
end
function vec2rotate(x, y, angle)
local sin = math.sin(angle)
local cos = math.cos(angle)
local tx = x
local ty = y
x = (cos * tx) - (sin * ty)
y = (sin * tx) + (cos * ty)
return x, y
end
function clamp(value, lower, upper)
if value > upper then
value = upper
elseif value < lower then
value = lower
end
return value
end
function pointBoxIntersection(x, y, bx, by, bw, bh)
return x >= bx and x <= bx + bw and y >= by and y <= by + bh
end