Specifications

118 Appendix Error! Main Document Only.Error! Main Document Only.6 - Calibration
and Scaling Algorithms
The screen coordinates in our example will be from 1 to 80 in X, and 1 to 25 in Y.
Therefore, Sxlow=1, Sxhigh=80, Sylow=1, and Syhigh=25. Any coordinate
scaling may be used, such as 0 to 99999 or 10 to 10.
The conversion process must be performed for both X and Y, but for simplicity,
we will only give the formula in X:
X = (Sx(Cx-Rxlow)/Rx) + Sxlow
where:
Cx is the raw coordinate at "+" in the X-axis.
X is the translated coordinate at "+" in screen coordinates.
Rx = Rxhigh - Rxlow (range of raw calibration coordinates).
Sx = Sxhigh - Sxlow (range of screen coordinates, e.g. 79 = 80-).
This algorithm can be computed with integer arithmetic if you do the following:
1. Do the multiply Sx(Cx-Rxlow) before dividing by Rx. Rx and Sx can be
pre-computed to improve performance, but Sx/Rx will likely be zero if pre-
computed because Sx may be smaller than Rx.
2. To adjust for slight rounding errors introduced in integer arithmetic, add a
rounding constant to the formula:
X = (Sx(Cx-Rxlow+(Rx/2Sx))/Rx) + Sxlow
The rounding constant may be pre-computed.
Other notes:
1. Touches outside the calibration range may be pushed just inside before the
conversion is performed, (equivalent of Trim Mode), although add the
rounding constant first. This effectively enlarges any touch zones at the edge of
the image. It also insures coordinates will always be in the desired range. For
example:
IF Cx < Rxlow THEN Cx := Rxlow
ELSE IF Cx > Rxhigh THEN Cx := Rxhigh;
2. The calibration points should not appear anywhere inside your application
program. By loading them at run time, your application is kept touchscreen and
controller independent.
3. The above formula works with signed numbers. This means that if your
touchscreen is installed upside down, while Ry may be negative, the
translated coordinates will still be as expected. Also, if you wish to invert the