Friday, March 20, 2015

physics - How do I calculate the forces exerted by a taut wire wrapping 2D objects?


Assume I have a physics primitive I am going to call a "wire", wrapped around a 2D environment (as described in this question).


Here's an illustration of what that might look like:


wire wrapped around static and dynamic game objects


In the example illustration: The box is being pulled upwards (held up) by the wire, and the box is pulling the wire downwards. The object on the spring is being pushed downward by the wire, but is also pushing the wire upwards.


While I haven't figured out how to implement it yet, assume the wire will slide freely across the points that it is wrapped around.



In a 2D physics simulation (ie: frame based) how do you calculate the forces (or impulses) to apply to the objects that are attached to or wrapped by a wire like this?




As I alluded to in my first question, I imagine that if the only non-static object "on" the wire was the mass at the end, then the force would be identical to a fixed-length joint between the mass and the point before that on the wire.



Answer



The box pulling on the wire applies a tension to the wire. Tension is a force, measured in Newtons. If we make some simplifying assumptions (no friction between wire and environment) then the tension is the same at all points along the wire.


If we consider your example to be static, then the tension on the wire is just the weight of the box:


T = m * g

where m is the mass of the box and g is acceleration due to gravity (i.e. 9.8 m/s^2). Note this is only valid in the static case, see below for an explanation of how to calculate it in the dynamic case.


The force at each bend in the wire is then just the projection of the tension onto the relevant direction. For example the force at the tip of the spring object is a force along the contact normal, of magnitude:



F = T * cos(angle between wire and contact normal)

In this case the contact normal direction would be the bisection of the angle between the wire segments. The force at your second marked point on the environment is irrelevant, since it has no impact on the tension or anything else.


Now, in the dynamic case the tension is simply the constraint force which you apply to the box in order to keep it attached to the wire. So if the physics engine is impulse based, the tension is just:


T = impulse / timestep

This leads into the general algorithm for wrapping the wire around the environment too. The important property is the total length of the wire. Only the last segment needs to be simulated, all the earlier segments can be considered to be fixed. So the length of the last segment is known, just subtract the lengths of the earlier segments from the total length. Then the last segment can be a simple spring constraint. Then just split a segment whenever it intersects with the environment, and remove the split when the bend straightens out.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...