   Hookes spring implementation question
  Hi, Im getting confused with the book Game Physics Engine Development implementation of a spring force..the (3D) formula is this:f = -k * ( |d| - restlength )* ¦d¦k = spring coefficient(stifness)d = spring current length vector( || is magnitude, ¦¦ is normalized direction )I guess I fully understand the formula, its simple..But look the book implementation:...//calculates d(particle pos - patotherend pos )Vector3 force = pParticle_p->position;force -= pPatOtherEnd->position;// Calculate the magnitude of the force.real magnitude = force.magnitude();magnitude = real_abs(magnitude - restLength);magnitude *= springConstant;...//continuesThe abs() function doesnt make any sense to me, more than that it makes shit on my opinion..Consider what is a negative value(on the parenthesis part of the eqation), to me it represents a spring compression, with is perfect, a compression will result on a force pushing away, on the contrary direction if the spring is extended, with means the negative sign would work like a charm..If Im wrong(witch is very probaly), what am I missing?The final part of code:// Calculate the final force and apply it.force.normalize();force *= -magnitude;particle->addForce(force); [Edited by - Icebone1000 on August 8, 2010 3:16:52 PM]
  You are probably right. There should be no use of abs.   ;  I agree. I think you have found a bug. I used this book to implement some basic physics but never used the code directly but rather the formulas, and my (working!) spring does not have an abs either.   