# Daft question spring physics,

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

## Recommended Posts

Sorry my understanding of maths is pritty bad ive stumbled into this im basically just trying to get a rope to display on the screen but this equation has me baffled, I do this for x y z, ForceA.x = -r->ks * ( sqrt(pow(Lx, 2) ) - r->r) + (r->kd * ((Ldotx * Lx) / sqrt(pow(Lx, 2))) ) * ( Lx / sqrt(pow(Lx, 2)) ); I dont think im working out this equation properly because at the moment the velocitys are crazy numbers -2000 etc =/ This is what i do for all the particles,
 r->kd = 0.2;
r->ks = 500;
r->r = 0.05;

for(num particles do, j++)
Lx = r->P[j].Pos.x - r->P[j+1].Pos.x;
Ly = r->P[j].Pos.y - r->P[j+1].Pos.y;
Lz = r->P[j].Pos.z - r->P[j+1].Pos.z;

Ldotx = r->P[j].Vel.x - r->P[j+1].Vel.x;
Ldoty = r->P[j].Vel.y - r->P[j+1].Vel.y;
Ldotz = r->P[j].Vel.z - r->P[j+1].Vel.z;

if(Lx != 0)
ForceA.x = -r->ks * ( sqrt(pow(Lx, 2) ) - r->r)
+ (r->kd * ( (Ldotx * Lx) / sqrt(pow(Lx, 2) ) )) * ( Lx / sqrt(pow(Lx, 2)) );
if(Ly != 0)
ForceA.y = -r->ks * ( sqrt(pow(Ly, 2) ) - r->r)
+ (r->kd * ( (Ldoty * Ly) / sqrt(pow(Ly, 2) ) )) * ( Ly / sqrt(pow(Ly, 2)) );
ForceA.y += -9.8 / r->P[j].M;
if(Lz != 0)
ForceA.z = -r->ks * ( sqrt(pow(Lz, 2) ) - r->r)
+ (r->kd * ( (Ldotz * Lz) / sqrt(pow(Lz, 2) ) )) * ( Lz / sqrt(pow(Lz, 2)) );

r->P[j].Force.x = ForceA.x;
r->P[j].Force.y  = ForceA.y;
r->P[j].Force.z  = ForceA.z;

r->P[j+1].Force.x = -ForceA.x;
r->P[j+1].Force.y  = -ForceA.y;
r->P[j+1].Force.z  = -ForceA.z;

EulerIntegration(&r->P[j], &r->P[j+1], deltaT);


void EulerIntegration(Particle *A, Particle *B, float deltaT)
{
float Mass;
float kdr = 0.04;

Mass = A->M;

B->Vel.x= -kdr*(A->Vel.x+ (deltaT*(A->Force.x/Mass)));
B->Vel.y= -kdr*(A->Vel.y+ (deltaT* (A->Force.y/Mass)));
B->Vel.z= -kdr*(A->Vel.z+ (deltaT* (A->Force.z/Mass)));

B->M = A->M;

B->Pos.x= A->Pos.x+ (deltaT* A->Vel.x);
B->Pos.y= A->Pos.y+ (deltaT* A->Vel.y);
B->Pos.z= A->Pos.z+ (deltaT* A->Vel.z);

}


thx alot for any help.

##### Share on other sites
Hi fishleg,

there is one problem that I've noticed in your code. The magnitude of the displacement in the original equation is |L|, or something like that. The magnitude is given by |L|2 = L.x*L.x + L.y*L.y + L.z*L.z

Note, this is not something that is done component by component.

// Your code...ForceA.x = -r->ks * ( sqrt(pow(Lx, 2) ) - r->r) + (r->kd * ( (Ldotx * Lx) / sqrt(pow(Lx, 2) ) )) * ( Lx / sqrt(pow(Lx, 2)) );// Altered...Lmag = sqrt(Lx*Lx + Ly*Ly + Lz*Lz);ForceA.x = -r->ks * (Lmag - r->r) + (r-kd * ((Ldotx * Lx) / Lmag )) * ( Lx / Lmag );

In addition, there seems to be something odd about the original equation. The first term appears to be a scalar but the second term is a vector. Maybe I am missing something there, but it seems odd to me.

I hope that helped.

##### Share on other sites
My teacher says to use this formulae if this makes more sense but i couldnt get this one to work so i got that one above from gamasutra.com.

Using this formulae and what jjd said about the magnitude i do this for all of x y z forces.

r->kd = 0.2;
r->ks = 500;
r->r = 0.5;

Lx = r->P[j].Pos.x - r->P[j+1].Pos.x;
" "
Ldotx = r->P[j].Vel.x - r->P[j+1].Vel.x;
" "
Lmag = sqrt(Lx*Lx + Ly*Ly + Lz*Lz);

if(Lx != 0)
ForceA.x = -(r->ks * (Lmag - r->r)
+ r->kd * ((Ldotx * Lx) / Lmag)) * ( Lx / Lmag);
if(Ly != 0)
ForceA.y = -(r->ks * (Lmag - r->r)
+ r->kd * ((Ldotx * Ly) / Lmag)) * ( Ly / Lmag);
ForceA.y += -9.8 / r->P[j].M;
if(Lz != 0)
ForceA.z = -(r->ks * (Lmag - r->r)
+ r->kd * ((Ldotx * Lz) / Lmag)) * ( Lz / Lmag);

If i do it this way all the particles are insanely close. I start off all these particles resting on the x axis spaced 0.5 appart i must be doing this wrong because the force in the x between the 1st and 2nd pixel is zero and between the 3rd and 4th particle its 250 force in the x axis =/.

thanks again for any help.

[Edited by - fishleg003 on November 25, 2005 12:28:50 PM]

• 11
• 18
• 12
• 22
• 9
• ### Forum Statistics

• Total Topics
631397
• Total Posts
2999822
×