04.12.2018, 13:45
Hello.
You can try this:
You can try this:
Code:
function linear_by_table(input,curve,offset)
local FDY = offset or 0
fk1= (curve["y"][1] - curve["y"][2]) / (curve["x"][1] - curve["x"][2])
fk2= (curve["y"][2] - curve["y"][3]) / (curve["x"][2] - curve["x"][3])
fk3= (curve["y"][3] - curve["y"][4]) / (curve["x"][3] - curve["x"][4])
if input < curve["x"][1] then
out = curve["y"][1] + FDY;
elseif input >= curve["x"][1] and input < curve["x"][2] then
out = fk1 * (input - curve["x"][1]) + curve["y"][1] + FDY
elseif input >= curve["x"][2] and input < curve["x"][3] then
out = fk2 * (input - curve["x"][2]) + curve["y"][2] + FDY
elseif input >= curve["x"][3] and input < curve["x"][4] then
out = fk3 * (input - curve["x"][3]) + curve["y"][3] + FDY
else
out = curve["y"][4] + FDY
end
return out
end
curve = {}
curve["x"] = {-20,-10,0,20}
curve["y"] = {80,70,65,18}
--offset=2
--log(linear_by_table(20,curve,offset))
log(linear_by_table(-15,curve))