simulationphysicsinversekinematics

Balloon string inverse kinematics


I have a simulation where I have balloons bouncing around the screen with a string attached to each one. it functions like a constraint. The string should obey gravity, such that if the balloon isn't max length, there should be slack hanging down.

In order to solve this, I represent the string with line segments. I have the string start hanging straight down, and then iterate over each segment, pointing it to the balloons, and then positioning it so it is connected. This gets the behavior very close to what I want, however in order to make sure that it doesn't leave the center, i translate it back to the place it is rooted in. The problem is that the end no longer is going to be connected. If i didn't have to reset the string to the vertical position this would work, but i have to in order to make sure the slack is calculated.

I added a temporary solution of iterating over it again to reconnect it, and the behavior is decent, but it definitely isn't realistic. An example can be seen here: http://www.mikerkoval.com/simulation/balloons

click to create balloons. I am unsure how to simulate gravity. Is there a better approach to make this more realistic?

-----EDIT----

I am strugglign to get my value solved for a in the catenary function.

I defined my function as:

var k = function (a){
    return Math.pow((2 * a[0]*Math.sinh(h/(2 * a[0])) - sqrt(s*s-   v*v)), 2)
}

however, when I call

var sol = numeric.uncmin(k, [1]);

it runs for a little then throws a Nan error. I am trying to figure out where the problem even is, but I am having very little success since I am struggling to learn what is going on with uncmin


Solution

  • I think what you want is to find the parameters for the catenary curve through two points p0 and p1, the positions of the anchor and balloon, which has given arc length s, which is the length of the string.

    The equation of the curve is

    y = a cosh (x / a)
    

    where a is a parameter you need to determine. Let v = y1 - y0 and h = x1 - h0. With a bit of algebra you can show the value of a must satisfy

    sqrt(s*s - v*v) = 2 * a * sinh(h / (2a))
    

    This article a nice discussion of how to solve this for a iteratively with Newton's method. The author makes a substitution of variables b = a/h that make makes the solution space close to linear, so Newton will converge very quickly to a good answer.

    Newton's method is a simple iteration that requires the explicit derivative of the curve and a starting point. The article above gives the derivative. Because the curve is so close to linear, you can pick any starting point on that linear portion - b = 0.2 will do. By converging quickly, I mean the number of correct significant digits doubles with each iteration. So in practice you're likely to have all the digits of a double precision floating point number in 6 iterations or less.

    Once you have the parameter, it will be a simple patter to plot the explicit curve you need.

    If Newton doesn't converge in 6 iterations or so, then the instance of the problem is a very ill-conditioned one. Here that means a curve that's very nearly a straight line. So just draw such a line between p0 and p1!

    All this should be easily fast enough: less expensive than your current approximation.