protected void generateForce () {

        double currentLength = getCurrentLength();
        boolean isContract = currentLength <= myRestLength;
        double distance = Math.abs(currentLength - myRestLength);
        double amplitude = distance * myStifness;
        if (amplitude == 0)
            return;
        double centerX = (myObject1.getX() + myObject2.getX()) / 2;

        double centerY = (myObject1.getY() + myObject2.getY()) / 2;

        double fx = isContract ? myObject1.getX() - centerX : centerX - myObject1.getX();
        double fy = isContract ? myObject1.getY() - centerY : centerY - myObject1.getY();
        if (currentLength == 0) {
            fx = lastFx;
            fy = lastFy;
        }
        else {
            fx = fx / (currentLength / 2) * amplitude;
            fy = fy / (currentLength / 2) * amplitude;
            lastFx = fx;
            lastFy = fy;
        }
        myObject1.setForce(fx, fy);
        myObject2.setForce(-fx, -fy);

    }