Skip to content

kylemathenia/rope_sim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rope_sim

A readable rope simulation class I made from scratch in python. Cheers.

Parameters:

  • fixed or constrained tail
  • Verlet or Euler integration
  • spring constant
  • viscous damping constant
  • drag coefficient
  • number of points
  • unstretched length
  • gravity value
# Springy
rope = Rope(k=5, c=10, start_pos=[0, 10], end_pos=[20, 10], num_pts=16, unstretched_len=15, fixed_tail=False, drag_coef=100)
rope.sim(num_steps=1000,step_size=0.05)

springy

# More damping and drag
rope.c = 100
rope.drag_coef = 1000

damped

# Update start and end points and step manually. Step size can vary in size between steps, which may be useful for real-time loops.
rope = Rope(k=5, c=20, start_pos=[0, 10], end_pos=[20, 0], num_pts=16, unstretched_len=10, fixed_tail=True, drag_coef=50)
num_steps, step_size = 1000, 0.05
for i in range(num_steps):
    rope.update_first_pt([15* math.sin(i/40),10* math.sin(i/15) + 10])
    rope.update_last_pt([20, 20 * math.sin(i / 60)])
    rope.step(step_size)

both_moving

# Other demos:

head_moving constrained

Optionally, use Euler integration and observe numerical instability!

rope = Rope(k=2, c=0, start_pos=[0, 20], end_pos=[20, 10], num_pts=8, unstretched_len=15, integration_method='euler', drag_coef=0.005)
rope.sim(num_steps=300,step_size=0.05)

euler_instability

About

A rope simulation class in Python

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages