Skip to content

Commit

Permalink
fixed freefall by removing unused "feelslike" calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
nfearnley committed May 27, 2024
1 parent 2cc51ad commit 54cecb7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 17 deletions.
2 changes: 1 addition & 1 deletion sizebot/cogs/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ async def fall(self, ctx: BotContext, distance: MemberOrFakeOrSize):
userdata = userdb.load(ctx.guild.id, ctx.author.id)
basemass = userdata.baseweight
scale = userdata.scale
time, vm, fl = freefall(basemass, distance, scale)
time, vm = freefall(basemass, distance, scale)
ftime = pretty_time_delta(time, millisecondAccuracy = True, roundeventually = True)

await ctx.send(f"You fell **{distance:,.3mu}** in **{ftime}**!\n"
Expand Down
16 changes: 2 additions & 14 deletions sizebot/lib/freefall.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sizebot.lib.units import TV, WV, SV


def freefall(basemass: WV, altitude: SV, scale: Decimal) -> Tuple[Decimal, Decimal, Decimal]:
def freefall(basemass: WV, altitude: SV, scale: Decimal) -> Tuple[Decimal, Decimal]:
"""
If dropped, how long does it take for person to hit ground
Expand All @@ -17,7 +17,6 @@ def freefall(basemass: WV, altitude: SV, scale: Decimal) -> Tuple[Decimal, Decim
returns tuple of:
Time of fall (secs)
Maximum velocity (m/s)
Terminal velocity (m/s)
"""
basemass = basemass / Decimal(1000)
m = basemass * (scale ** Decimal(3))
Expand All @@ -28,15 +27,7 @@ def freefall(basemass: WV, altitude: SV, scale: Decimal) -> Tuple[Decimal, Decim
t = Decimal(math.sqrt(m / (g * k))) * Decimal(math.acosh(Decimal(math.exp(h * k / m))))
vel = Decimal(math.sqrt(g * m / k)) * Decimal(math.tanh(t * Decimal(math.sqrt(g * k / m))))

# calculate feelslike
TWENTY_FIVE_SIXTHS = Decimal(25) / Decimal(6)
step2 = Decimal(math.sqrt(Decimal(1) / basemass))
step3 = Decimal(math.sqrt(basemass))
step4 = Decimal(math.atanh((Decimal("0.156436") * vel) / Decimal(math.sqrt(basemass))))
step5 = -Decimal(math.cosh(step2 * step3 * step4))
feelslike = m * Decimal(math.log(Decimal(math.pow(-step5, TWENTY_FIVE_SIXTHS))))

return TV(t), SV(vel), SV(feelslike)
return TV(t), SV(vel)

# https://www.omnicalculator.com/physics/free-fall-air-resistance#how-to-calculate-air-resistance
# If dropped, how long does it take for person to hit ground
Expand All @@ -59,10 +50,7 @@ def freefall(basemass: WV, altitude: SV, scale: Decimal) -> Tuple[Decimal, Decim
# OUT
# t Time of fall ? sec
# vel Maximum velocity ? m/s
# vmax Terminal Velocity ? m/s
#
# g = 9.807
# t = sqrt(m/(g*k))*acosh(exp(h*k/m))
# vel = sqrt(g*m/k)*tanh(t*sqrt(g*k/m))
# vmax = sqrt(g*m/k)
# feelslike = m * log(-(-cosh(sqrt(1/m) * sqrt(m) * atanh((0.156436 * v)/sqrt(m))))**(25/6))
3 changes: 1 addition & 2 deletions tests/test_freefall.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


def test_freefall_type():
t, vel, feelslike = freefall(Decimal(1), Decimal(1), Decimal(1))
t, vel = freefall(Decimal(1), Decimal(1), Decimal(1))
assert isinstance(t, Decimal)
assert isinstance(vel, Decimal)
assert isinstance(feelslike, Decimal)

0 comments on commit 54cecb7

Please sign in to comment.