[ODE] how do I do to simulate a damper with a slider?

Jeffrey Smith jeffreys at Softimage.com
Tue Dec 9 10:37:26 MST 2003


> how do I do to simulate a damper with a slider? 

I assume what you want is a spring/damper system, attached to the slider.
The equation for this is fairly simple:

 Fa = [ ks( LENGTH(l) - r) + kd( DOT( l_vel, l) / LENGTH(l))] * l / LENGTH(l)

where "Fa" is the force the spring is exerting on object "a". (similarly,
"Fb = -Fa"),  "ks" is the spring constant, "kd" is the damping constant,
"l" is the vector distance between object "a" and "b", "r" is the rest
length (a scalar), "l_vel" is the rate of change of the vector
distance between objects "a" and "b" (i.e. the first time derivative
of "l").  "LENGTH" merely takes the scalar magnitude of a vector, and
"DOT" is a dot-product function.

In pseudo-code, it would be something like:

    Vector3 spring_axis;
    GET_SPRING_AXIS( Body1, Body2, spring_axis);

    Vector3 spring_velocity;
    GET_SPRING_VELOCITY( Body1, Body2, spring_velocity);
    
    double Fs, Fd;
    Fs = Ks*(spring_axis.length() - rest_length);
    Fd = Kd*DOT(spring_velocity, spring_axis) / spring_axis.length();
    
    double   Ftemp;
    Vector3 Fa;
    Ftemp = (Fs + Fd) / spring_axis.length();

    for (int i=0; i<3; i++)
        Fa[i] = Ftemp*spring_axis[i];

    dBodyAddForce(Body1, (dReal) Fa[0], (dReal) Fa[1], (dReal) Fa[2]);
    dBodyAddForce(Body2, (dReal) -Fa[0], (dReal) -Fa[1], (dReal) -Fa[2]);


Where Vector3 is some 3-vector class, and GET_SPRING_AXIS() and
GET_SPRING_VELOCITY() are appropriately defined functions.

Jeff



More information about the ODE mailing list