# pin joints 2D rigid bodys, impulses

## Recommended Posts

I have been wanting to implement pin joints in my own engine for a while, but without needing any great advanced algorithm; I began to work upon a solution myself which seems to work in general, but in certain cases fails and i can't quite understand where the problem is. Modelling the rigid bodies with a linear and angular velocity (v and w) and with a vector from centre of mass to point on body in world space where the pin is (r) with mass and moment of inertia (m and I) i have an impulse (J) calculated that works to make the relative velocity of the two rigid bodies at the pin joint position 0. This seems to work perfectly; and is a unique solution; energy and momentum are conserved perfectly and even in a large chain of bodies pinned together the centre of mass of the system without an external force even if all bodies are spinning around eachover continuse to move in a straight line so all seems to point to it being correct. http://spamtheweb.com/ul/upload/140808/29561_testjoints.php --------- Here the blue plot traces the centre of mass of the system, you can drag objects to apply a force. However, when the system has a constant external force applied, say gravity and i pin one of the bodies in a chain to a static point in the world the pin joints to not seem to work as they should; i.e. the chain will not hang down in a straight line and actually begins to oscillate quite horribly. http://spamtheweb.com/ul/upload/140808/29668_testjoints.php Here air resistance is modelled loosely, and the left most object is pinned to world, if you drag the far right link to the right to model say a strong sideways wind, it does not respond at all how you would expect it to. ------------- Here's my maths work for calculating the impulse which is essentially translated directly into my code http://spamtheweb.com/ul/upload/140808/31800_ew.jpg For moving the objects together i calculate the vector between the two positions on the body where the joint acts and move the objects accordingly to force them together at this point, i do this in an iteration to converge on a result where all bodies are jointed together physically. Anyone have any ideas?

##### Share on other sites
Aressera    2919

The first problem there might be is that your error correcting mechanism might need some work. Do you manually move the objects to force them together at the contact points or do you use some sort of kinematic method (using impulses). This is usually done by applying an impulse at the joint which is proportional to the amount of positional error between the two joint points.

Additionally, you mention that you do iterations for the positional correction, but do you do this also for the constraint impulses (the impulses that satisfy that the relative velocity at the joint is zero)? This is necessary, as you mention for positional error, for constraints between more than two objects.

##### Share on other sites
I am forcing the objects together, and yes the constraint impulses are also done in the iteration.