General cubic curve fitting algorithm using stiffness coefficients