Skip to content

Instantly share code, notes, and snippets.

@mugyu
Created March 1, 2020 23:24
Show Gist options
  • Save mugyu/2f0d39b63068c932fd490af5ec6498d4 to your computer and use it in GitHub Desktop.
Save mugyu/2f0d39b63068c932fd490af5ec6498d4 to your computer and use it in GitHub Desktop.
def lerp(a, b, t)
a * (1 - t) + b * t
end
def inverseLerp(a, b, c)
v = (c - a) / (b - a)
v = 0 if v < 0
v = 1 if v > 1
v
end
# 5から10まで移動するとして
# その工程の20%では何処まで移動したか
p lerp(5.0, 10.0, 0.2)
# 5から10まで移動するとして
# 6まで移動した場合、それは全行程の何割進んだのか
p inverseLerp(5.0, 10.0, 6.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment