# Touch Screen Calibration ][

This is the third posting on the subject of Touch Screens. When we last looked at Touch Screen Calibration, a workable approach had been found. However there was a serious problem; the approach was iterative in nature. The user had to repeat that calibration steps until the data was accurate enough and it was difficult to know when enough was enough. The reason was that Plan B processed an inset touch point and the current guess at the opposite limit. Since each calculation used approximate data, there was always an error. Over several iterations, the error can be reduced, but never truly eliminated. To resolve this issue, a new plan was needed. A plan called Plan C!

# Plan C

The new approach is based on the idea of processing input, two points at a time with no recursion! Lets take a fresh look at the data:

Unlike previous charts, we now see two inset points. One is set 15 pixels from the left and the other 15 pixels from the right.

OK, time to bust out the algebra again. As before we know that the slopes of lines (0,$X_L$) to (319,$X_U$) and (15,$X_A$) to (304,$X_B$) are the same. The slope is the rise over the run and  can be expressed as:

$\frac{(X_U-X_L)}{320}=\frac{(X_B-X_A)}{290}$

$(X_U-X_L)=\frac{320}{290}(X_B-X_A)$

At this point we must pause. Both $X_L$ and $X_U$ are unknowns. We need a way to express things in terms that lets us reduce the number of unknowns to one per equation. To do this we need more information about our system. Consider for a moment, the center point of the two lines. It’s added to the illustration below:

Now the point (160, $X_C$) is the center point for both the shorter line from 15 to 304 and the longer one from 0 to 319. This means that the value $X_C$ is midway between $X_A$$X_B$ and also $X_L$$X_U$ Since these midpoints are equal, we are able to state:

$X_C=\frac{(X_U+X_L)}{2}=\frac{(X_A+X_B)}{2}$

Now $X_C$ itself is of no interest, it’s the other parts of the equality that are useful.

$\frac{(X_U+X_L)}{2}=\frac{(X_A+X_B)}{2}$

Multiply both sides by 2:

$X_U+X_L=X_A+X_B$

Now let’s isolate $X_L$ in the above:

$X_L=X_A+X_B-X_U$

We now have $X_L$ in terms of $X_U$,$X_A$, and $X_B$. We can now return to our earlier equation:

$(X_U-X_L)=\frac{320}{290}(X_B-X_A)$

Finally substitute  $X_A+X_B-X_U$ for $X_L$ and solve for $X_U$:

$(X_U-(X_A+X_B-X_U))=\frac{320}{290}(X_B-X_A)$

$(2X_U-(X_A+X_B))=\frac{320}{290}(X_B-X_A)$

$2X_U=(X_A+X_B)+\frac{320}{290}(X_B-X_A)$

$X_U=\frac{(X_A+X_B)+\frac{320}{290}(X_B-X_A)}{2}$

By the same token, the solution for $X_L$ is shown below. I shall leave the derivation of this as an exercise for the reader 😉 .

$X_L=\frac{(X_A+X_B)-\frac{320}{290}(X_B-X_A)}{2}$

So what are the results of all this math? Plan C produces accurate, reliable calibration data without having to iterate through a refining process. The math, while a little more complex, is still quite manageable. And with that, I think we can call this one closed for now. As always, your thoughts, comments and suggestions are invited.

Peter Camilleri (aka Squidly Jones)