Interpolate linear

From Sim Innovations Wiki
Jump to navigation Jump to search

Description

value = interpolate_linear(settings,value)

interpolate_linear is used to interpolate a value with given settings.

Return value

Argument Type Description
value Number Return value, can be nil if given value is outside of settings scope.

Arguments

# Argument Type Description
1 settings Table Interpolate settings. Can be manually created (see example), or created from table user property with interpolate_settings_from_user_prop function.
2 value Number Input value.

Example (manual settings)

-- Create interpolate settings
local settings = { { 0 , 0   },
                   { 10, 100 },
                   { 20, 200 },
                   { 30, 400 } }

-- Interpolate 25 (between 20-30)
local var = interpolate_linear(settings, 25)

-- Will print 300
print(var)

Example (table user property)

-- Create a table with two columns
local val = user_prop_add_table("Needle calibration", "Fill table with calibration data",
                                  "Speed", "DOUBLE", 0, "Fill in the speed of the flight simulator",
                                  "Needle position", "DOUBLE", 0, "Set needle position in steps")

-- Create interpolate settings from user property
local settings = interpolate_settings_from_user_prop(user_prop_get(val))

-- Interpolate using settings made by the user
local var = interpolate_linear(settings, 25)

--Print result
print(var)