Q:

How can I quantify a drawn line's straightness?

I'm working on a game which requires players to draw a line from a point A(x1,y1) to the other point B(x2,y2) on the screen of an Android device.
I want to find how well that drawing fits to a straight line. For instance, a result of 90% would mean the drawing almost perfectly fits the line. If players draw a curved line from A to B, it should get a low score.
The end points are not known in advance. How can I do this?

A:

A perfectly straight line would also be the shortest possible line with a total length of sqrt((x1-x2)² + (y1-y2)²). A more scribbly line will be a less ideal connection and thus be inevitably longer.
When you take all individual points of the path the user drew and sum up the distances between them, you can compare the total length with the ideal length. The smaller the total length divided by the ideal length, the better the line.
Here is a visualization. When the black dots are the end-points of the gesture and the blue points are the points you measured during the gesture, you would calculate and add up the lengths of the green lines and divide it by the length of the red line:

A score or sinuosity index of 1 would be perfect, anything higher would be less perfect, anything below 1 would be a bug. When you prefer to have the score in percent, divide 100% by that number.

A:

This might not be the best way to implement this either, but I suggest a RMSD (root mean square deviation) could be better, than merely the distance method, in cases mentioned by Dancrumb (see first two lines below).
RMSD = sqrt(mean(deviation^2))
Note:

The sum of the absolute deviations (integral-like) might be better, as it does not average out positive errors with negative ones. ( =sum(abs(deviation)))
You probably would have to search the shortest distance to the linear line if there is a way that creates shorter distances than dropping the perpendicular.

(Please excuse the low quality of my drawing)
As you see, you have to 

find an orthogonal vector to your line (dot-product equals 0). 
If your line points towards (1, 3)  you'd want (3, -1) (trough the origin each)
Measure the distances h from the ideal line to the user one, parallel to that vector.
Calculate the RMSD or sum of absolute differences.

A:

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 (a(t+h)-a(t))/h.
And, a(t) becomes ((x(t+h)-x(t))/h,(y(t+h)-y(t))/h)/||((x(t+h)-x(t))/h,(y(t+h)-y(t))/h)||.
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 1/(1+S).
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.

