vector getSpringForce(position from,position to,float desiredLength,float constant) { vector force=new vector(from,to); if(dist(from,to)>.5) { vector deltaLength=new vector(force); position targetPos=new position(to.displace(getHeading(to,from),desiredLength)); deltaLength=new vector(from,targetPos); // fill(255,0,0); // ellipse(targetPos.x,targetPos.y,5,5); force=new vector(deltaLength); force.m*=constant; // force.m=float(int(force.m*100))/100; // force.m=constrain(force.m,-10,10); // if(force.m<.01) // force.m=0; } return force; } vector getSpringForceVerlet(position from,position to,float desiredLength,float constant) { float dx=to.x-from.x; float dy=to.y-from.y; float d1=sqrt(dx*dx+dy*dy); float d2=constant*(d1-desiredLength)/d1; dx=dx*d2; dy=dy*d2; position newFrom=new position(from.x+dx,from.y+dy); // from.y+=dy; // to.x-=dx; // to.y-=dy; vector force=new vector(from,newFrom); return force; } float getSpringForceScalar(float from,float to,float desiredLength,float constant) { float force=to; force-=from; if(force!=0) { float deltaLength=force; float targetLength=desiredLength; deltaLength=deltaLength-targetLength; force=deltaLength; force*=constant; } return force; }