This repository has been archived on 2025-02-14. You can view files and clone it, but cannot push or open issues or pull requests.
quack-twn/data/scripts/trig.lua

38 lines
550 B
Lua
Raw Normal View History

2025-02-02 00:26:32 +00:00
local M = {}
function M.v3_length_squared(v)
local x2 = v.x * v.x
local y2 = v.y * v.y
local z2 = v.z * v.z
return x2 + y2 + z2
end
function M.v3_normalized(v)
local length = math.sqrt(M.v3_length_squared(v))
local new_vec = {
x = v.x / length,
y = v.y / length,
z = v.z / length,
}
return new_vec
end
function M.v3_mult(v, f)
return {
x = v.x * f,
y = v.y * f,
z = v.z * f,
}
end
function M.v3_add(v1, v2)
return {
x = v1.x + v2.x,
y = v1.y + v2.y,
z = v1.z + v2.z,
}
end
return M