Existing answers do not take into account that the end points are arbitrary (rather than given).
Thus, when measuring the straightness of the curve, it does not make sense to use the end points (for example, to calculate expected length, angle, position).
A simple example would be a straight line with both ends kincked. If we measure using the distance from the curve and the straight line between the end points this will be quite large, as the straight line we have drawn is offset from the straight line between the end points.
How do we tell how straight the curve is? Assuming that the curve is smooth enough, we want to know how much, on average, the tangent to the curve is changing. For a line, this would be zero (as the tangent is constant).
If we let the position at time t be (x(t),y(t)), then the tangent is (Dx(t),Dy(t)), where Dx(t) is the derivative of x at time t (this site appears to be missing TeX support).
If the curve is not parameterized by arc-length, we normalize by dividing by ||(Dx(t),Dy(t))||.
So we have a unit vector (or angle) of the tangent to the curve at time t.
So, the angle is a(t)=(Dx(t),Dy(t))/||(Dx(t),Dy(t))||
We are then interested in ||Da(t)||^2 integrated along the curve.
Given that we most likely have discrete data points rather than a curve, we must use finite differences to approximate the derivatives.
So, Da(t) becomes
And, a(t) becomes
Then we then get S by summing up
h||Da(t)||^2 for all datapoints and possibly normalizing by the length of the curve.
Most likely, we use
h=1, but it really is just an arbitrary scale factor.
To reiterate, S will be zero for a line and larger the more it deviates from a line.
To convert to the required format, use
Given that the scale is somewhat arbitrary, it is possible to multiply S by some positive number (or transform it in some other way, e.g. use bS^c instead of S) to adjust how straight certain curves are.