Elastically simulating a string

Started by
7 comments, last by Mordoch Bob 22 years, 2 months ago
I need to simulate a string which is anchored at one end, which is a constantly moving point. The simulation works, except for a fairly annoying problem: the string grows. As far as I can figure out, what happens is that the dual forces of gravity and the one anchored end pull the nodes apart to the point where they are equally stretched out, making each node more or less stable at some point ten or so times further away from its neighbors. I have used a 2D version of this to simulate water before, and to combat this particular problem I used artificial anchors for each node to keep it in place. However, given that the string is constantly moving, it''s not possible to define any point to keep the points on the string. So, is there some method for combatting this that I''m unaware of or is this unavoidable? ------------------------------------------------ The wind shear alone from a pink golfball can take the head off a 90-pound midget from 300 yards. -Six String Samurai
_________________________________________________________________________________The wind shear alone from a pink golfball can take the head off a 90-pound midget from 300 yards.-Six String Samurai
Advertisement
Can you pretend that it''s a spring? In such a case, you can just use F=-kx (Hooke''s Law) for your force equation and draw the spring out like you would a spring.
Mordoch,

Are you doing numerical integration for your simulation, e.g., using something like Euler''s method to update at each frame/time step?

If so, the problem you describe sounds like a type of numerical error called "dissipation." Which actually refers to growth or decay of errors in the magnitude of a result. The correct length is constant, while the numerical length grows and so the error grows. This type of error is extremely common when using very simple integration methods such as simple Euler. Euler, in particular, does not work very well at all when you have vibrations such as the string movement you describe.

yellowjon''s proposed solution, using Hooke''s law as a closed form solution, may work as a replacement for numerical integration. Another approach is to use a different integration scheme. The Runge-Kutta schemes (not necessarily 4th order) handles vibrations much much better than Euler''s method, and would exhibit less dissipation error.

If you''re unsure what I mean by simple Euler or Runge Kutta, check the archives. There were a number of prior discussions of these methods.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
Two bits of clarification:
I am not using computational methods to do this, I''m just iteratively computing the shape of the string according to Hooke''s law. Unfortunately, for some reason that is not working, and I''m getting the problems I listed above. I''ve tried increasing k to the point where it is too stiff to expand, but given that the top of the string is getting thrown around continuously that makes it exceedingly unstable and prone to going way off into the distance. So, given that this is simply being computed iteratively, do you have any idea what I''m facing here?

------------------------------------------------
The wind shear alone from a pink golfball can take the head off a 90-pound midget from 300 yards.

-Six String Samurai
_________________________________________________________________________________The wind shear alone from a pink golfball can take the head off a 90-pound midget from 300 yards.-Six String Samurai
Hi,

I remember reading on some forum here about a method to solve these kinds of problems (forgot the name of this method). I have not done this myself, but basically what you do is, at each frame, simply force the two end of the string to their correct position. Then, if the length of the string is too long now, shorten the string to the correct lenght by moving both ends towards each other by the same amount ((cur_distance - string_length)/2), so that the lenght is correct again. Over a couple of frames, the string will correct itself, and there is no instability. Also, you need to move whatever free object is tied to the end of the string to where the new string end position is, or something along those lines.

I think it''s basically a spring with zero damping, or something.

I''d be curious to know if something like that works. Let us know.

SS
SS
If what you are trying to do is simulate a piece of string hanging from a fixed point - where this anchor point is moving with time - then you don't need Hooke's Law.

What you can do is simulate the string as a set of pin-joined beams. When the anchor point moves, this applies a translational and possibly rotational force (moment) on the first beam. This affect is translated through all pins using basic statics equations. Gravity also acts on all beams uniformly downward. Resolving all forces on the beams in this way will enable you to work out velocities of beams/pins and hence simulate your string.

The difficulty with doing this is that you need to solve for an equilibrium condition over the entire set of beams. This is why some people utilise springs between beams instead of pins. You can get away with a little bit of stretch that helps to ease the numerical complexity of the problem. The problem as you have found is that numerical error will creep in to stretch the springs to an equilibrium position.

If you want to implement the pinned beam system, I suggest you start out with a simpler problem to get your algorithm working. Consider a two segment beam. One end of the first beam is anchored to an overhead point that oscillates in the x dimension according to some function. The second beam hangs from the bottom of the first beam. If you can solve for the (x,y) coordinates of the interface pin and the end of the second beam, then you can easily extend the method to n beam segments.

