Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tarapov_page_57_5_springs.py
- # 19_09_21
- '''
- Vector and Tensor Analysis with Applications
- Borisenko, Tarapov, Silverman
- Exercise 21, page 57
- "...springs that have relaxed lengths of zero":
- Introduction to Classical Mechanics
- by David Morin (2017), p. 124
- Classical Mechanics with Calculus of Variations...
- by Mark Levi (2014), pp. 126-127
- p. 126
- "linear zero length spring"
- p. 127
- "...the moment of inertia can be interpreted as the potential
- energy of a set of linear zero length springs." #todo
- Morin p. 690
- F = ma vs. F = dp/dt
- F("system") = dp/dt
- = m(dv/dt) + v(dm/dt)
- cf. "The Momentum Principle"
- Matter & Interactions (2007)
- by Chabay, Sherwood, pp.45-
- '''
- from vpython import *
- import sys
- def main():
- scene.width, scene.height = 1000, 800
- scene.background = color.black
- scene.align = 'left'
- scene.autoscale = False
- scene.autozoom = False
- scene.userspin = True
- scene.userzoom = True
- scene.userpan = True
- scene.resizable = False
- scene.center = vec(0,0,0)
- scene.range = 1.7
- RATE = 200
- PAUSED_AT_START = 0
- RANDOM_K = 0
- # Fdrag = -DRAG_CONSTANT * p
- DRAG_CONSTANT = 0.6
- if 1:
- N = 5
- L = [vec(-0.3, 0.6, 0),
- vec(0.8, 0.9, 0),
- vec(1.2, 0, 0),
- vec(0.7, -1, 0),
- vec(-0.6, -1, 0)]
- else:
- N = 12
- L = []
- v = vec(1,0,0)
- L.append(v)
- for _ in range(N-1):
- v = v.rotate(radians(360./N), vec(0,0,1))
- # ~ v.rotate_in_place(radians(360./N), vec(0,0,1))
- L.append(v)
- # CENTER MASS, M
- x = -1.0 + 2.0*random()
- y = -1.0 + 2.0*random()
- M = sphere(pos=vec(x,y,0), radius=0.05, color=vec(1,0,0))
- M.p = vec(0,0,0)
- M.mass = 1.0
- # MIRROR MASS, M2
- dx = 1.7
- M2 = simple_sphere(pos=M.pos - vec(dx,0,0), radius=0.007,
- color=vec(1,0,0), make_trail = 1, trail_radius=0.004)
- # INITIALIZE MASS SPRING SYSTEM
- points = []
- for i in range(N):
- point = simple_sphere(pos=L[i], radius=0.02, color=vec(1,1,1))
- point.m = 1.0
- points.append(point)
- springs = []
- for i in range(N):
- spring = helix(pos=M.pos, axis=points[i].pos - M.pos,
- coils=18, radius=0.02, thickness=0.005, opacity=0.7)
- if RANDOM_K:
- spring.k = random() * 2.0
- else:
- spring.k = 2.0
- spring.L0 = 0.0 # "zero-length spring"
- springs.append(spring)
- '''
- CALCULATE EQUILIBRIUM POSITION OF M
- ===================================
- This formula is accurate only for springs
- that have "relaxed lengths of zero" (Morin)
- Formula from:
- Vector and Tensor Analysis with Applications
- Borisenko, Tarapov, Silverman
- Exercise 21, page 57
- This formula is analogous to the Center of Mass
- formula (substituting m for k)
- '''
- R = vec(0.,0.,0.)
- K = 0.
- for i in range(N):
- k = springs[i].k
- R += k * points[i].pos
- K += k
- R /= K
- sphere(pos=R, radius=0.02, color=color.green)
- def pause_run():
- g.paused = not g.paused
- pause.text=' RUN ' if g.paused else 'PAUSE'
- scene.append_to_caption('\n ')
- pause = button(bind=pause_run)
- g.paused = not PAUSED_AT_START
- pause_run()
- def key(e):
- s = e.key
- if s in [' ', '\n']: pause_run()
- scene.bind('keydown', key)
- # IMPART SOME INITIAL MOMENTUM
- M.p = vec(0.5, 0.5,0)
- t = 0
- dt = 0.002
- while t < 30:
- rate(RATE)
- if g.paused: continue
- for i in range(N):
- r = M.pos - points[i].pos
- Fs = -springs[i].k * (r.mag - springs[i].L0) * r.hat
- Fdrag = -DRAG_CONSTANT * M.p
- M.p += (Fs + Fdrag) * dt
- M.pos += M.p / M.mass * dt
- springs[i].pos = M.pos
- springs[i].axis = points[i].pos - M.pos
- M2.pos = M.pos - vec(dx, 0, 0)
- t += dt
- print()
- s1 = ' Predicted Equilibrium point: '
- s2 = ' Actual Equilibrium point: '
- print(s1, R)
- print(s2, M.pos)
- scene.append_to_caption('\n\n')
- scene.append_to_caption(s1 + str(R) + '\n')
- scene.append_to_caption('\n')
- scene.append_to_caption(s2 + ' ' + str(M.pos) + '\n')
- class g: ...
- if __name__ == '__main__':
- sys.exit(main())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement