butiran

screen coords transform recipe

· 1 min read · edit

Figure 1. Coordinate system of world $(x, y)$ and screen $(X, Y)$.

In general the relation between world variable $z$ and screen variable $Z$ can be formulated as

$$\tag{1} \left( \frac{Z - Z_{\min}}{Z_{\max} - Z_{\min}} \right) = \left( \frac{z - z_{\min}}{z_{\max} - z_{\min}} \right). $$

Following tables give the mapping between world and screen variables from Figure 1.

Table 1. Mapping from $z$ to $x$, $y$.

$z$$x$$y$
$z_{\min}$$x_{\min}$$y_{\min}$
$z_{\max}$$x_{\max}$$y_{\max}$

Table 2. Mapping from $Z$ to $X$, $Y$

$Z$$X$$Y$
$Z_{\min}$$X_{\min}$$Y_{\max}$
$Z_{\max}$$X_{\max}$$Y_{\min}$

Eqn (1) with the help of Tables 1 and 2 can be used to obtain the functions

$$\tag{2} x = f(X), \ \ \ \ y = g(Y) $$

or

$$\tag{3} X = f^{-1}(x), \ \ \ \ Y = g^{-1}(x). $$

Transformation from world coordinates to screen coordinates or vice versa are simply using Eqns (2) and (3).