This is a standard undergraduate engineering mathematics problem. You should find reference to it (or similar problems) in introductory statics books (no, not statistics, statics!).

If you want a more challenging problem, invert it (so that the beams now stand above a surface) to find the oscillating function needed to balance a two segment beam anchored to a rolling trolley on the ground!

Good luck,

Timkin

Edited by - Timkin on February 27, 2002 11:17:48 PM
Timkin, I know that the better way would be to have a collection of hinged pins, but I was just trying to get away with using a method that''s a bit simpler. If I get around to it, I might try coding something like that up, but for now I''m sticking to finding a workaround for the problems inherent to the Hooke''s law approach. However, I''m glad to know that the problem *is* inherent to the approach and not just some bug in my program.

In answer to Axter''s post, the method you describe was pretty much what I first tried doing when I encountered this problem. What I found, however, was that I could only retain stability if I reduced the length to something like 99.9% of its original length, and even that wonked out on me sometimes. The problem is that whenever you reduce the length between two points, you increase the distance between those points and their other neighbors. And even though you reduce the distance there as well, an extra little jump is propagated through the string, and as these little jumps keep occurring, the string goes haywire and the strings go off to that small little graveyard in the computer known as "infinity." I imagine that if the technique you describe was actually given a name, it probably was fairly effective, and therefore had a workaround for this problem. Unfortunately, I have no idea what that workaround would be, and if you could inform me I''d be happy to try it out.

Anyway, I''ve just decided to deal with the problem as it stands, and limit the length of the string by controlling the number of nodes within the string. It''s not an idea solution, but it works and the whole string thing just isn''t important enough to warrant that much more concern. Thanks for all your help.

------------------------------------------------
The wind shear alone from a pink golfball can take the head off a 90-pound midget from 300 yards.

-Six String Samurai
_________________________________________________________________________________The wind shear alone from a pink golfball can take the head off a 90-pound midget from 300 yards.-Six String Samurai
Increase the number of iterations. It should be that simple.

Forgive me if im wrong, but from the problems you describe, thats all thats overlooked. You dont have to know the names of or how to apply different integration techniques. Just visualise.

To make it more tensile, less elastic/stretchy, and reduce the errors vastly, you should just give more time to the simulation (increase iterations), increasing its precision, apparently speeding up the interactions. Instead of just tweaking the magnitude of energy transfered. This has the effect of changing the properties of the string (decreasing its elasticity). So you would need to define the elasticity of the string, then divide it down by the number of iters for working. So really increasing the number of iterations just enables you to to increase the tensility/stiffness without experiencing the great mess of what GRhodes describes (i think).

I would interpolate the movements of the anchor/control point over that time as well.
I think the motion of the string will always degrade no matter how precise the simulation, how much you slow it down, thats entropy for ya. The energy you put in should mostly still be there though.
If you dont want that kind of energy left in the system, with the nodes chaotically twitching and vibrating you can add in absorption. Simply using part of the potential energy for displacement instead of momentum will work. So that the ''collision'' energy isnt all carried over into the velocity, and will quickly be dampened/absorbed/whatever, leaving mostly the rotational part. The energy in the string will decrease though, but its just as if its been dissipated as sound or heat etc.

Appologies if ive totally missed the point, or sounded patronising. I just thought the prob was a lot simpler than the way everyone else put it.

P.S. I remember a strange effect, that when a string is vibrating a lot (no dampening) it appears to become stiff (like a springy wire), and able to stand up against gravity etc. I would have thought the opposite, in that it would bunch up into a mess. Can anyone explain why? is there any info on this anywhere? Id love to know if its something real or just a programme artifact. Thanks.
There is something to what you say, but there''s one problem: it becomes much less string-like. I messed around a bit with increased iterations and the like, but the problem is that everything gets propagated through the string that much faster than it really should, and it just looks too stiff. However, it *does* help certain stability issues. But there''s one thing you should always remember, which is that no matter how what you do, there will always be a case where everything destabilizes. I''ll explore the usage of Runge-Kutta integration next time around, but I''m not sure when the next time I''ll need to simulate a string will be. I''d like to thank everyone for their suggestions along they way, because they did actually help a bit along the way.


------------------------------------------------
The wind shear alone from a pink golfball can take the head off a 90-pound midget from 300 yards.

-Six String Samurai
_________________________________________________________________________________The wind shear alone from a pink golfball can take the head off a 90-pound midget from 300 yards.-Six String Samurai

This topic is closed to new replies.

Advertisement