2

I'm using pymunk to apply forces to a circular body at the ends of its diameter. The forces are of different magnitudes, and neither has an x-component (relative to the body, that is, so they are perpendicular to the diameter). I would expect these forces together to rotate the body to some degree, but instead they just add together to create a force vector with no x-component and a y-component (so, again, perpendicular to the diameter) that is just a combination of the magnitudes of both forces.

Is pymunk just unable to calculate the resultant rotation from multiple forces applied at separate points on a body? Since that is the only reason I'm even using a physics engine at all, I would be extremely disappointed if that were the case. I would appreciate any help with this problem. Thank you in advance.

desophos
  • 207
  • 1
  • 9

1 Answers1

1

pymunk should be able to calculate the rotation unless I misunderstand the question. Check this example:

>>> b = Body(1,100)
>>> c = Circle(b,10)
>>> s.add(b,c)
>>> b.apply_impulse((100,0), (0,10))
>>> b.apply_impulse((-50,0), (0,-10))
>>> s.step(.1)
>>> b.angle
-1.5
>>> b.position
Vec2d(5.0, 0.0)
>>> s.step(.1)
>>> b.angle
-3.0
>>> b.position
Vec2d(10.0, 0.0)
viblo
  • 4,159
  • 4
  • 20
  • 28
  • But if I use one impulse with force (100,0) and the other with force (50,0), will the circle move and turn at the same time? It appears in my simulation that that is not the case, unless there is something wrong with my application of forces. Do I need to break down each force into its world-relative x and y components? I thought that I could just apply each force at each end of the circle's diameter and as the circle turned, the forces would continue to apply as relative to the body (I calculate the locations of the ends of the diameter each step). – desophos Dec 10 '12 at 05:55
  • 1
    I changed the example a little bit.. but if you dont get it to work then I suggest you create a minimal example and paste here – viblo Dec 10 '12 at 13:46
  • Ah, this example illustrates my question exactly. You apply different impulses to the ends of a diameter, but instead of the body being pushed in a circle, it just rotates and moves along the x-axis. Shouldn't it move in a circular pattern, with movement along both the x- and y-axis? – desophos Dec 10 '12 at 17:16
  • 1
    Ah, now I understand what you think should happen! :) I think it should move in x only. Take a look here: http://physics.stackexchange.com/questions/29122/motion-of-a-rod-struck-at-one-end – viblo Dec 11 '12 at 22:59
  • What I'm actually doing is constantly applying forces and changing them dynamically, but you helped me realize what was going wrong. I did fix it and I've completed my work with pymunk thanks to your pushes in the right direction. Thank you! – desophos Dec 12 '12 at 22:46