Advertisement
Geometrian

Snails on a Plane Example Calculation

Mar 18th, 2024 (edited)
753
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.39 KB | Source Code | 0 0
  1. # Example for https://puzzling.stackexchange.com/questions/126002/the-alien-snails-experiment
  2.  
  3.  
  4.  
  5. from math import *
  6.  
  7.  
  8.  
  9. def get_log10_str( log10_val ):
  10.     intpow = floor(log10_val)
  11.     frac = 10**( log10_val - intpow )
  12.     while frac < 1.0:
  13.         frac *= 10
  14.         intpow -= 1
  15.     return f"{frac:.4}∙10^{intpow}"
  16.  
  17.  
  18.  
  19. anne_pos0 = ( 0, 0 )
  20. bill_pos0 = ( 1e12*cos(radians(-24)), 1e12*sin(radians(-24)) )
  21.  
  22. anne_dir = ( 1, 0 )
  23. bill_dir = ( cos(radians(71)), sin(radians(71)) )
  24.  
  25. print("Starting configuration:")
  26. print(f"  Anne pos=⟨ {anne_pos0[0]}, {anne_pos0[1]} ⟩")
  27. print(f"       dir=⟨ {anne_dir[0]}, {anne_dir[1]} ⟩")
  28. print(f"  Bill pos=⟨ {bill_pos0[0]:.3e}, {bill_pos0[1]:.3e} ⟩")
  29. print(f"       dir=⟨ {bill_dir[0]:.4}, {bill_dir[1]:.4} ⟩")
  30. print(f"  Speed (μm/s): {1e6*1/86400:.4}")
  31. print()
  32.  
  33.  
  34.  
  35. #Speed described by 1/t, where t the remaining time, so displacement by
  36. #   \int_x^86400 dt/t = ln(86400)-ln(x) = ln(86400/x)
  37. #For higher precision, if x=c*10^p, then
  38. #                     = ln(86400) - ln(c) + p*ln(10)
  39. #                     = ln(86400/c) + p*ln(10)
  40.  
  41. print("Displacement with time remaining:")
  42. print(f"  t=       60: {log(86400.0/    60.0):.4}")
  43. print(f"  t=       10: {log(86400.0/    10.0):.4}")
  44. print(f"  t=        1: {log(86400.0/     1.0):.4}")
  45. print(f"  t=     1e-3: {log(86400.0/  1.0e-3):.4}")
  46. print(f"  t=   1e-100: {log(86400.0/1.0e-100):.4}")
  47. print(f"  t=1e-100000: {round( log(86400.0/1.0)+100000*log(10) )}")
  48. print()
  49.  
  50.  
  51.  
  52. #Bill crosses x-axis.  The elapsed time is
  53. #   \int_x^86400 dt/t = ln(86400)-ln(x) = `param`
  54.  
  55. param = -bill_pos0[1] / bill_dir[1]
  56. cross_pos = ( bill_pos0[0]+param*bill_dir[0], bill_pos0[1]+param*bill_dir[1] )
  57.  
  58. ln_tc = log(86400) - param
  59. log10_tc = log10(e) * ln_tc
  60.  
  61. print("Bill crosses the x-axis at:")
  62. print(f"  Location      : ⟨ {cross_pos[0]:.3e}, {cross_pos[1]} ⟩")
  63. print(f"  Remaining time: {get_log10_str(log10_tc)}")
  64. print()
  65.  
  66.  
  67.  
  68. #Anne finds trail on x-axis and changes speed to 2/t.  This happens when Anne's displacement is the
  69. #crossing point, so:
  70. #   (cross_pos[0]) = \int_x^86400 dt/t   =>   ln(x) = ln(86400) - (cross_pos[0])
  71.  
  72. ln_t1 = log(86400) - cross_pos[0]
  73. log_t1 = log10(e) * ln_t1
  74.  
  75. dist = cross_pos[0]
  76. anne_pos1 = ( dist, 0 )
  77. bill_pos1 = ( bill_pos0[0]+dist*bill_dir[0], bill_pos0[1]+dist*bill_dir[1] )
  78.  
  79. log_v = log10(2) - ln_t1*log10(e)
  80.  
  81. separation = hypot( anne_pos1[0]-bill_pos1[0], anne_pos1[1]-bill_pos1[1] )
  82.  
  83. print("Anne finds the trail:")
  84. print(f"  Anne's position : ⟨ {anne_pos1[0]:.3e}, {anne_pos1[1]} ⟩")
  85. print(f"  Bill's position : ⟨ {bill_pos1[0]:.3e}, {bill_pos1[1]:.3e} ⟩")
  86. print(f"  Separation      : {separation:.3e}")
  87. print(f"  Remaining time  : {get_log10_str(log_t1)}")
  88. print(f"  Anne's new speed: {get_log10_str(log_v)}") #the effect of the 2 is not visible at this scale
  89. print()
  90.  
  91.  
  92.  
  93. #The relative speed of Anne and Bill is -1/t.  They intersect when that speed removes the distance
  94. #between them.  That is:
  95. #   \int_x^exp(`ln_t`) -dt/t = -`separation`
  96.  
  97. ln_t2 = ln_t1 - separation
  98. log_t2 = log10(e) * ln_t2
  99.  
  100. log_relvel_by_c = log10(e)*( separation - ln_t1 - log(299792458) )
  101.  
  102. param = log(86400) - log_t2
  103. pos2 = ( bill_pos0[0]+param*bill_dir[0], bill_pos0[1]+param*bill_dir[1] )
  104.  
  105. print("Meetup:")
  106. print(f"  Position      : ⟨ {pos2[0]:.3e}, {pos2[1]:.3e} ⟩")
  107. print(f"  Remaining time: {get_log10_str(log_t2)}")
  108. print(f"  Relative speed: {get_log10_str(log_relvel_by_c)} ⨯ c")
  109. print()
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement