Created
March 1, 2020 23:24
-
-
Save mugyu/2f0d39b63068c932fd490af5ec6498d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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