Никита Круглицкий 0850d7798b types
2025-06-14 14:21:56 +06:00

36 lines
822 B
Lua

---@class FrictionPresetConfig
---@field B? number
---@field C? number
---@field D? number
---@field E? number
---@class FrictionPreset
---@field B number
---@field C number
---@field D number
---@field E number
local FrictionPreset = class('FrictionPreset')
---@param config FrictionPresetConfig
function FrictionPreset:initialize(config)
config = config or {}
self.B = config.B or 10.86
self.C = config.C or 2.15
self.D = config.D or 0.933
self.E = config.E or 0.992
end
---@param slip number
---@return number
function FrictionPreset:evaluate(slip)
local t = math.abs(slip)
return self.D * math.sin(self.C * math.atan(self.B * t - self.E * (self.B * t - math.atan(self.B * t))))
end
---@type fun(config?: FrictionPresetConfig): FrictionPreset
FrictionPreset.new = FrictionPreset.new
return FrictionPreset