# spring with natural length !=0 [fixed: programmer stupidity]

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

## Recommended Posts

My spring model works with 0 natural length, but when natural length is greater than zero, it comes to rest prematurely. image removed to save bandwidth This was captured after the springs came to rest. Both springs have a natural length of two grid units (1 unit=1 meter). The left spring is attached to the cube's center of mass, so only 1 unit worth is visible.
void Spring::tick(double dt)
{
vector3 dxv=(b->world_position() - a->world_position()); //direction of force on a by b
double dx=dxv.length()-N;
vector3 F = k*dx*Normalized(dxv);

a->F += F;
b->F += -F;
}


where a,b are endpoints (assumably connected to masses), N is natural length, k is spring constant Whats wrong with my source [Edited by - thedustbustr on January 5, 2005 8:08:47 PM]

##### Share on other sites
Code looks fine for what you are doing to me.

Some more info would help. What is the computed length at dxv when it comes to rest. It should obviously be the rest length. If it isn't, then there should be a force, track that force and see why it isn't moving the things. Are there other forces applied (Gravity, damping, etc)? Turn those off.

##### Share on other sites
 I'm being stupid: since gravity is turned off, the spring won't be pulled down. Stupid me =

There is no force (rather, very little, because I'm not cutting the spring off at a certain threshhold). See the second to last line in the screenshot, the force vector is dumped.

There is no gravity or friction, and if I didn't damp accelerations when I integrate them then it would oscillate forever. I damp every acceleration on every object proportional to the object's velocity.

o->a += -0.3 * o->v; //linear energy losso->A += -0.3 * o->w; //rotational energy loss

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 69
• 11
• 10
• 14
• ### Forum Statistics

• Total Topics
632967
• Total Posts
3009570
• ### Who's Online (See full list)

There are no registered users currently online

×