I am interested in simulating a sort of rod-pendulum system:
from intro import pymunk, space, App
import pygame
from pymunk.vec2d import Vec2d
pygame.init()
b0 = space.static_body #declare a universe
b1 = pymunk.Body(mass=1000, moment=10)
b1.position = (240, 200)
c1 = pymunk.Segment(b1, (0, -40), (0, 40), 6)
c1.elasticity = 0.1
space.add(b1, c1)
b2 = pymunk.Body(mass=.1, moment=1)
b2.position = (240, 100)
c2 = pymunk.Segment(b2, (0, 0), (0, -40), 6)
c2.elasticity = 0.1
space.add(b2, c2)
j1 = pymunk.constraints.PinJoint(b0, b1, (240, 200), (0,0))
j2 = pymunk.constraints.PinJoint(b2, b1, (0, 0),(0,-40))
space.add(j1, j2)
b1.torque = 4000
space.gravity = 0,0 #gx , gy
print(b1.position, b1.velocity)
App().run()
print(b1.position, b1.velocity)
But it is not operating as I would expect.
- I have a set torque on the main rod. I would assume that the system left alone should slowly speed up over time. I am not seeing that.
- The secondary rod does not seem to be feeling a centripetal acceleration. I would think that as it is swung around , it would want to point outwards. I think this has to do with how the simulated mass is distributed. Would I need to turn the secondary rod into a series of masses, or is there an easier way to move the center of mass?
- I can change the mass ratio of the main rod vs the secondary rod. I would assume when M1>>M2 that the system would just spin in circles as if there were no secondary rod. But I am not seeing that, instead the main rod oscillates as if it were transferring a substantial amount of angular momentum to the secondary rod. Am I missing something?
- Is pymunk even supposed to be a reliable physics simulator? or is it just approximating something to physics, just good enough to be part of a game?
- Is there a python based physics simulator that you would recommend for a system like this one. Eventually I would like to be able to model the oscillations through variable torque and with drag, all while recording the forces on the system.