This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

FB Editor
#8
The adapted script, where in both versions the X is input (outdoor air temperature for example) and the calculated Y is output.

--- [Function] fbe_curve_2pt
--- Curve function with 2 points
--- [Comment]
--- Depending on a straight line defined by 2 points, this module supplies a y-value for an x-value.
--- The first point of the straight line is defined by x1 and y1.
--- The second point of the straight line is defined by x2 and y2.
--- If x is less than x1, then y=y1.
--- If x is greater than x2, then y=y2.
--- Only strictly monotone rising or falling functions can be realised. This means x1 < x2.
--- [Input]
--- Input [value, object, storage]
--- X1 [value, object, storage]
--- Y1 [value, object, storage]
--- X2 [value, object, storage]
--- Y2 [value, object, storage]
--- [Output]
--- out - Output [object, storage]
function fbe_curve_2pt(input, x1, y1, x2, y2)
if input <= x1 then
return y1
elseif input >= x2 then
return y2
end
local n1, n2 = y2 - y1, x1 - x2
if n1 < 0 then
n1 = n1 * -1
n2 = n2 * -1
end
local c = -n1 * x1 - n2 * y1
return (-n1 * input - c) / n2
end

--- [Function] fbe_curve_2pt_offset
--- Curve function with 2 points and offset
--- [Comment]
--- Depending on straight lines defined by 2 points, this module supplies an x-value for a y-value.
--- The first point of the straight line is defined by x1 and y1.
--- The second point of the straight line is defined by x2 and y2.
--- The x and the y-axis can be shifted by the respective offset.
--- If x is less than (x1 offset x), then y=y1.
--- If x is greater than (x2 offset x), then y=y2.
--- [Input]
--- Input [object, storage]
--- X1 [value, object, storage]
--- Y1 [value, object, storage]
--- X2 [value, object, storage]
--- Y2 [value, object, storage]
--- Offset X [value, object, storage]
--- Offset Y [value, object, storage]
--- [Output]
--- out - Output [object, storage]
function fbe_curve_2pt_offset(input, x1, y1, x2, y2, offsetX, offsetY)
if input <= (x1 + offsetX) then
return y1
elseif input >= (x2 + offsetX) then
return y2
end
local n1, n2 = y2 - y1, x1 - x2
if n1 < 0 then
n1 = n1 * -1
n2 = n2 * -1
end
local c = -n1 * (x1 + offsetX) - n2 * (y1 + offsetY)
return (-n1 * input - c) / n2
end
Reply


Messages In This Thread
FB Editor - by KoBra - 12.01.2021, 10:38
RE: FB Editor - by Daniel - 12.01.2021, 10:50
RE: FB Editor - by KoBra - 12.01.2021, 12:20
RE: FB Editor - by Daniel - 12.01.2021, 12:23
RE: FB Editor - by KoBra - 13.01.2021, 09:15
RE: FB Editor - by Daniel - 14.01.2021, 10:46
RE: FB Editor - by KoBra - 14.01.2021, 11:44
RE: FB Editor - by KoBra - 14.01.2021, 12:53

Forum Jump: