# Mass spring system weird integrator

This topic is 3781 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Greetings, I stumbled upon a code segment that implements an integrator for a mass spring system. The code works perfectly and it produces stable results. However I would like to know what is the theory behind this code. Here’s the general algorithm:
// A system is a set of atoms connected by links...
System::Update()
Begin
For (i=0 to rigidity)
l->Update();

For each atom a
a->Snap();
End For

For each atom a
a->Update();
End

Atom::Snap()
begin
Force *= 1/Mass;
Position += Force;
OldPosition += Force * MotionConstant;
Force = Vector();		// Zeros
end

Atom::Update()
begin
Vector newPos = 2 * Position - OldPosition;
newPos.Y += Gravity;

OldPosition = Position;
Position = newPos;
end

begin
// Nothing special, just add some computed values
// to the atoms connected by this link
end


I’m particularly puzzled by this MotionConstant. Also I would like to find out how to make the computations dependent on time. This is a snippet from the source code of Physical. http://www.alecrivers.com/physical/index.htm I studied and understood the whole code, I'm just missing this point :hoping: Edit: I think I made a mistake, snap is called only once after calling links updates. Also forgot to mention the source link :p Thanks Abdo Haji-Ali Programmer In|Framez [modified by grhodes_at_work to make code listing more readable] [Edited by - Abdo Haji-Ali on August 4, 2008 5:00:33 AM]

##### Share on other sites
Quote:
 Original post by Abdo Haji-Ali...I would like to know what is the theory behind this code......I’m particularly puzzled by this MotionConstant......Also I would like to find out how to make the computations dependent on time...

I definitely second that! Very interesting integration setup. Could you perhaps post a more fleshed out / detailed version?

Cheers,
Michael

[Edited by - h4tt3n on August 1, 2008 11:11:06 AM]

##### Share on other sites
Quote:
 Original post by h4tt3nI definitely second that! Very interesting integration setup. Could you perhaps post a more fleshed out / detailed version?

Isn't it? :p I'm really amazed by it's results and simple diagram.
I don't think there're any other details relating to the main integrator. However, I just included the link which I took the algorithm from in my original post. The above code is taken from the two main files: System.cpp and atom.cpp
There are other details concerning collision detection (called repluse fields in this engine) and some sample objects. However, I think this is the main core.

Abdo Haji-Ali
Programmer
In|Framez

PS: I already tried to contact the developer of Physical (Alec Rivers: arr33@cornell.edu). However, I received a message from the mailer-deamon saying that this account is inactive. Sadly enough, Alec doen't mention another way to contact him on his site.

[Edited by - Abdo Haji-Ali on August 2, 2008 4:13:41 AM]

##### Share on other sites
Don't mind the fleshing out :-)

I've found a very similar setup, which supposedly is an avanced version of the verlet integration algo. The one I stumbled across includes an explicit timestep, which I think you were looking for? I wouldn't min posting an example.

btw, shouldn't it be:

System::Update()
Begin
For (i=0 to rigidity)
l->Update();

For each atom a
a->Snap(); <---- change
End For

For each atom a
a->Update();
End

cheers,
Michael

##### Share on other sites
Quote:
 Original post by h4tt3nDon't mind the fleshing out :-)I've found a very similar setup, which supposedly is an avanced version of the verlet integration algo. The one I stumbled across includes an explicit timestep, which I think you were looking for? I wouldn't min posting an example.

Interseting. So you're saying that this algorithm is an advanced version of Verlet integration? That would make sense. Would you please post a link or an example?

Quote:
 Original post by h4tt3nbtw, shouldn't it be:System::Update()Begin For (i=0 to rigidity) For each link l l->Update(); For each atom a a->Snap(); <---- change End For For each atom a a->Update();End

Yep! That's right. This is one of the pitfalls of Ctrl+C/V

Abdo Haji-Ali
Programmer
In|Framez

[Edited by - Abdo Haji-Ali on August 4, 2008 5:59:49 AM]

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633662
• Total Posts
3013231
×